You are here

function drush_coder_review_install_php_code_sniffer in Coder 7.2

Drush command installs PHP Code_Sniffer.

@todo: support Windows?

File

coder_review/coder_review.drush.inc, line 477
Command line utility support for Coder_review module.

Code

function drush_coder_review_install_php_code_sniffer() {

  // Try loading CodeSniffer first, and if it already exists, exit.
  if (!@(include_once 'PHP/CodeSniffer.php')) {
    $missing = TRUE;
  }
  else {
    drush_print(dt('PHP_CodeSniffer already installed.'));
  }

  // Install PHP_CodeSniffer using pear.
  if (!empty($missing)) {
    if (!drush_shell_exec('pear update-channels') || !drush_shell_exec('pear install PHP_CodeSniffer')) {
      return drush_set_error('PHP_CODESNIFFER', dt('pear install failed: @output.', array(
        '@output' => implode("; ", drush_shell_exec_output()),
      )));
    }
  }

  // Get the pear install directory.
  if (drush_shell_exec('pear config-get php_dir')) {
    $output = drush_shell_exec_output();
    $php_dir = $output[0];

    // Check that the pear include path is include in the PHP path.
    if (strpos(ini_get('include_path'), $php_dir) === FALSE) {

      // @todo: Add the include path to php.ini.
      drush_print(dt('Please add @dir to include_path in php.ini', array(
        '@dir' => $php_dir,
      )));
    }

    // Symlink the Drupal Coder sniffs.
    $link = "{$php_dir}/PHP/CodeSniffer/Standards";
    $target = __DIR__ . "/../coder_sniffer/Drupal";
    if (!is_link($link) || readlink($link) != $target) {
      drush_shell_exec("ln -s {$target} {$link}");
    }
  }
}