Permalink
Browse files

CONTRIB-3564 codechecker: update sniffer to 1.3.3 and require Moodle 2.2

  • Loading branch information...
1 parent 9eadaae commit a8c3b2e9db2f1867949b0ae004f93517d61e6803 @stronk7 stronk7 committed Mar 31, 2012
Showing 628 changed files with 3,247 additions and 1,935 deletions.
View
90 pear/PHP/CodeSniffer.php 100755 → 100644
@@ -9,9 +9,8 @@
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
- * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
+ * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
- * @version CVS: $Id: CodeSniffer.php 308981 2011-03-06 21:54:08Z squiz $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
@@ -61,7 +60,7 @@
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
- * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
+ * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
* @version Release: @package_version@
* @link http://pear.php.net/package/PHP_CodeSniffer
@@ -115,16 +114,6 @@ class PHP_CodeSniffer
protected $ruleset = array();
/**
- * The path that that PHP_CodeSniffer is being run from.
- *
- * Stored so that the path can be restored after it is changed
- * in the constructor.
- *
- * @var string
- */
- private $_cwd = null;
-
- /**
* The listeners array, indexed by token type.
*
* @var array
@@ -220,7 +209,10 @@ public function __construct(
// Change into a directory that we know about to stop any
// relative path conflicts.
- $this->_cwd = getcwd();
+ if (defined('PHPCS_CWD') === false) {
+ define('PHPCS_CWD', getcwd());
+ }
+
chdir(dirname(__FILE__).'/CodeSniffer/');
// Set default CLI object in case someone is running us
@@ -242,7 +234,7 @@ public function __construct(
*/
public function __destruct()
{
- chdir($this->_cwd);
+ chdir(PHPCS_CWD);
}//end __destruct()
@@ -430,8 +422,8 @@ public function process($files, $standard, array $sniffs=array(), $local=false)
if ($ruleset !== false) {
$standardName = (string) $ruleset['name'];
}
- } else if (is_file(realpath($this->_cwd.'/'.$standard)) === true) {
- $ruleset = simplexml_load_file(realpath($this->_cwd.'/'.$standard));
+ } else if (is_file(realpath(PHPCS_CWD.'/'.$standard)) === true) {
+ $ruleset = simplexml_load_file(realpath(PHPCS_CWD.'/'.$standard));
if ($ruleset !== false) {
$standardName = (string) $ruleset['name'];
}
@@ -604,7 +596,7 @@ public function setTokenListeners($standard, array $sniffs=array())
if (is_dir($this->standardDir) === false) {
// This isn't looking good. Let's see if this
// is a relative path to a custom standard.
- $path = realpath($this->_cwd.'/'.$standard);
+ $path = realpath(PHPCS_CWD.'/'.$standard);
if (is_dir($path) === true) {
// This is a relative path to a custom standard.
$this->standardDir = $path;
@@ -735,11 +727,11 @@ public function getSniffFiles($dir, $standard=null)
}
foreach ($ruleset->rule as $rule) {
- $includedSniffs = array_merge($includedSniffs, self::_expandRulesetReference($rule['ref']));
+ $includedSniffs = array_merge($includedSniffs, $this->_expandRulesetReference($rule['ref']));
if (isset($rule->exclude) === true) {
foreach ($rule->exclude as $exclude) {
- $excludedSniffs = array_merge($excludedSniffs, self::_expandRulesetReference($exclude['name']));
+ $excludedSniffs = array_merge($excludedSniffs, $this->_expandRulesetReference($exclude['name']));
}
}
}//end foreach
@@ -1027,6 +1019,10 @@ public function getFilesToProcess($paths, $local=false)
$files[] = $file->getPathname();
}//end foreach
} else {
+ if ($this->shouldIgnoreFile($path) === true) {
+ continue;
+ }
+
$files[] = $path;
}//end if
}//end foreach
@@ -1049,18 +1045,46 @@ public function shouldProcessFile($path)
{
// Check that the file's extension is one we are checking.
// We are strict about checking the extension and we don't
- // let files through with no extension.
- $fileParts = explode('.', $path);
- $extension = array_pop($fileParts);
- if ($extension === $path) {
+ // let files through with no extension or that start with a dot.
+ $fileName = basename($path);
+ $fileParts = explode('.', $fileName);
+ if ($fileParts[0] === $fileName || $fileParts[0] === '') {
return false;
}
- if (isset($this->allowedFileExtensions[$extension]) === false) {
+ // Checking multi-part file extensions, so need to create a
+ // complete extension list and make sure one is allowed.
+ $extensions = array();
+ array_shift($fileParts);
+ foreach ($fileParts as $part) {
+ $extensions[implode('.', $fileParts)] = 1;
+ array_shift($fileParts);
+ }
+
+ $matches = array_intersect_key($extensions, $this->allowedFileExtensions);
+ if (empty($matches) === true) {
return false;
}
// If the file's path matches one of our ignore patterns, skip it.
+ if ($this->shouldIgnoreFile($path) === true) {
+ return false;
+ }
+
+ return true;
+
+ }//end shouldProcessFile()
+
+
+ /**
+ * Checks filtering rules to see if a file should be ignored.
+ *
+ * @param string $path The path to the file being checked.
+ *
+ * @return bool
+ */
+ public function shouldIgnoreFile($path)
+ {
foreach ($this->ignorePatterns as $pattern) {
if (is_array($pattern) === true) {
// A sniff specific ignore pattern.
@@ -1074,13 +1098,13 @@ public function shouldProcessFile($path)
$pattern = strtr($pattern, $replacements);
if (preg_match("|{$pattern}|i", $path) === 1) {
- return false;
+ return true;
}
}//end foreach
- return true;
+ return false;
- }//end shouldProcessFile()
+ }//end shouldIgnoreFile()
/**
@@ -1105,6 +1129,9 @@ public function processFile($file, $contents=null)
}
$filePath = realpath($file);
+ if ($filePath === false) {
+ $filePath = $file;
+ }
// Before we go and spend time tokenizing this file, just check
// to see if there is a tag up top to indicate that the whole
@@ -1313,7 +1340,9 @@ public function getFilesErrors()
*/
public function generateDocs($standard, array $sniffs=array(), $generator='Text')
{
- include_once 'PHP/CodeSniffer/DocGenerators/'.$generator.'.php';
+ if (class_exists('PHP_CodeSniffer_DocGenerators_'.$generator, true) === false) {
+ throw new PHP_CodeSniffer_Exception('Class PHP_CodeSniffer_DocGenerators_'.$generator.' not found');
+ }
$class = "PHP_CodeSniffer_DocGenerators_$generator";
$generator = new $class($standard, $sniffs);
@@ -1536,6 +1565,9 @@ public static function resolveSimpleToken($token)
case '$':
$newToken['type'] = 'T_DOLLAR';
break;
+ case '`':
+ $newToken['type'] = 'T_BACKTICK';
+ break;
default:
$newToken['type'] = 'T_NONE';
break;
View
0 pear/PHP/CodeSniffer.sample.conf 100755 → 100644
No changes.
View
53 pear/PHP/CodeSniffer/CLI.php 100755 → 100644
@@ -7,9 +7,8 @@
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
- * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
+ * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
- * @version CVS: $Id: CLI.php 307425 2011-01-12 22:23:07Z squiz $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
@@ -25,9 +24,9 @@
* @category PHP
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
- * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
+ * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
- * @version Release: 1.3.0
+ * @version Release: 1.3.3
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_CLI
@@ -296,7 +295,7 @@ public function processLongArgument($arg, $pos, $values)
exit(0);
break;
case 'version':
- echo 'PHP_CodeSniffer version 1.3.0 (stable) ';
+ echo 'PHP_CodeSniffer version 1.3.3 (stable) ';
echo 'by Squiz Pty Ltd. (http://www.squiz.net)'.PHP_EOL;
exit(0);
break;
@@ -383,6 +382,7 @@ public function processLongArgument($arg, $pos, $values)
'summary',
'svnblame',
'gitblame',
+ 'hgblame',
);
if (in_array($report, $validReports) === false) {
@@ -486,10 +486,19 @@ public function process($values=array())
exit(0);
}
+ $fileContents = '';
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);
+ // 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']);
@@ -541,6 +550,10 @@ public function process($values=array())
$values['local']
);
+ if ($fileContents !== '') {
+ $phpcs->processFile('STDIN', $fileContents);
+ }
+
return $this->printErrorReport(
$phpcs,
$values['reports'],
@@ -582,13 +595,21 @@ public function printErrorReport(
$reports['full'] = $reportFile;
}
- $errors = 0;
+ $errors = 0;
+ $toScreen = false;
foreach ($reports as $report => $output) {
if ($output === null) {
$output = $reportFile;
}
+ if ($reportFile === null) {
+ $toScreen = true;
+ }
+
+ // We don't add errors here because the number of
+ // errors reported by each report type will always be the
+ // same, so we really just need 1 number.
$errors = $reporting->printReport(
$report,
$filesViolations,
@@ -598,6 +619,18 @@ public function printErrorReport(
);
}
+ // Only print PHP_Timer output if no reports were
+ // printed to the screen so we don't put additional output
+ // in something like an XML report. If we are printing to screen,
+ // the report types would have already worked out who should
+ // print the timer info.
+ if ($toScreen === false
+ && PHP_CODESNIFFER_INTERACTIVE === false
+ && class_exists('PHP_Timer', false) === true
+ ) {
+ echo PHP_Timer::resourceUsage().PHP_EOL.PHP_EOL;
+ }
+
// They should all return the same value, so it
// doesn't matter which return value we end up using.
return $errors;
@@ -680,7 +713,7 @@ public function printUsage()
echo ' <generator> The name of a doc generator to use'.PHP_EOL;
echo ' (forces doc generation instead of checking)'.PHP_EOL;
echo ' <report> Print either the "full", "xml", "checkstyle", "csv", "emacs"'.PHP_EOL;
- echo ' "source", "summary", "svnblame" or "gitblame" report'.PHP_EOL;
+ echo ' "source", "summary", "svnblame", "gitblame" or "hgblame" report'.PHP_EOL;
echo ' (the "full" report is printed by default)'.PHP_EOL;
echo ' <reportfile> Write the report to the specified file path'.PHP_EOL;
echo ' <reportWidth> How many columns wide screen reports should be printed'.PHP_EOL;
@@ -8,9 +8,8 @@
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
- * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
+ * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
- * @version CVS: $Id: AbstractDocElement.php 302087 2010-08-11 01:51:18Z squiz $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
@@ -57,9 +56,9 @@
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
- * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
+ * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
- * @version Release: 1.3.0
+ * @version Release: 1.3.3
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
abstract class PHP_CodeSniffer_CommentParser_AbstractDocElement implements PHP_CodeSniffer_CommentParser_DocElement
@@ -8,9 +8,8 @@
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
- * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
+ * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
- * @version CVS: $Id: AbstractParser.php 302086 2010-08-11 01:50:50Z squiz $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
@@ -62,9 +61,9 @@
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
- * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
+ * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
- * @version Release: 1.3.0
+ * @version Release: 1.3.3
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
abstract class PHP_CodeSniffer_CommentParser_AbstractParser
@@ -8,9 +8,8 @@
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
- * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
+ * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
- * @version CVS: $Id: ClassCommentParser.php 270281 2008-12-02 02:38:34Z squiz $
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
@@ -26,9 +25,9 @@
* @package PHP_CodeSniffer
* @author Greg Sherwood <gsherwood@squiz.net>
* @author Marc McIntyre <mmcintyre@squiz.net>
- * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
+ * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
* @license http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
- * @version Release: 1.3.0
+ * @version Release: 1.3.3
* @link http://pear.php.net/package/PHP_CodeSniffer
*/
class PHP_CodeSniffer_CommentParser_ClassCommentParser extends PHP_CodeSniffer_CommentParser_AbstractParser
Oops, something went wrong.

0 comments on commit a8c3b2e

Please sign in to comment.