本文整理汇总了PHP中PHP_CodeSniffer::setTokenListeners方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer::setTokenListeners方法的具体用法?PHP PHP_CodeSniffer::setTokenListeners怎么用?PHP PHP_CodeSniffer::setTokenListeners使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP_CodeSniffer
的用法示例。
在下文中一共展示了PHP_CodeSniffer::setTokenListeners方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: explainStandard
/**
* Prints a report showing the sniffs contained in a standard.
*
* @param string $standard The standard to validate.
*
* @return void
*/
public function explainStandard($standard)
{
$phpcs = new PHP_CodeSniffer();
$phpcs->setTokenListeners($standard);
$sniffs = $phpcs->getSniffs();
$sniffs = array_keys($sniffs);
sort($sniffs);
ob_start();
$lastStandard = '';
$lastCount = '';
$sniffCount = count($sniffs);
$sniffs[] = '___';
echo PHP_EOL . "The {$standard} standard contains {$sniffCount} sniffs" . PHP_EOL;
ob_start();
foreach ($sniffs as $sniff) {
$parts = explode('_', str_replace('\\', '_', $sniff));
if ($lastStandard === '') {
$lastStandard = $parts[0];
}
if ($parts[0] !== $lastStandard) {
$sniffList = ob_get_contents();
ob_end_clean();
echo PHP_EOL . $lastStandard . ' (' . $lastCount . ' sniffs)' . PHP_EOL;
echo str_repeat('-', strlen($lastStandard . $lastCount) + 10);
echo PHP_EOL;
echo $sniffList;
$lastStandard = $parts[0];
$lastCount = 0;
ob_start();
}
echo ' ' . $parts[0] . '.' . $parts[2] . '.' . substr($parts[3], 0, -5) . PHP_EOL;
$lastCount++;
}
//end foreach
ob_end_clean();
}
示例2: testSuppressFile
/**
* Test suppressing a whole file.
*
* @return void
*/
public function testSuppressFile()
{
$phpcs = new PHP_CodeSniffer();
$phpcs->setTokenListeners('Squiz', array('Generic_Sniffs_Commenting_TodoSniff'));
$phpcs->populateTokenListeners();
// Process without suppression.
$content = '<?php ' . PHP_EOL . '//TODO: write some code';
$phpcs->processFile('noSuppressionTest.php', $content);
$files = $phpcs->getFiles();
$file = $files[0];
$warnings = $file->getWarnings();
$numWarnings = $file->getWarningCount();
$this->assertEquals(1, $numWarnings);
$this->assertEquals(1, count($warnings));
// Process with suppression.
$content = '<?php ' . PHP_EOL . '// @codingStandardsIgnoreFile' . PHP_EOL . '//TODO: write some code';
$phpcs->processFile('suppressionTest.php', $content);
$files = $phpcs->getFiles();
$file = $files[1];
$warnings = $file->getWarnings();
$numWarnings = $file->getWarningCount();
$this->assertEquals(0, $numWarnings);
$this->assertEquals(0, count($warnings));
}
示例3: testSuppressFile
/**
* Test suppressing a whole file.
*
* @return void
*/
public function testSuppressFile()
{
$phpcs = new PHP_CodeSniffer();
$phpcs->setTokenListeners('Squiz', array('Squiz_Sniffs_Commenting_FileCommentSniff'));
$phpcs->populateTokenListeners();
// Process without suppression.
$content = '<?php ' . PHP_EOL . '$var = FALSE;';
$phpcs->processFile('noSuppressionTest.php', $content);
$files = $phpcs->getFiles();
$file = $files[0];
$errors = $file->getErrors();
$numErrors = $file->getErrorCount();
$this->assertEquals(1, $numErrors);
$this->assertEquals(1, count($errors));
$this->assertEquals(1, count($files));
// Process with suppression.
$content = '<?php ' . PHP_EOL . '// @codingStandardsIgnoreFile' . PHP_EOL . '$var = FALSE;';
$phpcs->processFile('suppressionTest.php', $content);
// The file shouldn't even be added to the $files array.
$files = $phpcs->getFiles();
$this->assertEquals(1, count($files));
}