You are here

function do_coder_review_regex in Coder 5

Same name and namespace in other branches
  1. 5.2 coder.module \do_coder_review_regex()
  2. 6.2 coder.module \do_coder_review_regex()
  3. 6 coder.module \do_coder_review_regex()
  4. 7.2 coder_review/coder_review.common.inc \do_coder_review_regex()
  5. 7 coder_review/coder_review.module \do_coder_review_regex()
1 call to do_coder_review_regex()
do_coder_review in ./coder.module

File

./coder.module, line 1018
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.

Code

function do_coder_review_regex(&$coder_args, $review, $rule, $lines, &$results) {
  if (isset($rule['#value'])) {
    $regex = '/' . $rule['#value'] . '/';
    if (!isset($rule['#case-sensitive'])) {
      $regex .= 'i';
    }
    $function_regex = isset($rule['#function']) ? '/' . $rule['#function'] . '/' : '';
    $current_function = '';
    $paren = 0;
    $not_regex = isset($rule['#not']) ? '/' . $rule['#not'] . '/i' : '';
    foreach ($lines as $lineno => $line) {

      // some rules apply only within certain functions
      if ($function_regex) {
        if (preg_match('/function (\\w+)\\(/', $line, $match)) {
          $current_function = $match[1];
        }
        if (preg_match('/([{}])/', $line, $match)) {
          $paren += $match[0] == '{' ? 1 : -1;
        }
        if ($paren < 0 || $current_function == '' || !preg_match($function_regex, $current_function)) {
          continue;
        }
      }
      if (preg_match($regex, $line, $matches)) {

        // don't match some regex's
        if ($not_regex) {
          foreach ($matches as $match) {
            if (preg_match($not_regex, $match)) {
              continue 2;
            }
          }
        }
        $line = $coder_args['#all_lines'][$lineno];
        $severity_name = _coder_severity_name($coder_args, $review, $rule);
        _coder_error($results, $rule, $severity_name, $lineno, $line);
      }
    }
  }
}