本文整理汇总了PHP中PHP_CodeSniffer::getInstalledStandardPath方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer::getInstalledStandardPath方法的具体用法?PHP PHP_CodeSniffer::getInstalledStandardPath怎么用?PHP PHP_CodeSniffer::getInstalledStandardPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP_CodeSniffer
的用法示例。
在下文中一共展示了PHP_CodeSniffer::getInstalledStandardPath方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: suite
/**
* Add all sniff unit tests into a test suite.
*
* Sniff unit tests are found by recursing through the 'Tests' directory
* of each installed coding standard.
*
* @return PHPUnit_Framework_TestSuite
*/
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('PHP CodeSniffer Standards');
$baseDir = pathinfo(getcwd() . "/Ongr", PATHINFO_DIRNAME);
\PHP_CodeSniffer::setConfigData('installed_paths', $baseDir);
$path = pathinfo(\PHP_CodeSniffer::getInstalledStandardPath('Ongr'), PATHINFO_DIRNAME);
$testsDir = $path . DIRECTORY_SEPARATOR . 'Tests' . DIRECTORY_SEPARATOR . 'Unit';
$directoryIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($testsDir));
/** @var \SplFileInfo $fileinfo */
foreach ($directoryIterator as $file) {
// Skip hidden and extension must be php.
if ($file->getFilename()[0] === '.' || pathinfo($file, PATHINFO_EXTENSION) !== 'php') {
continue;
}
$className = str_replace([$baseDir . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR], ['', '\\'], substr($file, 0, -4));
$suite->addTest(new $className('getErrorList'));
}
return $suite;
}
示例2: process
private function process($files, $interactive = true)
{
$standards = 'Webasyst';
if (PHP_CodeSniffer::isInstalledStandard($standards) === false) {
$this->tracef('WARNING: %s standard not found, will used PSR2. Some rules are differ', $standards);
$standards = 'PSR2';
}
if (is_array($standards) === false) {
$standards = array($standards);
}
$phpcs = new PHP_CodeSniffer(0, 4, 'UTF-8', $interactive);
// Set file extensions if they were specified. Otherwise,
// let PHP_CodeSniffer decide on the defaults.
if (true) {
$extensions = array('php', 'js', 'css');
$phpcs->setAllowedFileExtensions($extensions);
}
if (is_array($files) === false) {
$files = array($files);
}
// Reset the members.
// Ensure this option is enabled or else line endings will not always
// be detected properly for files created on a Mac with the /r line ending.
ini_set('auto_detect_line_endings', true);
$sniffs = array();
foreach ($standards as $standard) {
$installed = $phpcs->getInstalledStandardPath($standard);
if ($installed !== null) {
$standard = $installed;
} else {
if (is_dir($standard) === true && is_file(realpath($standard . '/ruleset.xml')) === true) {
$standard = realpath($standard . '/ruleset.xml');
}
}
$sniffs = array_merge($sniffs, $phpcs->processRuleset($standard));
}
//end foreach
$sniffRestrictions = array();
$phpcs->registerSniffs($sniffs, $sniffRestrictions);
$phpcs->populateTokenListeners();
// The SVN pre-commit calls process() to init the sniffs
// and ruleset so there may not be any files to process.
// But this has to come after that initial setup.
//define('PHP_CODESNIFFER_IN_TESTS',true);
$_SERVER['argc'] = 0;
$errors_count = 0;
foreach ($files as $file) {
$phpcsFile = $phpcs->processFile($file);
// Show progress information.
if ($phpcsFile !== null) {
$count = $phpcsFile->getErrorCount() + $phpcsFile->getWarningCount();
if (!$interactive && $count) {
$report = array('ERROR' => $phpcsFile->getErrors(), 'WARNING' => $phpcsFile->getWarnings());
$this->tracef("\nFILE: %s", str_replace($this->path . '/', '', $file));
$this->trace(str_repeat('-', 80));
foreach ($report as $type => $errors) {
foreach ($errors as $line => $line_errors) {
foreach ($line_errors as $column => $errors) {
foreach ($errors as $error) {
$this->tracef('%4d | %s | %s', $line, $type, $error['message']);
}
}
}
}
$this->trace(str_repeat('-', 80));
}
$errors_count += $count;
}
}
return $errors_count;
}