process() public method

Runs PHP_CodeSniffer over files and directories.
See also: getCommandLineValues()
public process ( array $values = [] ) : integer
$values array An array of values determined from CLI args.
return integer The number of error and warning messages shown.
Exemplo n.º 1
0
 /**
  * @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;
 }
Exemplo n.º 3
0
 /**
  * Run PHPCS on a file.
  *
  * Returns a string representation of the output that would normally
  * be printed to the console. Artifically sets the `-s` (showSources)
  * command line switch to make it possible to parse which rules failed
  * for a given sample file.
  *
  * @param string $file to run.
  * @return string The output from phpcs.
  */
 public function runPhpCs($file)
 {
     $defaults = $this->_phpcs->getDefaults();
     $standard = $this->_rootDir . '/ruleset.xml';
     if (defined('PHP_CodeSniffer::VERSION') && version_compare(PHP_CodeSniffer::VERSION, '1.5.0') != -1) {
         $standard = [$standard];
     }
     $options = ['encoding' => 'utf-8', 'files' => [$file], 'standard' => $standard, 'showSources' => true] + $defaults;
     // New PHPCS has a strange issue where the method arguments
     // are not stored on the instance causing weird errors.
     $reflection = new ReflectionProperty($this->_phpcs, 'values');
     $reflection->setAccessible(true);
     $reflection->setValue($this->_phpcs, $options);
     ob_start();
     $this->_phpcs->process($options);
     $result = ob_get_contents();
     ob_end_clean();
     return $result;
 }
Exemplo n.º 4
0
Arquivo: Cli.php Projeto: memaw/phpcs
 /**
  * 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);
 }
Exemplo n.º 5
0
<?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, "This script requires Composer to be set up, please run 'composer install' first.\n");
}
require REPO_BASE . '/vendor/autoload.php';
// Welcome message
fwrite(STDOUT, "Initializing PHP_CodeSniffer checks.\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("There were %d issues detected.\n", $numErrors));
    exit(1);
} else {
    fwrite(STDOUT, "There were no issues detected.\n");
    exit(0);
}
Exemplo n.º 6
0
 *
 * @category  PHP
 * @package   PHP_CodeSniffer
 * @author    Greg Sherwood <*****@*****.**>
 * @author    Marc McIntyre <*****@*****.**>
 * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
 * @link      http://pear.php.net/package/PHP_CodeSniffer
 */
error_reporting(E_ALL | E_STRICT);
// Optionally use PHP_Timer to print time/memory stats for the run.
// Note that the reports are the ones who actually print the data
// as they decide if it is ok to print this data to screen.
@(include_once 'PHP/Timer.php');
if (class_exists('PHP_Timer', false) === true) {
    PHP_Timer::start();
}
if (is_file(dirname(__FILE__) . '/../CodeSniffer/CLI.php') === true) {
    include_once dirname(__FILE__) . '/../CodeSniffer/CLI.php';
} else {
    //include_once 'PHP/CodeSniffer/CLI.php';
    include_once 'CodeSniffer/CLI.php';
}
$phpcs = new PHP_CodeSniffer_CLI();
$phpcs->checkRequirements();
$numErrors = $phpcs->process();
if ($numErrors === 0) {
    exit(0);
} else {
    exit(1);
}
Exemplo n.º 7
0
#!/usr/bin/env php
<?php 
chdir(__DIR__);
$returnStatus = null;
passthru('composer install', $returnStatus);
if ($returnStatus !== 0) {
    exit(1);
}
require 'vendor/autoload.php';
$phpcsCLI = new PHP_CodeSniffer_CLI();
$phpcsArguments = ['standard' => ['PSR1'], 'files' => ['src', 'tests', 'build.php'], 'warningSeverity' => 0];
$phpcsViolations = $phpcsCLI->process($phpcsArguments);
if ($phpcsViolations > 0) {
    exit(1);
}
$phpunitConfiguration = PHPUnit_Util_Configuration::getInstance(__DIR__ . '/phpunit.xml');
$phpunitArguments = ['coverageHtml' => __DIR__ . '/coverage', 'configuration' => $phpunitConfiguration];
$testRunner = new PHPUnit_TextUI_TestRunner();
$result = $testRunner->doRun($phpunitConfiguration->getTestSuiteConfiguration(), $phpunitArguments);
if (!$result->wasSuccessful()) {
    exit(1);
}
$cloverCoverage = new PHP_CodeCoverage_Report_Clover();
file_put_contents('clover.xml', $cloverCoverage->process($result->getCodeCoverage()));
$coverageFactory = new PHP_CodeCoverage_Report_Factory();
$coverageReport = $coverageFactory->create($result->getCodeCoverage());
if ($coverageReport->getNumExecutedLines() !== $coverageReport->getNumExecutableLines()) {
    file_put_contents('php://stderr', "Code coverage was NOT 100%\n");
    exit(1);
}
echo "Code coverage was 100%\n";
Exemplo n.º 8
0
#!/usr/bin/env php
<?php 
require 'vendor/autoload.php';
$phpcsCLI = new PHP_CodeSniffer_CLI();
$phpcsViolations = $phpcsCLI->process(['standard' => ['PSR1'], 'files' => ['bin', 'src', 'tests', 'build.php']]);
if ($phpcsViolations > 0) {
    exit(1);
}
$phpunitConfiguration = PHPUnit_Util_Configuration::getInstance(__DIR__ . '/phpunit.xml');
$phpunitArguments = ['coverageHtml' => __DIR__ . '/coverage', 'configuration' => $phpunitConfiguration];
$testRunner = new PHPUnit_TextUI_TestRunner();
$result = $testRunner->doRun($phpunitConfiguration->getTestSuiteConfiguration(), $phpunitArguments, false);
if (!$result->wasSuccessful()) {
    exit(1);
}
$coverageReport = $result->getCodeCoverage()->getReport();
if ($coverageReport->getNumExecutedLines() !== $coverageReport->getNumExecutableLines()) {
    file_put_contents('php://stderr', "Code coverage was NOT 100%\n");
    exit(1);
}
file_put_contents('php://stderr', "Code coverage was 100%\n");
Exemplo n.º 9
0
<?php

// Bootstrap the application.
require __DIR__ . '/../src/bootstrap.php';
error_reporting(E_ALL | E_STRICT);
// Set up the command line interface.
$phpcs = new PHP_CodeSniffer_CLI();
$phpcs->checkRequirements();
// Add the Drupal standard.
$values = $phpcs->getCommandLineValues();
$standard = dirname(__DIR__) . '/src/Drupal';
if (!isset($values['standard'])) {
    $values['standard'] = $standard;
} else {
    $values['standard'] .= ',' . $standard;
}
// Process width PHP CodeSnifer.
$numErrors = $phpcs->process($values);
if ($numErrors === 0) {
    exit(0);
} else {
    exit(1);
}
Exemplo n.º 10
0
#!/usr/bin/env php
<?php 
require 'vendor/autoload.php';
$phpcsCLI = new PHP_CodeSniffer_CLI();
$phpcsViolations = $phpcsCLI->process(array('standard' => array('PSR1'), 'files' => array('src', 'tests', 'build.php')));
if ($phpcsViolations > 0) {
    exit(1);
}
$phpunitConfiguration = PHPUnit_Util_Configuration::getInstance(__DIR__ . '/phpunit.xml');
$phpunitArguments = array('coverageHtml' => __DIR__ . '/coverage', 'configuration' => $phpunitConfiguration);
$testRunner = new PHPUnit_TextUI_TestRunner();
$result = $testRunner->doRun($phpunitConfiguration->getTestSuiteConfiguration(), $phpunitArguments);
if (!$result->wasSuccessful()) {
    exit(1);
}
$coverageFactory = new PHP_CodeCoverage_Report_Factory();
$coverageReport = $coverageFactory->create($result->getCodeCoverage());
if ($coverageReport->getNumExecutedLines() !== $coverageReport->getNumExecutableLines()) {
    file_put_contents('php://stderr', "Code coverage was NOT 100%\n");
    exit(1);
}
file_put_contents('php://stderr', "Code coverage was 100%\n");
 /**
  * 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;
 }