Newer
Older
<?php
// $Id$
/** @file
* Developer Module that assists with code review and version upgrade that
* supports a plug-in extensible hook system so contributed modules can
* define additional review standards.
*
* Built-in support for:
* - Drupal Coding Standards - http://drupal.org/node/318
* - Handle text in a secure fashion - http://drupal.org/node/28984
* - Converting 4.6.x modules to 4.7.x - http://drupal.org/node/22218
* - Converting 4.7.x modules to 5.x - http://drupal.org/node/64279
*
* Credit also to dries:
* - http://cvs.drupal.org/viewcvs/drupal/drupal/scripts/code-style.pl
*/
/**
* Implementation of hook_init().
*/
function coder_init() {
// hook init is called even on cached pages, but we don't want to
// actually do anything in that case.
if (!function_exists('drupal_get_path')) {
return;
}
// Load all our module plug-ins
Doug Green
committed
$path = drupal_get_path('module', 'coder') .'/includes';
$files = drupal_system_listing('coder_.*\.inc$', $path, 'name', 0);
Doug Green
committed
require_once('./'. $file->filename);
}
}
/**
* Get all of the code review modules
*/
function _coder_reviews() {
$reviews = array();
// get the review definitions from the include directory
global $_coder_coders;
if ($_coder_coders) {
foreach ($_coder_coders as $coder) {
Doug Green
committed
$function = $coder .'_reviews';
if (function_exists($function)) {
if ($review = call_user_func($function)) {
$reviews = array_merge($reviews, $review);
}
}
}
}
// get the contributed module review definitions
if ($review = module_invoke_all('reviews')) {
$reviews = array_merge($reviews, $review);
}
return $reviews;
}
/**
* Implementation of hook_cron().
*/
function coder_cron() {
if ($use_cache = variable_get('coder_cache', 1)) {
// TODO: move some of the work here... is this really worth it?
}
}
/**
* Implementation of hook_perm().
*/
function coder_perm() {
return array('view code review');
}
/**
* Implementation of hook_menu().
*/
function coder_menu($may_cache = TRUE) {
if (substr(VERSION, 0, 1) == '6') {
$items['coder'] = array(
'title' => t('Code review'),
'page callback' => 'coder_page',
'access arguments' => array('view code review'),
'type' => MENU_NORMAL_ITEM,
);
$items['coder/settings'] = array(
'title' => t('Selection Form'),
'page callback' => 'coder_page',
'access arguments' => array('view code review'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -2,
);
$items['coder/default'] = array(
'title' => t('Default'),
'page callback' => 'coder_page',
'access arguments' => array('view code review'),
'type' => MENU_LOCAL_TASK,
'weight' => -1,
$items['coder/core'] = array(
'title' => t('Core'),
'page callback' => 'coder_page',
'access arguments' => array('view code review'),
);
$items['coder/active'] = array(
'title' => t('Active'),
'page callback' => 'coder_page',
'access arguments' => array('view code review'),
$items['coder/all'] = array(
'title' => t('All'),
'page callback' => 'coder_page',
'access arguments' => array('view code review'),
'type' => MENU_LOCAL_TASK,
);
$items['admin/settings/coder'] = array(
'title' => t('Code review'),
'description' => t('Select code review plugins and modules'),
'page callback' => 'drupal_get_form',
'page arguments' => array('coder_admin_settings'),
'access arguments' => array('administer site configuration'),
);
}
else {
$items[] = array(
'path' => 'coder',
'title' => t('Code review'),
'callback' => 'coder_page',
'access' => user_access('view code review'),
'type' => MENU_NORMAL_ITEM,
);
$items[] = array(
'path' => 'coder/settings',
'title' => t('Selection Form'),
'callback' => 'coder_page',
'access' => user_access('view code review'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -2,
);
$items[] = array(
'path' => 'coder/default',
'title' => t('Default'),
'callback' => 'coder_page',
'access' => user_access('view code review'),
'type' => MENU_LOCAL_TASK,
'weight' => -1,
$items[] = array(
'path' => 'coder/core',
'title' => t('Core'),
'callback' => 'coder_page',
'access' => user_access('view code review'),
);
$items[] = array(
'path' => 'coder/active',
'title' => t('Active'),
'callback' => 'coder_page',
'access' => user_access('view code review'),
'path' => 'coder/all',
'title' => t('All'),
'callback' => 'coder_page',
'access' => user_access('view code review'),
'type' => MENU_LOCAL_TASK,
);
$items[] = array(
'path' => 'admin/settings/coder',
'title' => t('Code review'),
'description' => t('Select code review plugins and modules'),
'callback' => 'drupal_get_form',
'callback arguments' => 'coder_admin_settings',
'access' => user_access('administer site configuration'),
);
}
/**
* Implementation of hook_form_alter().
*/
function coder_form_alter($form_id, &$form) {
if ($form_id == 'system_modules') {
if (user_access('view code review')) {
foreach ($form['name'] as $name => $data) {
$form['name'][$name]['#value'] = l($data['#value'], "coder/$name");
function _coder_default_reviews() {
return drupal_map_assoc(array('style', 'security'));
function _coder_settings_form($settings, &$system, &$files) {
// add the javascript
$path = drupal_get_path('module', 'coder');
drupal_add_js($path .'/coder.js');
// create the list of review options from the coder review plug-ins
$reviews = _coder_reviews();
foreach ($reviews as $name => $review) {
$review_options[$name] = l($review['#title'], $review['#link']);
}
// what review standards should be applied
$form['coder_reviews_group'] = array(
'#type' => 'fieldset',
'#title' => t('Reviews'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['coder_reviews_group']['coder_reviews'] = array(
'#type' => 'checkboxes',
'#options' => $review_options,
'#description' => t('apply the checked coding reviews'),
'#default_value' => $settings['coder_reviews'],
);
$form['coder_reviews_group']['coder_severity'] = array(
'#type' => 'radios',
'#options' => array(
1 => 'minor (most)',
5 => 'normal',
9 => 'critical (fewest)'
),
'#description' => t('show warnings at or above the severity warning level'),
'#default_value' => $settings['coder_severity'],
// get the modules and theme
$sql = "SELECT name, filename, type, status FROM {system} WHERE type='module' OR type='theme' ORDER BY weight ASC, filename ASC";
$system_modules = array();
$system_themes = array();
while ($system = db_fetch_object($result)) {
$display_name = $system->name;
if ($system->status) {
if ($system->type == 'module') {
$system_modules[$system->name] = $system->name;
}
else {
$system_themes[$system->name] = $system->name;
}
$system_links[$system->name] = l($display_name, "coder/$system->name");
$files[$system->name] = $system->filename;
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['coder_what']['coder_active_modules'] = array( // NOTE: should rename var
'#default_value' => isset($settings['coder_active_modules']) ? $settings['coder_active_modules'] : 0,
'#default_value' => isset($settings['coder_core']) ? $settings['coder_core'] : 0,
'#type' => 'checkbox',
'#default_value' => $settings['coder_includes'],
'#title' => t('include files (.inc and .php files)'),
if (arg(0) == 'admin') {
'#type' => 'checkbox',
'#default_value' => $settings['coder_cache'],
'#title' => t('use the experimental coder cache'),
);
}
'#type' => 'fieldset',
'#title' => t('Select Specific Modules'),
'#collapsible' => TRUE,
if (isset($settings['coder_all'])) {
$modules = $system_modules;
}
elseif (isset($settings['coder_active_modules']) && $settings['coder_active_modules']) {
if (isset($settings['coder_core']) && $settings['coder_core']) {
$modules = array_intersect($system_active, $system_core);
$modules = array_intersect($modules, $system_modules);
}
else {
$modules = array_intersect($system_active, $system_modules);
}
}
elseif (isset($settings['coder_core']) && $settings['coder_core']) {
$modules = array_intersect($system_core, $system_modules);
}
elseif (isset($settings['coder_active_modules']) && $settings['coder_active_modules']) {
$modules = array_intersect($system_active, $system_modules);
}
else {
$modules = isset($settings['coder_modules']) && is_array($settings['coder_modules']) ? $settings['coder_modules'] : array();
}
// display the themes in a fieldset
$form['coder_what']['coder_themes'] = array(
'#type' => 'fieldset',
'#title' => t('Select Specific Themes'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
if (isset($settings['coder_all'])) {
$themes = $system_themes;
}
elseif (isset($settings['coder_active_modules']) && $settings['coder_active_modules']) {
if (isset($settings['coder_core']) && $settings['coder_core']) {
$themes = array_intersect($system_active, $system_core);
$themes = array_intersect($themes, $system_themes);
$themes = array_intersect($system_active, $system_themes);
elseif (isset($settings['coder_core']) && $settings['coder_core']) {
$themes = array_intersect($system_core, $system_themes);
elseif (isset($settings['coder_active_modules']) && $settings['coder_active_modules']) {
$themes = array_intersect($system_active, $system_themes);
$themes = isset($settings['coder_themes']) && is_array($settings['coder_themes']) ? $settings['coder_themes'] : array();
if (in_array($name, $system_themes)) {
$type = 'theme';
$default_value = isset($themes[$name]);
}
else {
$type = 'module';
$default_value = isset($modules[$name]);
}
$form['coder_what']["coder_${type}s"]["coder_${type}s-$name"] = array(
'#title' => $link,
'#default_value' => $default_value,
'#attributes' => array('class' => implode(' ', $classes)),
);
}
/**
* Implementation of settings page for Drupal 5
*/
function coder_admin_settings() {
$form = _coder_settings_form($settings, $system, $files);
$form['#submit']['coder_settings_form_submit'] = array();
$form['#submit']['system_settings_form_submit'] = array();
return system_settings_form($form);
}
function coder_settings_form_submit($form_id, &$form_values) {
variable_set('coder_modules', _coder_settings_array($form_values, 'module'));
variable_set('coder_themes', _coder_settings_array($form_values, 'theme'));
function _coder_settings_array(&$form_values, $type) {
$typekey = "coder_{$type}s-";
$typelen = strlen($typekey);
$systems = array();
$system = substr($key, $typelen);
$systems[$system] = 1;
}
function coder_page_form_submit($form_id, $form_values) {
// HELP: is there a better way to get these to coder_page_form()???
return FALSE;
/**
* Implementation of code review page
*/
function coder_page() {
return drupal_get_form('coder_page_form');
}
function _coder_get_default_settings($args = '') {
$settings['coder_reviews'] = variable_get('coder_reviews', _coder_default_reviews());
$settings['coder_severity'] = variable_get('coder_severity', 5);
$settings['coder_cache'] = variable_get('coder_cache', 1);
// determine any options based on the passed in URL,
switch ($args) {
case '':
break;
case 'active':
$settings['coder_active_modules'] = 1;
break;
case 'core':
case 'all':
$settings['coder_core'] = 1;
$settings['coder_includes'] = 1;
$settings['coder_all'] = 1;
break;
case 'default':
$settings['coder_active_modules'] = variable_get('coder_active_modules', 1);
$settings['coder_core'] = variable_get('coder_core', 0);
$settings['coder_includes'] = variable_get('coder_includes', 0);
$settings['coder_modules'] = variable_get('coder_modules', array());
$settings['coder_themes'] = variable_get('coder_themes', array());
// TODO: does this need to go into coder_themes sometimes?
$settings['coder_modules'] = array($args => $args);
break;
}
return $settings;
}
function coder_page_form() {
// HELP: is there a better way to get these from coder_page_form_submit()???
$form_values = $_POST;
if (isset($form_values['op'])) {
$settings = $form_values;
$settings['coder_modules'] = _coder_settings_array($form_values, 'module');
$settings['coder_themes'] = _coder_settings_array($form_values, 'theme');
drupal_set_title(t('Code review (submitted options)'));
$options = arg(1);
$settings = _coder_get_default_settings($options);
if ($options) {
drupal_set_title(t('Code review (@options)', array('@options' => isset($options) ? $options : 'default options')));
}
// get this once - list of the reviews to perform
$reviews = array();
$avail_reviews = _coder_reviews();
foreach ($selected_reviews as $name => $checked) {
if ($checked) {
$reviews[$name] = $avail_reviews[$name];
}
}
if ($coder_form = _coder_settings_form($settings, $system, $files)) {
// add style sheet
$path = drupal_get_path('module', 'coder');
drupal_add_css($path .'/coder.css', 'module');
// code review non-module core files
$module_weight = 0;
if (isset($settings['coder_core']) && $settings['coder_core']) {
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
$coder_args = array(
'#reviews' => $reviews,
'#severity' => $settings['coder_severity'],
'#filename' => $filename,
);
$form['core_php'] = array(
'#type' => 'fieldset',
'#title' => 'core (php)',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => ++ $module_weight,
);
$phpfiles = file_scan_directory('.', '.*\.php', array('.', '..', 'CVS'), 0, FALSE, 'name', 0);
_coder_page_form_includes($form, $coder_args, 'core_php', $phpfiles, 2);
$form['core_includes'] = array(
'#type' => 'fieldset',
'#title' => 'core (includes)',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => ++ $module_weight,
);
$includefiles = drupal_system_listing('.*\.inc$', 'includes', 'name', 0);
_coder_page_form_includes($form, $coder_args, 'core_includes', $includefiles, 0);
}
// loop through the selected modules and themes
if (isset($system)) {
if ($checked) {
// process this one file
$filename = $files[$name];
if (!$filename) {
drupal_set_message(t('Code Review file for %module not found', array('%module' => $name)));
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
continue;
}
$coder_args = array(
'#reviews' => $reviews,
'#severity' => $settings['coder_severity'],
'#filename' => $filename,
);
$results = do_coder_reviews($coder_args);
// output the results in a collapsible fieldset
$form[$name] = array(
'#type' => 'fieldset',
'#title' => $filename,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => ++ $module_weight,
);
if (count($results) == 0) {
$results[] = t('No Problems Found');
}
else {
$form[$name]['#collapsed'] = FALSE;
}
$form[$name]['output'] = array(
'#value' => theme('coder', $name, $filename, $results),
'#weight' => -1,
);
// process the same directory include files
if ($settings['coder_includes']) {
// NOTE: convert to the realpath here so drupal_system_listing
// doesn't return additional paths (i.e., try "module").
$path = str_replace('\\', '/', dirname(realpath($filename)));
$offset = strpos($path, dirname($filename));
if (!isset($dups[$path])) {
if (substr($filename, -7) == '.module') {
$coder_args['#php_minor'] = 1;
}
$dups[$path] = 1;
$includefiles = drupal_system_listing('.*\.(inc|php)$', $path, 'name', 0);
_coder_page_form_includes($form, $coder_args, $name, $includefiles, $offset);
}
// prepend the settings form
$form['settings'] = array(
'#type' => 'fieldset',
if ($form['settings']['#collapsed']) {
$form['settings']['#prefix'] = t('<div>Use the Selection Form to select options for this code review, or change the <a href="@settings">Default Settings</a> and use the <a href="@default">Default</a> tab above.</div>', array('@settings' => url('admin/settings/coder'), '@default' => url('coder/default')));
$form['settings'][] = $coder_form;
$form['settings']['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
function _coder_page_form_includes(&$form, $coder_args, $name, $files, $offset) {
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
foreach ($files as $file) {
$filename = drupal_substr($file->filename, $offset);
$coder_args['#filename'] = $filename;
$results = do_coder_reviews($coder_args);
// output the results in a collapsible fieldset
$form[$name][$filename] = array(
'#type' => 'fieldset',
'#title' => $filename,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => ++ $weight,
);
if (count($results) == 0) {
$results[] = t('No Problems Found');
}
else {
$form[$name][$filename]['#collapsed'] = FALSE;
$form[$name]['#collapsed'] = FALSE;
}
$form[$name][$filename]['output'] = array(
'#value' => theme('coder', $name, $filename, $results),
);
}
}
Doug Green
committed
function _coder_modified() {
static $_coder_mtime;
if (!isset($_coder_mtime)) {
$path = drupal_get_path('module', 'coder');
$includefiles = drupal_system_listing('.*\.(inc|module)$', $path, 'name', 0);
$_coder_mtime = 0;
foreach ($includefiles as $file) {
$mtime = filemtime(realpath($file->filename));
if ($mtime > $_coder_mtime) {
$_coder_mtime = $mtime;
}
}
}
return $_coder_mtime;
}
function do_coder_reviews($coder_args) {
// the cache is still experimental, so users must enable it
if ($use_cache = variable_get('coder_cache', 1)) {
// cache the results because:
$cache_key = 'coder:'. implode(':', array_keys($coder_args['#reviews'])) . $coder_args['#severity'] .':'. $coder_args['#filename'];
$cache_mtime = filemtime(realpath($coder_args['#filename']));
if ($cache_serialized_results = cache_get($cache_key)) {
$cache_results = unserialize($cache_serialized_results->data);
Doug Green
committed
if ($cache_results['mtime'] == $cache_mtime && _coder_modified() < $cache_serialized_results->created) {
return $cache_results['results'];
}
}
}
$results = array();
// skip php include files when the user requested severity is above minor
if ($coder_args['#php_minor'] && drupal_substr($coder_args['#filename'], -4) == '.php') {
if ($coder_args['#severity'] > 1) {
return $results;
}
}
// read the file
if (_coder_read_and_parse_file($coder_args)) {
// do all of the code reviews
foreach ($coder_args['#reviews'] as $review) {
if ($result = do_coder_review($coder_args, $review)) {
$results += $result;
}
}
// sort the results
}
else {
_coder_error_msg($results, t('Could not read the file'), 'critical');
}
// save the results in the cache
if ($use_cache) {
$cache_results = array(
'mtime' => $cache_mtime,
'results' => $results,
);
cache_set($cache_key, 'cache', serialize($cache_results));
}
return $results;
}
function _coder_read_and_parse_file(&$coder_args) {
if ($filepath = realpath($coder_args['#filename'])) {
$content = file_get_contents($filepath);
$content_length = drupal_strlen($content);
// parse the file:
// - strip comments
// - strip quote content // - strip stuff not in php // - break into lines
$lineno = 0;
for ($pos = 0; $pos < $content_length; $pos ++) {
// get the current character
$char = $content[$pos];
if ($char == "\n") {
if ($in_comment == '/') { // end C++ style comments on newline
unset($in_comment);
}
Doug Green
committed
// assume that html inside quotes doesn't span newlines
unset($in_quote_html);
Doug Green
committed
// remove blank lines now, so we avoid processing them over-and-over
if (trim($all_lines[$lineno]) == '') {
unset($all_lines[$lineno]);
Doug Green
committed
}
if (trim($php_lines[$lineno]) == '') {
unset($php_lines[$lineno]);
}
if (trim($html_lines[$lineno]) == '') {
unset($html_lines[$lineno]);
Doug Green
committed
}
$lineno ++;
continue;
}
if ($in_php) {
// look for the ending php tag which tags precedence over everything
if ($char == '?' && $content[$pos + 1] == '>') {
unset($char);
unset($in_php);
$pos ++;
}
// when in a quoted string, look for the trailing quote
// strip characters in the string, replacing with '' or ""
elseif ($in_quote) {
if ($in_backslash) {
unset($in_backslash);
}
elseif ($char == '\\') {
$in_backslash = '\\';
}
elseif ($char == $in_quote && !$in_backslash) {
unset($in_quote);
}
elseif ($char == '<') {
$in_quote_html = '>';
}
if ($in_quote && $in_quote_html) {
$html_lines[$lineno] .= $char;
}
if ($char == $in_quote_html) {
unset($in_quote_html);
}
unset($char); // NOTE: trailing char output with starting one
}
elseif ($in_heredoc) {
if ($beginning_of_line && $char == $in_heredoc[0] && substr($content, $pos, $in_heredoc_length) == $in_heredoc) {
$all_lines[$lineno] .= substr($content, $pos + 1, $in_heredoc_length - 1);
unset($in_heredoc);
$pos += $in_heredoc_length;
}
elseif ($char == '<') {
$in_heredoc_html = '>';
}
if ($in_heredoc && $in_heredoc_html) {
$html_lines[$lineno] .= $char;
}
if ($char == $in_heredoc_html) {
unset($in_heredoc_html);
}
unset($char);
}
// when in a comment look for the trailing comment
elseif ($in_comment) {
if ($in_comment == '*' && $char == '*' && $content[$pos + 1] == '/') {
unset($in_comment);
$pos ++;
}
unset($char); // don't add comments to php output
switch ($char) {
case '\'':
case '"':
if ($content[$pos - 1] != '\\') {
$php_lines[$lineno] .= $char;
$in_quote = $char;
}
break;
case '/':
$next_char = $content[$pos + 1];
if ($next_char == '/' || $next_char == '*') {
unset($char);
$in_comment = $next_char;
$pos ++;
}
break;
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
case '<':
if ($content[$pos + 1] == '<' && $content[$pos + 2] == '<') {
unset($char);
$all_lines[$lineno] .= '<<';
// get the heredoc word
// read until the end-of-line
for ($pos += 3; $pos < $content_length; $pos ++) {
$char = $content[$pos];
if ($char == "\n") {
$pos --;
if (preg_match('/^\s+(\w+)/', $heredoc, $match)) {
$in_heredoc = $match[1];
$in_heredoc_length = drupal_strlen($in_heredoc);
}
break;
}
$all_lines[$lineno] .= $char;
$heredoc .= $char;
}
unset($heredoc);
// replace heredoc's with an empty string
$php_lines[$lineno] .= "''";
unset($char);
}
break;
if (isset($char)) {
$php_lines[$lineno] .= $char;
else {
switch ($char) {
case '<':
if ($content[$pos + 1] == '?') {
if ($content[$pos + 2] == ' ') {
$in_php = 1;
$pos += 2;
}
elseif (substr($content, $pos + 2, 3) == 'php') {
$in_php = 1;
$pos += 4;
}
break;
}
// FALTHROUGH
default:
$html_lines[$lineno] .= $char;
break;
}
// add the files lines to the arguments
$coder_args['#php_lines'] = $php_lines;
$coder_args['#html_lines'] = $html_lines;
return 1;
function _coder_severity($severity_name, $default_value = 5) {
// NOTE: implemented this way in hopes that it is faster than a php switch
if (!isset($severity_names)) {
$severity_names = array(
'minor' => 1,
'normal' => 5,
'critical' => 9,
);
}
if (isset($severity_names[$severity_name])) {
return $severity_names[$severity_name];
}
return $default_value;
}
function _coder_severity_name($coder_args, $review, $rule) {
// NOTE: warnings in php includes are suspicious because
// php includes are frequently 3rd party products
if ($coder_args['#php_minor'] && substr($coder_args['#filename'], -4) == '.php') {
return 'minor';
}
// get the severity as defined by the rule
if (isset($rule['#severity'])) {
return $rule['#severity'];
}
// if it's not defined in the rule, then it can be defined by the review
if (isset($review['#severity'])) {
return $review['#severity'];
}
// use the default
return 'normal';
}
function do_coder_review($coder_args, $review) {
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
// get the review's severity, used when the rule severity is not defined
$default_severity = _coder_severity($review['#severity']);
foreach ($review['#rules'] as $rule) {
// perform the review if above the user requested severity
$severity = _coder_severity($rule['#severity'], $default_severity);
if ($severity >= $coder_args['#severity']) {
if (isset($rule['#original'])) { // deprecated
$lines = $coder_args['#all_lines'];
}
elseif (isset($rule['#source'])) { // all, html, comment, or php
$source = '#'. $rule['#source'] .'_lines';
$lines = $coder_args[$source];
}
else {
$lines = $coder_args['#php_lines'];
}
if ($lines) {
switch ($rule['#type']) {
case 'regex':
do_coder_review_regex($coder_args, $review, $rule, $lines, $results);
break;
case 'grep':
do_coder_review_grep($coder_args, $review, $rule, $lines, $results);
break;
case 'callback':
do_coder_review_callback($coder_args, $review, $rule, $lines, $results);
break;
}
function do_coder_review_regex(&$coder_args, $review, $rule, $lines, &$results) {
if (preg_match($regex, $line, $matches)) {
// don't match some regex's
if ($not = $rule['#not']) {
foreach ($matches as $match) {
$severity_name = _coder_severity_name($coder_args, $review, $rule);
_coder_error($results, $rule, $severity_name, $lineno, $line);
function _coder_error(&$results, $rule, $severity_name, $lineno = -1, $line = '', $original = '') {
Doug Green
committed
if (isset($rule['#warning_callback'])) {
if (function_exists($rule['#warning_callback'])) {