You are here

function _coder_6x_callback in Coder 5.2

Same name and namespace in other branches
  1. 5 includes/coder_6x.inc \_coder_6x_callback()
  2. 6.2 includes/coder_6x.inc \_coder_6x_callback()
  3. 6 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 466
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);
      $warning = _coder_6x_hook_theme_warning();
      $results[0] = theme('coder_warning', $warning, $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);
            $warning = t('New syntax for <a href="!uri">.info files</a>, use dependencies[]', array(
              '!uri' => 'http://drupal.org/node/114774#info',
            ));
            $results[-1] = theme('coder_warning', $warning, $severity_name, $lineno, $line);
          }
          if (preg_match('/^core\\s*=/', $line)) {
            $core = TRUE;
          }
        }
        if (!isset($core)) {
          $severity_name = _coder_severity_name($coder_args, $review, $rule);
          $warning = t('New syntax for <a href="!uri">.info files</a> files requires core=6.x', array(
            '!uri' => 'http://drupal.org/node/114774#info',
          ));
          $results[-1] = theme('coder_warning', $warning, $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);
      $warning = array(
        '#warning' => t('Translations moved from ./po to ./translations'),
        '#link' => 'http://drupal.org/node/114774#translations_directory',
      );
      $results[-2] = theme('coder_warning', $warning, $severity_name, -1, $dir);
    }
  }
}