當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。