You are here

function _coder_review_6x_callback in Coder 7

Same name and namespace in other branches
  1. 7.2 coder_review/includes/coder_review_6x.inc \_coder_review_6x_callback()

Define the rule callbacks for 6.x, see do_coder_review_callback().

1 string reference to '_coder_review_6x_callback'
coder_review_6x_reviews in coder_review/includes/coder_review_6x.inc
Implements hook_reviews().

File

coder_review/includes/coder_review_6x.inc, line 499
This include file implements coder functionality for 5.x -> 6.x upgrades.

Code

function _coder_review_6x_callback(&$coder_args, $review, $rule, $lines, &$results) {
  $ignores = $coder_args['#ignore_lines'];
  $ignores = empty($ignores) ? array() : $ignores[$review['#review_name']];

  // Only perform this check on module's (not includes).
  $filename = $coder_args['#filename'];
  if (drupal_substr($filename, -7) == '.module') {

    // If there are any theme functions, make sure that a hook_theme exists.
    $theme = FALSE;
    $hook_theme = FALSE;
    foreach ($lines as $lineno => $line) {
      if (preg_match('/function theme_/', $line[0])) {
        if (!$theme) {
          $theme = TRUE;
          $theme_line = $line[0];
          $theme_lineno = $lineno;
        }
      }
      if (preg_match('/function \\w+_theme\\(/', $line[0])) {
        $hook_theme = TRUE;
      }
    }
    if ($theme && !$hook_theme) {
      $severity_name = _coder_review_severity_name($coder_args, $review, $rule);
      $tmprule = $rule;
      $tmprule['#warning_callback'] = '_coder_review_6x_hook_theme_warning';
      _coder_review_error($results, $tmprule, $severity_name, $theme_lineno, $theme_line, $ignores);
    }

    // Read the .info file.
    $filename = drupal_substr(realpath($filename), 0, -7) . '.info';
    if (file_exists($filename)) {
      if ($lines = file($filename)) {
        foreach ($lines as $lineno => $line) {
          if (preg_match('/^dependencies\\s*=/', $line)) {
            $severity_name = _coder_review_severity_name($coder_args, $review, $rule);
            $tmprule = $rule;
            $tmprule['#warning_callback'] = '_coder_review_6x_dependency_warning';
            _coder_review_error($results, $tmprule, $severity_name, $lineno, $line, $ignores);
          }
          if (preg_match('/^core\\s*=/', $line)) {
            $core = TRUE;
          }
        }
        if (!isset($core)) {
          $severity_name = _coder_review_severity_name($coder_args, $review, $rule);
          $tmprule = $rule;
          $tmprule['#warning_callback'] = '_coder_review_6x_core_warning';
          _coder_review_error($results, $tmprule, $severity_name, $lineno, $line, $ignores);
        }
      }
    }

    // Check that there is a translations directory and not a po directory.
    $dir = dirname($filename);
    if (file_exists($dir . '/po') && !file_exists($dir . '/translations')) {
      $severity_name = _coder_review_severity_name($coder_args, $review, $rule);
      $tmprule = $rule;
      $tmprule['#warning_callback'] = '_coder_review_6x_translations_warning';
      _coder_review_error($results, $tmprule, $severity_name, -1, $dir);
    }
  }
}