You are here

function _coder_6x_callback in Coder 6

Same name and namespace in other branches
  1. 5.2 includes/coder_6x.inc \_coder_6x_callback()
  2. 5 includes/coder_6x.inc \_coder_6x_callback()
  3. 6.2 includes/coder_6x.inc \_coder_6x_callback()

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

1 string reference to '_coder_6x_callback'
coder_6x_reviews in includes/coder_6x.inc
Implementation of hook_reviews().

File

includes/coder_6x.inc, line 492
This include file implements coder functionality for 5.x -> 6.x upgrades.

Code

function _coder_6x_callback(&$coder_args, $review, $rule, $lines, &$results) {

  // Only perform this check on module's (not includes).
  $filename = $coder_args['#filename'];
  if (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)) {
        if (!$theme) {
          $theme = TRUE;
          $theme_line = $line;
          $theme_lineno = $lineno;
        }
      }
      if (preg_match('/function \\w+_theme\\(/', $line)) {
        $hook_theme = TRUE;
      }
    }
    if ($theme && !$hook_theme) {
      $severity_name = _coder_severity_name($coder_args, $review, $rule);
      $tmprule = $rule;
      $tmprule['#warning_callback'] = '_coder_6x_hook_theme_warning';
      _coder_error($results, $tmprule, $severity_name, $theme_lineno, $theme_line);
    }

    // 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_severity_name($coder_args, $review, $rule);
            $tmprule = $rule;
            $tmprule['#warning_callback'] = '_coder_6x_dependency_warning';
            _coder_error($results, $tmprule, $severity_name, $lineno, $line);
          }
          if (preg_match('/^core\\s*=/', $line)) {
            $core = TRUE;
          }
        }
        if (!isset($core)) {
          $severity_name = _coder_severity_name($coder_args, $review, $rule);
          $tmprule = $rule;
          $tmprule['#warning_callback'] = '_coder_6x_core_warning';
          _coder_error($results, $tmprule, $severity_name, $lineno, $line);
        }
      }
    }

    // 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_severity_name($coder_args, $review, $rule);
      $tmprule = $rule;
      $tmprule['#warning_callback'] = '_coder_6x_translations_warning';
      _coder_error($results, $tmprule, $severity_name, -1, $dir);
    }
  }
}