You are here

function coder_review_drush_review in Coder 7

Do the actual review.

1 string reference to 'coder_review_drush_review'
coder_review_drush_command in coder_review/coder_review.drush.inc
Implements hook_drush_command().

File

coder_review/coder_review.drush.inc, line 69
Command line utility for coder_review.

Code

function coder_review_drush_review() {
  _coder_review_drush_set_option('drush');

  // Check for drush style options.
  foreach (array(
    'summary',
    'no-empty',
    'xml',
    'checkstyle',
  ) as $option) {
    if (drush_get_option($option)) {
      _coder_review_drush_set_option($arg);
    }
  }
  $severity = drush_get_option('severity', '');
  foreach (array(
    'major',
    'minor',
    'critical',
  ) as $option) {
    if (drush_get_option($option)) {
      $severity_name = $option;
    }
  }
  foreach (array(
    'active',
    'core',
    'contrib',
    'all',
    'default',
  ) as $option) {
    if (drush_get_option($option)) {
      $settings = _coder_review_get_default_settings($option);
      $settings['coder_includes'] = TRUE;
    }
  }

  // Process command line arguments.
  $args = func_get_args();
  $reviews = array();
  $modules = array();
  $output = array();
  $settings = _coder_review_get_default_settings();
  if (count($args)) {
    $avail_reviews = _coder_review_reviews();
    foreach ($args as $arg) {
      switch ($arg) {
        case 'summary':
        case 'no-empty':
        case 'xml':
        case 'checkstyle':
          _coder_review_drush_set_option($arg);
          break;
        case 'active':
        case 'core':
        case 'contrib':
        case 'all':
        case 'default':
          $settings = _coder_review_get_default_settings($arg);
          $settings['coder_includes'] = TRUE;
          break;
        case 'major':
        case 'minor':
        case 'critical':
          $severity_name = $arg;
          break;
        default:
          if (isset($avail_reviews[$arg])) {
            $reviews[$arg] = $arg;
          }
          elseif (drupal_substr($arg, 0, 3) == 'no-') {
            _coder_review_set_form_modules($settings);
            unset($settings['coder_modules-' . drupal_substr($arg, 3)]);
          }
          elseif (strpos($arg, '*') !== FALSE || strpos($arg, '%') !== FALSE) {
            $result = db_query('SELECT name FROM {system} WHERE name LIKE :name', array(
              ':name' => str_replace('*', '%', $arg),
            ));
            foreach ($result as $system) {
              $settings['coder_modules-' . $system->name] = 1;
              $match = TRUE;
            }
            if (!isset($match)) {
              _coder_review_drush_print(dt('no matches found for @name', array(
                '@name' => $arg,
              )));
              return;
            }
            unset($settings['coder_active_modules']);
            unset($settings['coder_core']);
            unset($settings['coder_all']);
            unset($settings['coder_modules']);
            $settings['coder_includes'] = TRUE;
          }
          else {
            $root = drupal_realpath('.');
            if (_coder_review_drush_is_patch_arg($arg, $root)) {
              $settings['coder_patches'] = 1;
              $settings['coder_patch_link'] = $arg;
            }
            else {
              $path = preg_replace(",^{$root}/,", '', $_SERVER['OLDPWD'] . '/' . $arg);
              if (file_exists($path)) {
                $settings['coder_files'] = 1;
                if (empty($settings['coder_file_list'])) {
                  $settings['coder_file_list'] = '';
                }
                if (is_dir($path)) {
                  $ext = variable_get('coder_review_php_ext', array(
                    'inc',
                    'php',
                    'install',
                    'test',
                  ));
                  $settings['coder_file_list'] .= implode("\n", array_keys(drupal_system_listing('/\\.(' . implode('|', $ext) . ')$/', $path, 'filepath', 0)));
                }
                else {
                  $settings['coder_file_list'] .= $path . "\n";
                }
              }
              else {
                $settings['coder_modules-' . $arg] = 1;
                $settings['coder_includes'] = TRUE;
              }
            }
            unset($settings['coder_active_modules']);
            unset($settings['coder_core']);
            unset($settings['coder_all']);
            unset($settings['coder_modules']);
          }
          break;
      }
    }
    if (_coder_review_drush_is_option('checkstyle')) {
      _coder_review_drush_xml_output_header('checkstyle');
    }
    elseif (_coder_review_drush_is_option('xml')) {
      _coder_review_drush_xml_output_header('xml');
    }
    if (!empty($severity_name)) {
      if (_coder_review_drush_is_option('xml')) {
        _coder_review_drush_xml_output_severity($severity_name);
      }
      $output[] = dt('Severity @severity_name', array(
        '@severity_name' => $severity_name,
      ));
      $settings['coder_severity'] = _coder_review_severity($severity_name);
    }
    if (count($reviews)) {
      if (_coder_review_drush_is_option('xml') && !_coder_review_drush_is_option('checkstyle')) {
        _coder_review_drush_xml_output_reviews($reviews, $avail_reviews);
      }
      else {
        foreach ($reviews as $review) {
          $output[] = $avail_reviews[$review]['#title'];
        }
      }
      $settings['coder_reviews'] = $reviews;
    }
    if (count($output) && !_coder_review_drush_is_option('summary') && !_coder_review_drush_is_option('xml') && !_coder_review_drush_is_option('checkstyle')) {
      _coder_review_drush_print(implode(', ', $output) . "\n");
    }
  }
  _coder_review_set_form_modules($settings);
  $settings['op'] = 'drush';
  $form_state['storage'] = $settings;
  coder_review_page_form(array(), $form_state);
  if (_coder_review_drush_is_option('checkstyle')) {
    _coder_review_drush_xml_output_footer('checkstyle');
  }
  elseif (_coder_review_drush_is_option('xml')) {
    _coder_review_drush_xml_output_footer('xml');
  }
}