You are here

function _coder_review_6x_callback in Coder 7.2

Same name and namespace in other branches
  1. 7 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 899
This include file implements coder functionality for 5.x -> 6.x upgrades.

Code

function _coder_review_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 = $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'] = array(
        '#text' => 'new !hook_theme() function is required to register theme_ functions',
        '#args' => array(
          '!hook_theme' => _drupalapi('hook_theme', 6),
        ),
        '#link' => _drupalnode(114774, 'theme_registry'),
      );
      _coder_review_error($results, $tmprule, $severity_name, $theme_lineno, $theme_line, $coder_args['#ignores']);
    }

    // Read the .info file.
    $filename = _substr(realpath($filename), 0, -7) . '.info';
    if (file_exists($filename)) {
      $lines = file($filename);
      if ($lines) {
        $core = FALSE;
        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'] = array(
              '#warning' => 'New syntax for .info files, use dependencies[]',
              '#link' => _drupalnode(114774, 'info'),
            );
            _coder_review_error($results, $tmprule, $severity_name, $lineno, $line, $coder_args['#ignores']);
          }
          if (preg_match('/^core\\s*=/', $line)) {
            $core = TRUE;
          }
        }
        if (!$core) {
          $severity_name = _coder_review_severity_name($coder_args, $review, $rule);
          $tmprule = $rule;
          $tmprule['#warning'] = array(
            '#text' => 'New syntax for .info files files requires core=6.x',
            '#link' => _drupalnode(114774, 'info'),
          );
          _coder_review_error($results, $tmprule, $severity_name, $lineno, $line, $coder_args['#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'] = array(
        '#text' => 'Translations moved from ./po to ./translations',
        '#link' => _drupalnode(114774, 'translations_directory'),
      );
      _coder_review_error($results, $tmprule, $severity_name, -1, $dir);
    }
  }
}