当前位置: 首页>>代码示例>>PHP>>正文


PHP PHP_CodeSniffer::setTokenListeners方法代码示例

本文整理汇总了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();
 }
开发者ID:austinpapp,项目名称:push-notifications-temp,代码行数:43,代码来源:CLI.php

示例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));
 }
开发者ID:austinpapp,项目名称:push-notifications-temp,代码行数:29,代码来源:ErrorSuppressionTest.php

示例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));
 }
开发者ID:natmchugh,项目名称:PHP_CodeSniffer,代码行数:27,代码来源:ErrorSuppressionTest.php


注:本文中的PHP_CodeSniffer::setTokenListeners方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。