/** * @return Result */ public function run() { $this->startTimer(); if (!isset($this->standard)) { $this->standard[] = $this->getJoomlaCodingSniffers(); } $this->printTaskInfo('Initialising CodeSniffer Checks...'); // Build the options for the sniffer $options = array('files' => $this->files, 'standard' => $this->standard, 'ignored' => $this->ignored, 'showProgress' => true, 'verbosity' => false, 'ignore_errors_on_exit' => $this->ignore_errors_on_exit); // Instantiate the sniffer $phpcs = new \PHP_CodeSniffer_CLI(); // Ensure PHPCS can run, will exit if requirements aren't met $phpcs->checkRequirements(); // Run the sniffs $numErrors = $phpcs->process($options); $this->stopTimer(); $message = 'There were no code style issues detected.'; $exitCode = 0; if ($numErrors) { $message = "There were {$numErrors} issues detected."; $exitCode = 1; } if ($this->ignore_errors_on_exit) { $exitCode = 0; } return new Result($this, $exitCode, $message, ['time' => $this->getExecutionTime()]); }
/** * (non-PHPdoc) * @see MageUC_Console_Task::execute() */ public function execute() { print '[checkstyle] Lancement du checkstyle : ' . $this->getArgument('to_check') . PHP_EOL; require_once 'PHP' . DS . 'CodeSniffer.php'; $phpcs = new PHP_CodeSniffer_CLI(); $phpcs->checkRequirements(); $phpcs->process($this->_getOptions()); print '[checkstyle] done' . PHP_EOL; }
/** * Run the coding style check * * @return int */ public function process() { $this->setDefaultValues(); \PHP_CodeSniffer_Reporting::startTiming(); $phpcs = new \PHP_CodeSniffer_CLI(); $phpcs->checkRequirements(); $values = $phpcs->getCommandLineValues(); foreach ($this->defaultValues as $k => $v) { if (empty($values[$k])) { $values[$k] = $v; } } return $phpcs->process($values); }
<?php php_sapi_name() == 'cli' ?: die('CLI only'); // Script defines define('REPO_BASE', dirname(__DIR__)); // Require Composer autoloader if (!file_exists(REPO_BASE . '/vendor/autoload.php')) { fwrite(STDOUT, "[37;41mThis script requires Composer to be set up, please run 'composer install' first.[0m\n"); } require REPO_BASE . '/vendor/autoload.php'; // Welcome message fwrite(STDOUT, "[32;1mInitializing PHP_CodeSniffer checks.[0m\n"); // Ignored files $ignored = array(REPO_BASE . '/component/admin/views/*/tmpl/*', REPO_BASE . '/component/admin/layouts/*', REPO_BASE . '/component/site/views/*/tmpl/*', REPO_BASE . '/component/site/layouts/*'); // Build the options for the sniffer $options = array('files' => array(REPO_BASE . '/plugins', REPO_BASE . '/components', REPO_BASE . '/libraries'), 'standard' => array(REPO_BASE . '/.travis/phpcs/Joomla'), 'ignored' => $ignored, 'showProgress' => true, 'verbosity' => false); // Instantiate the sniffer $phpcs = new PHP_CodeSniffer_CLI(); // Ensure PHPCS can run, will exit if requirements aren't met $phpcs->checkRequirements(); // Run the sniffs $numErrors = $phpcs->process($options); // If there were errors, output the number and exit the app with a fail code if ($numErrors) { fwrite(STDOUT, sprintf("[37;41mThere were %d issues detected.[0m\n", $numErrors)); exit(1); } else { fwrite(STDOUT, "[32;1mThere were no issues detected.[0m\n"); exit(0); }
/** * CodeSnifferShell::_process() * * @return int Exit */ protected function _process() { include_once 'PHP/CodeSniffer/CLI.php'; $phpcs = new PHP_CodeSniffer_CLI(); $phpcs->checkRequirements(); $cliValues = $phpcs->getCommandLineValues(); if ($this->params['fix']) { // Override some of the command line settings that might be used and stop us // gettting a diff file. $diffFile = TMP . 'phpcbf-fixed.diff'; $cliValues['generator'] = ''; $cliValues['explain'] = false; $cliValues['reports'] = ['diff' => $diffFile]; if (file_exists($diffFile) === true) { unlink($diffFile); } } $numErrors = $phpcs->process($cliValues); $exit = 0; if ($this->params['fix']) { if (file_exists($diffFile) === false) { // Nothing to fix. if ($numErrors === 0) { // And no errors reported. $exit = 0; } else { // Errors we can't fix. $exit = 2; } } else { $cmd = "cd / && patch -p0 -ui \"{$diffFile}\" && cd \"" . APP . "\""; $output = []; $retVal = null; exec($cmd, $output, $retVal); unlink($diffFile); if ($retVal === 0) { // Everything went well. $filesPatched = count($output); echo "Patched {$filesPatched} files\n"; $exit = 1; } else { print_r($output); echo "Returned: {$retVal}\n"; $exit = 3; } } } if ($numErrors !== 0) { $this->err('An error occured during processing.'); } return $exit; }