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


PHP PHP_CodeSniffer::populateTokenListeners方法代码示例

本文整理汇总了PHP中PHP_CodeSniffer::populateTokenListeners方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer::populateTokenListeners方法的具体用法?PHP PHP_CodeSniffer::populateTokenListeners怎么用?PHP PHP_CodeSniffer::populateTokenListeners使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHP_CodeSniffer的用法示例。


在下文中一共展示了PHP_CodeSniffer::populateTokenListeners方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: analyze

 protected static function analyze(array $sniffs, $files)
 {
     $sniffs = array_map(static function ($sniff) {
         $sniff = __DIR__ . '/../../../../src/' . $sniff . '.php';
         static::assertFileExists($sniff, 'Sniff does not exist');
         return $sniff;
     }, $sniffs);
     $files = array_map(static function ($file) {
         static::assertFileExists($file, 'Source file does not exists');
         return $file;
     }, (array) $files);
     $codeSniffer = new PHP_CodeSniffer();
     $codeSniffer->registerSniffs($sniffs, []);
     $codeSniffer->populateTokenListeners();
     $report = [];
     foreach ($files as $file) {
         $phpcsFile = $codeSniffer->processFile($file);
         $report[$file] = [];
         $report[$file]['numWarnings'] = $phpcsFile->getWarningCount();
         $report[$file]['warnings'] = $phpcsFile->getWarnings();
         $report[$file]['numErrors'] = $phpcsFile->getErrorCount();
         $report[$file]['errors'] = $phpcsFile->getErrors();
     }
     return $report;
 }
开发者ID:asev,项目名称:kodierungsregelwerksammlung,代码行数:25,代码来源:AbstractTestCase.php

示例2: refreshTokenListeners

 /**
  * Rebuilds the list of listeners to ensure their state is cleared.
  *
  * @return void
  */
 public function refreshTokenListeners()
 {
     $this->phpcs->populateTokenListeners();
     $this->_listeners = $this->phpcs->getTokenSniffs();
 }
开发者ID:dereuromark,项目名称:cakephp-codesniffer,代码行数:10,代码来源:File.php

示例3: 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

示例4: 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

示例5: 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;
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:71,代码来源:webasystCompress.cli.php


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