当前位置: 首页>>代码示例>>PHP>>正文


PHP PHP_CodeSniffer::setCli方法代码示例

本文整理汇总了PHP中PHP_CodeSniffer::setCli方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer::setCli方法的具体用法?PHP PHP_CodeSniffer::setCli怎么用?PHP PHP_CodeSniffer::setCli使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHP_CodeSniffer的用法示例。


在下文中一共展示了PHP_CodeSniffer::setCli方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 public function execute()
 {
     require_once $this->mooshDir . "/includes/codesniffer_cli.php";
     require_once $this->mooshDir . "/includes/coderepair/CodeRepair.php";
     $moodle_sniffs = $this->mooshDir . "/vendor/moodlerooms/moodle-coding-standard/moodle";
     $options = $this->expandedOptions;
     $interactive = $options['interactive'];
     if (isset($options['path'])) {
         $this->checkDirArg($options['path']);
         $path = $options['path'];
     } else {
         $path = $this->cwd;
     }
     $files = $this->_get_files($path);
     if ($options['repair'] === true) {
         $code_repair = new \CodeRepair($files);
         $code_repair->drymode = false;
         $code_repair->start();
     }
     $phpcscli = new \codesniffer_cli();
     $phpcs = new \PHP_CodeSniffer(1, 0, 'utf-8', (bool) $interactive);
     $phpcs->setCli($phpcscli);
     $phpcs->process($files, $moodle_sniffs);
     $phpcs->reporting->printReport('full', false, $phpcscli->getCommandLineValues(), null);
 }
开发者ID:tmuras,项目名称:moosh,代码行数:25,代码来源:ToolsCodeCheck.php

示例2: execute

 public function execute()
 {
     require_once $this->mooshDir . "/includes/codesniffer/CodeSniffer.php";
     require_once $this->mooshDir . "/includes/codesniffer/lib.php";
     require_once $this->mooshDir . "/includes/coderepair/CodeRepair.php";
     $moodle_sniffs = $this->mooshDir . "/includes/codesniffer/moodle";
     $options = $this->expandedOptions;
     $interactive = $options['interactive'];
     if (isset($options['path'])) {
         $this->checkFileArg($options['path']);
         $path = $options['path'];
     } else {
         $path = $this->cwd;
     }
     $files = $this->_get_files($path);
     if ($options['repair'] === true) {
         $code_repair = new \CodeRepair($files);
         $code_repair->drymode = false;
         $code_repair->start();
     }
     $phpcs = new \PHP_CodeSniffer(1, 0, 'utf-8', false);
     $phpcs->setCli(new \codesniffer_cli());
     $numerrors = $phpcs->process($files, $moodle_sniffs);
     $phpcs->reporting->printReport('full', false, null);
 }
开发者ID:dariogs,项目名称:moosh,代码行数:25,代码来源:ToolsCodeCheck.php

示例3: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->outputHeading($output, 'Moodle Code Checker on %s');
     $files = $this->plugin->getFiles($this->finder);
     if (count($files) === 0) {
         return $this->outputSkip($output);
     }
     $sniffer = new \PHP_CodeSniffer();
     $sniffer->setCli(new CodeSnifferCLI(['reports' => ['full' => null], 'colors' => true, 'encoding' => 'utf-8', 'showProgress' => true, 'reportWidth' => 120]));
     $sniffer->process($files, $this->standard);
     $results = $sniffer->reporting->printReport('full', false, $sniffer->cli->getCommandLineValues(), null, 120);
     return $results['errors'] > 0 ? 1 : 0;
 }
开发者ID:gjb2048,项目名称:moodle-plugin-ci,代码行数:13,代码来源:CodeCheckerCommand.php

示例4: getSniffAnalysis

 /**
  * Runs PHP sniff analysis.
  *
  * @return []string
  * Textual summary of the analysis.
  */
 function getSniffAnalysis(Module $module, $extensions)
 {
     #print_r(get_defined_vars());
     $verbosity = 1;
     // Run php analyser directly as PHP.
     $phpcs = new \PHP_CodeSniffer($verbosity);
     // Need to emulate a CLI environment in order to pass certain settings down
     // to the internals.
     // Decoupling here is atrocious.
     $cli = new SniffReporter();
     $phpcs->setCli($cli);
     // Parameters passed to phpcs.
     // Normally we just name the standard,
     // but passing the full path to it also works.
     $values = array('standard' => 'Drupal', 'sniffs' => array());
     try {
         $phpcs->initStandard($values['standard'], $values['sniffs']);
     } catch (Exception $e) {
         $message = "Could not initialize coding standard " . $values['standard'] . " " . $e->getMessage();
         error_log($message);
         return array($message);
     }
     $analysis = array();
     try {
         // PHPCS handles recursion on its own.
         // $analysis = $phpcs->processFiles($module->getLocation());
         // But we have already enumerated the files, so lets keep consistent.
         $tree = $module->getCodeFiles($extensions);
         // $analysis = $phpcs->processFiles($tree);
         // processFiles is too abstract, it doesn't return the individual results.
         // Do the iteration ourselves.
         foreach ($tree as $filepath) {
             /** @var PHP_CodeSniffer_File $analysed */
             $analysed = $phpcs->processFile($filepath);
             $analysis[$filepath] = $analysed;
         }
     } catch (Exception $e) {
         $message = "When processing " . $module->getLocation() . " " . $e->getMessage();
         error_log($message);
     }
     // Params for reporting.
     $report = 'full';
     $showSources = FALSE;
     $cliValues = array('colors' => FALSE);
     $reportFile = 'report.out';
     $result = $phpcs->reporting->printReport($report, $showSources, $cliValues, $reportFile);
     #print_r($result);
     return $analysis;
 }
开发者ID:dman-coders,项目名称:drupal-code-metrics,代码行数:55,代码来源:SniffReport.php

示例5: execute

 /**
  * Execute the command.
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $this->setupFormatters($output->getFormatter());
     $finder = new Finder();
     $phpcs = new CodeSniffer(0);
     $phpcsCli = new CLI();
     $phpcsCli->errorSeverity = PHPCS_DEFAULT_ERROR_SEV;
     $phpcsCli->warningSeverity = PHPCS_DEFAULT_WARN_SEV;
     $phpcsCli->dieOnUnknownArg = false;
     $phpcsCli->setCommandLineValues(['--colors', '-p', '--report=full']);
     $phpcs->setCli($phpcsCli);
     $existing = [];
     foreach (RootDirectories::getEnforceable() as $directory) {
         if (file_exists($directory) && is_dir($directory)) {
             $existing[] = $directory;
         }
     }
     $files = $finder->files()->in($existing)->notName('*Sniff.php')->ignoreUnreadableDirs()->ignoreDotFiles(true)->ignoreVCS(true)->name('*.php');
     $phpcs->reporting->startTiming();
     $phpcs->initStandard(Anchor::getDirectory());
     $files = array_keys(iterator_to_array($files->getIterator()));
     $processed = [];
     $withErrors = [];
     $withWarnings = [];
     foreach ($files as $file) {
         $done = $phpcs->processFile($file);
         if ($done->getErrorCount() > 0) {
             $output->write('E');
             $withErrors[] = $done;
             if ($done->getWarningCount() > 0) {
                 $withWarnings[] = $done;
             }
         } elseif ($done->getWarningCount() > 0) {
             $output->write('W');
             $withWarnings[] = $done;
         } else {
             $output->write('.');
         }
         $processed[] = $done;
     }
     $this->renderSummary($withErrors, $withWarnings, $output);
 }
开发者ID:MarkVaughn,项目名称:standard,代码行数:50,代码来源:LintCommand.php

示例6: process

 /**
  * Runs PHP_CodeSniffer over files and directories.
  *
  * @param array $values An array of values determined from CLI args.
  *
  * @return int The number of error and warning messages shown.
  * @see getCommandLineValues()
  */
 public function process($values = array())
 {
     if (empty($values) === true) {
         $values = $this->getCommandLineValues();
     }
     if ($values['generator'] !== '') {
         $phpcs = new PHP_CodeSniffer($values['verbosity']);
         $phpcs->generateDocs($values['standard'], $values['files'], $values['generator']);
         exit(0);
     }
     $fileContents = '';
     if (empty($values['files']) === true) {
         // Check if they passing in the file contents.
         $handle = fopen('php://stdin', 'r');
         $fileContents = stream_get_contents($handle);
         fclose($handle);
         if ($fileContents === '') {
             // No files and no content passed in.
             echo 'ERROR: You must supply at least one file or directory to process.' . PHP_EOL . PHP_EOL;
             $this->printUsage();
             exit(2);
         }
     }
     $values['standard'] = $this->validateStandard($values['standard']);
     if (PHP_CodeSniffer::isInstalledStandard($values['standard']) === false) {
         // They didn't select a valid coding standard, so help them
         // out by letting them know which standards are installed.
         echo 'ERROR: the "' . $values['standard'] . '" coding standard is not installed. ';
         $this->printInstalledStandards();
         exit(2);
     }
     $phpcs = new PHP_CodeSniffer($values['verbosity'], $values['tabWidth'], $values['encoding'], $values['interactive']);
     // Set file extensions if they were specified. Otherwise,
     // let PHP_CodeSniffer decide on the defaults.
     if (empty($values['extensions']) === false) {
         $phpcs->setAllowedFileExtensions($values['extensions']);
     }
     // Set ignore patterns if they were specified.
     if (empty($values['ignored']) === false) {
         $phpcs->setIgnorePatterns($values['ignored']);
     }
     // Set some convenience member vars.
     if ($values['errorSeverity'] === null) {
         $this->errorSeverity = PHPCS_DEFAULT_ERROR_SEV;
     } else {
         $this->errorSeverity = $values['errorSeverity'];
     }
     if ($values['warningSeverity'] === null) {
         $this->warningSeverity = PHPCS_DEFAULT_WARN_SEV;
     } else {
         $this->warningSeverity = $values['warningSeverity'];
     }
     $phpcs->setCli($this);
     $phpcs->process($values['files'], $values['standard'], $values['sniffs'], $values['local']);
     if ($fileContents !== '') {
         $phpcs->processFile('STDIN', $fileContents);
     }
     return $this->printErrorReport($phpcs, $values['reports'], $values['showSources'], $values['reportFile'], $values['reportWidth']);
 }
开发者ID:CobaltBlueDW,项目名称:oddsandends,代码行数:67,代码来源:CLI.php

示例7: process

 /**
  * Runs PHP_CodeSniffer over files and directories.
  *
  * @param array $values An array of values determined from CLI args.
  *
  * @return int The number of error and warning messages shown.
  * @see    getCommandLineValues()
  */
 public function process($values = array())
 {
     if (empty($values) === true) {
         $values = $this->getCommandLineValues();
     } else {
         $values = array_merge($this->getDefaults(), $values);
         $this->values = $values;
     }
     if ($values['generator'] !== '') {
         $phpcs = new PHP_CodeSniffer($values['verbosity']);
         if ($values['standard'] === null) {
             $values['standard'] = $this->validateStandard(null);
         }
         foreach ($values['standard'] as $standard) {
             $phpcs->generateDocs($standard, $values['sniffs'], $values['generator']);
         }
         exit(0);
     }
     // If no standard is supplied, get the default.
     $values['standard'] = $this->validateStandard($values['standard']);
     foreach ($values['standard'] as $standard) {
         if (PHP_CodeSniffer::isInstalledStandard($standard) === false) {
             // They didn't select a valid coding standard, so help them
             // out by letting them know which standards are installed.
             echo 'ERROR: the "' . $standard . '" coding standard is not installed. ';
             $this->printInstalledStandards();
             exit(2);
         }
     }
     if ($values['explain'] === true) {
         foreach ($values['standard'] as $standard) {
             $this->explainStandard($standard);
         }
         exit(0);
     }
     $phpcs = new PHP_CodeSniffer($values['verbosity'], null, null, null);
     $phpcs->setCli($this);
     $phpcs->initStandard($values['standard'], $values['sniffs']);
     $values = $this->values;
     $phpcs->setTabWidth($values['tabWidth']);
     $phpcs->setEncoding($values['encoding']);
     $phpcs->setInteractive($values['interactive']);
     // Set file extensions if they were specified. Otherwise,
     // let PHP_CodeSniffer decide on the defaults.
     if (empty($values['extensions']) === false) {
         $phpcs->setAllowedFileExtensions($values['extensions']);
     }
     // Set ignore patterns if they were specified.
     if (empty($values['ignored']) === false) {
         $ignorePatterns = array_merge($phpcs->getIgnorePatterns(), $values['ignored']);
         $phpcs->setIgnorePatterns($ignorePatterns);
     }
     // Set some convenience member vars.
     if ($values['errorSeverity'] === null) {
         $this->errorSeverity = PHPCS_DEFAULT_ERROR_SEV;
     } else {
         $this->errorSeverity = $values['errorSeverity'];
     }
     if ($values['warningSeverity'] === null) {
         $this->warningSeverity = PHPCS_DEFAULT_WARN_SEV;
     } else {
         $this->warningSeverity = $values['warningSeverity'];
     }
     if (empty($values['reports']) === true) {
         $values['reports']['full'] = $values['reportFile'];
         $this->values['reports'] = $values['reports'];
     }
     // Include bootstrap files.
     foreach ($values['bootstrap'] as $bootstrap) {
         include $bootstrap;
     }
     $phpcs->processFiles($values['files'], $values['local']);
     if (empty($values['files']) === true || $values['stdin'] !== null) {
         $fileContents = $values['stdin'];
         if ($fileContents === null) {
             // Check if they are passing in the file contents.
             $handle = fopen('php://stdin', 'r');
             stream_set_blocking($handle, true);
             $fileContents = stream_get_contents($handle);
             fclose($handle);
         }
         if ($fileContents === '') {
             // No files and no content passed in.
             echo 'ERROR: You must supply at least one file or directory to process.' . PHP_EOL . PHP_EOL;
             $this->printUsage();
             exit(2);
         } else {
             $phpcs->processFile('STDIN', $fileContents);
         }
     }
     // Interactive runs don't require a final report and it doesn't really
     // matter what the retun value is because we know it isn't being read
//.........这里部分代码省略.........
开发者ID:ghermans,项目名称:PHP_CodeSniffer,代码行数:101,代码来源:CLI.php

示例8: dirname

 * @package    local_codechecker
 * @copyright  2011 The Open University
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
define('CLI_SCRIPT', true);
require dirname(__FILE__) . '/../../config.php';
require_once $CFG->libdir . '/clilib.php';
require_once $CFG->dirroot . '/local/codechecker/locallib.php';
// Get the command-line options.
list($options, $unrecognized) = cli_get_params(array('help' => false, 'interactive' => false), array('h' => 'help', 'i' => 'interactive'));
if (count($unrecognized) != 1) {
    $options['help'] = true;
} else {
    $path = clean_param(reset($unrecognized), PARAM_PATH);
}
if ($options['help']) {
    echo get_string('clihelp', 'local_codechecker'), "\n";
    die;
}
$interactive = false;
if ($options['interactive']) {
    $interactive = true;
}
raise_memory_limit(MEMORY_HUGE);
$standard = $CFG->dirroot . str_replace('/', DIRECTORY_SEPARATOR, '/local/codechecker/moodle');
$cli = new local_codechecker_codesniffer_cli();
$phpcs = new PHP_CodeSniffer(1, 0, 'utf-8', $interactive);
$phpcs->setCli($cli);
$phpcs->setIgnorePatterns(local_codesniffer_get_ignores());
$phpcs->process(local_codechecker_clean_path($CFG->dirroot . '/' . trim($path, '/')), local_codechecker_clean_path($standard));
$phpcs->reporting->printReport('full', false, $cli->getCommandLineValues(), null);
开发者ID:yarilcaos,项目名称:moodle-local_codechecker,代码行数:31,代码来源:run.php

示例9: dirname

 * Run the code checker from the command-line.
 *
 * @package    local
 * @subpackage codechecker
 * @copyright  2011 The Open University
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
define('CLI_SCRIPT', true);
require dirname(__FILE__) . '/../../config.php';
require_once $CFG->libdir . '/clilib.php';
require_once $CFG->dirroot . '/local/codechecker/locallib.php';
// Get the command-line options.
list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help'));
if (count($unrecognized) != 1) {
    $options['help'] = true;
} else {
    $path = clean_param(reset($unrecognized), PARAM_PATH);
}
if ($options['help']) {
    echo get_string('clihelp', 'local_codechecker'), "\n";
    die;
}
raise_memory_limit(MEMORY_HUGE);
$standard = $CFG->dirroot . str_replace('/', DIRECTORY_SEPARATOR, '/local/codechecker/moodle');
$phpcs = new PHP_CodeSniffer(1);
$phpcs->setCli(new local_codechecker_codesniffer_cli());
$phpcs->setIgnorePatterns(local_codesniffer_get_ignores());
$numerrors = $phpcs->process(local_codechecker_clean_path($CFG->dirroot . '/' . trim($path, '/')), local_codechecker_clean_path($standard));
$reporting = new PHP_CodeSniffer_Reporting();
$problems = $phpcs->getFilesErrors();
$reporting->printReport('full', $problems, false, null);
开发者ID:ravivare,项目名称:moodle-local_codechecker,代码行数:31,代码来源:run.php

示例10: process

 /**
  * Runs PHP_CodeSniffer over files are directories.
  *
  * @param array $values An array of values determined from CLI args.
  *
  * @return int The number of error and warning messages shown.
  * @see getCommandLineValues()
  */
 public function process($values = array())
 {
     if (empty($values) === true) {
         $values = $this->getCommandLineValues();
     }
     if ($values['generator'] !== '') {
         $phpcs = new PHP_CodeSniffer($values['verbosity']);
         $phpcs->generateDocs($values['standard'], $values['files'], $values['generator']);
         exit(0);
     }
     if (empty($values['files']) === true) {
         echo 'ERROR: You must supply at least one file or directory to process.' . PHP_EOL . PHP_EOL;
         $this->printUsage();
         exit(2);
     }
     $values['standard'] = $this->validateStandard($values['standard']);
     if (PHP_CodeSniffer::isInstalledStandard($values['standard']) === false) {
         // They didn't select a valid coding standard, so help them
         // out by letting them know which standards are installed.
         echo 'ERROR: the "' . $values['standard'] . '" coding standard is not installed. ';
         $this->printInstalledStandards();
         exit(2);
     }
     $phpcs = new PHP_CodeSniffer($values['verbosity'], $values['tabWidth'], $values['interactive']);
     // Set file extensions if they were specified. Otherwise,
     // let PHP_CodeSniffer decide on the defaults.
     if (empty($values['extensions']) === false) {
         $phpcs->setAllowedFileExtensions($values['extensions']);
     }
     // Set ignore patterns if they were specified.
     if (empty($values['ignored']) === false) {
         $phpcs->setIgnorePatterns($values['ignored']);
     }
     $phpcs->setCli($this);
     $phpcs->process($values['files'], $values['standard'], $values['sniffs'], $values['local']);
     return $this->printErrorReport($phpcs, $values['report'], $values['showWarnings'], $values['showSources'], $values['reportFile'], $values['reportWidth']);
 }
开发者ID:josephj,项目名称:modev,代码行数:45,代码来源:CLI.php


注:本文中的PHP_CodeSniffer::setCli方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。