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


PHP PHP_CodeSniffer::processFile方法代码示例

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


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

示例1: testSniff

 /**
  * Tests the extending classes Sniff class.
  */
 public final function testSniff()
 {
     // Skip this test if we can't run in this environment.
     if ($this->shouldSkipTest() === true) {
         $this->markTestSkipped();
     }
     $testFiles = $this->getTestFiles();
     $sniffCodes = $this->getSniffCodes();
     self::$phpcs->initStandard(dirname(__DIR__) . '/src/Drupal', $sniffCodes);
     $failureMessages = array();
     foreach ($testFiles as $testFile) {
         try {
             $phpcsFile = self::$phpcs->processFile($testFile);
         } catch (Exception $e) {
             $this->fail('An unexpected exception has been caught: ' . $e->getMessage());
         }
         $failures = $this->generateFailureMessages($phpcsFile);
         $failureMessages = array_merge($failureMessages, $failures);
         if ($phpcsFile->getFixableCount() > 0) {
             // Attempt to fix the errors.
             $phpcsFile->fixer->fixFile();
             $fixable = $phpcsFile->getFixableCount();
             if ($fixable > 0) {
                 $filename = basename($testFile);
                 $failureMessages[] = "Failed to fix {$fixable} fixable violations in {$filename}";
             }
         }
     }
     //end foreach()
     if (empty($failureMessages) === false) {
         $this->fail(implode(PHP_EOL, $failureMessages));
     }
 }
开发者ID:robloach,项目名称:php_codesniffer_drupal,代码行数:36,代码来源:CoderSniffUnitTest.php

示例2: sniffFile

 /**
  * Sniff a file and return resulting file object
  *
  * @param string $filename Filename to sniff
  * @param string $targetPhpVersion Value of 'testVersion' to set on PHPCS object
  * @return PHP_CodeSniffer_File File object
  */
 public function sniffFile($filename, $targetPhpVersion = null)
 {
     if (null !== $targetPhpVersion) {
         PHP_CodeSniffer::setConfigData('testVersion', $targetPhpVersion, true);
     }
     $filename = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . $filename;
     try {
         $phpcsFile = self::$phpcs->processFile($filename);
     } catch (Exception $e) {
         $this->fail('An unexpected exception has been caught: ' . $e->getMessage());
         return false;
     }
     return $phpcsFile;
 }
开发者ID:christopheg,项目名称:PHPCompatibility,代码行数:21,代码来源:BaseSniffTest.php

示例3: testSniff

 /**
  * Tests the extending classes Sniff class.
  *
  * @return void
  * @throws PHPUnit_Framework_Error
  */
 public final function testSniff()
 {
     // Skip this test if we can't run in this environment.
     if ($this->shouldSkipTest() === true) {
         $this->markTestSkipped();
     }
     $testFiles = $this->getTestFiles();
     $sniffCodes = $this->getSniffCodes();
     // Determine the standard to be used from the class name.
     $class_name_parts = explode('_', get_class($this));
     $standard = $class_name_parts[0];
     $failureMessages = array();
     foreach ($testFiles as $testFile) {
         self::$phpcs->initStandard("coder_sniffer/{$standard}", $sniffCodes);
         $filename = basename($testFile);
         try {
             $cliValues = $this->getCliValues($filename);
             self::$phpcs->cli->setCommandLineValues($cliValues);
             $phpcsFile = self::$phpcs->processFile($testFile);
         } catch (Exception $e) {
             $this->fail('An unexpected exception has been caught: ' . $e->getMessage());
         }
         $failures = $this->generateFailureMessages($phpcsFile);
         $failureMessages = array_merge($failureMessages, $failures);
         // Attempt to fix the errors.
         // Re-initialize the standard to use all sniffs for the fixer.
         self::$phpcs->initStandard("coder_sniffer/{$standard}");
         self::$phpcs->cli->setCommandLineValues($cliValues);
         $phpcsFile = self::$phpcs->processFile($testFile);
         $phpcsFile->fixer->fixFile();
         $fixable = $phpcsFile->getFixableCount();
         if ($fixable > 0) {
             $failureMessages[] = "Failed to fix {$fixable} fixable violations in {$filename}";
         }
         // Check for a .fixed file to check for accuracy of fixes.
         $fixedFile = $testFile . '.fixed';
         if (file_exists($fixedFile) === true) {
             $diff = $phpcsFile->fixer->generateDiff($fixedFile);
             if (trim($diff) !== '') {
                 $filename = basename($testFile);
                 $fixedFilename = basename($fixedFile);
                 $failureMessages[] = "Fixed version of {$filename} does not match expected version in {$fixedFilename}; the diff is\n{$diff}";
             }
         }
     }
     //end foreach
     if (empty($failureMessages) === false) {
         $this->fail(implode(PHP_EOL, $failureMessages));
     }
 }
开发者ID:atif-shaikh,项目名称:DCX-Profile,代码行数:56,代码来源:CoderSniffUnitTest.php

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

示例5: runTest

 /**
  * Tests the extending classes Sniff class.
  *
  * @test
  * @return void
  * @throws PHPUnit_Framework_Error
  */
 public final function runTest()
 {
     // Skip this test if we can't run in this environment.
     if ($this->shouldSkipTest() === true) {
         $this->markTestSkipped();
     }
     if (!defined('TEST_PATH') || realpath(TEST_PATH) === false) {
         throw new \Exception('TEST_PATH is not defined');
     }
     $testClassFile = (new ReflectionClass(get_class($this)))->getFileName();
     $testClassFile = realpath($testClassFile);
     $testFile = dirname($testClassFile) . '/' . basename($testClassFile, '.php') . '.inc';
     if (!is_file($testFile)) {
         $this->fail("Required file [{$testFile}] not found");
     }
     self::$phpcs->process(array(), $this->getStandardName(), array($this->getSniffCode()));
     self::$phpcs->setIgnorePatterns(array());
     try {
         $phpcsFile = self::$phpcs->processFile($testFile);
     } catch (Exception $e) {
         $this->fail('An unexpected exception has been caught: ' . $e->getMessage());
     }
     $failureMessages = $this->generateFailureMessages($phpcsFile);
     if (empty($failureMessages) === false) {
         $this->fail(implode(PHP_EOL, $failureMessages));
     }
 }
开发者ID:chr0n1x,项目名称:php_codesniffer_tests,代码行数:34,代码来源:AbstractSniffUnitTest.php

示例6: testSniff

 /**
  * Tests the extending classes Sniff class.
  *
  * @return void
  * @throws PHPUnit_Framework_Error
  */
 public final function testSniff()
 {
     // Skip this test if we can't run in this environment.
     if ($this->shouldSkipTest() === true) {
         $this->markTestSkipped();
     }
     self::$phpcs->initStandard(self::$standardName, [self::$sniffCode]);
     self::$phpcs->setIgnorePatterns([]);
     $failureMessages = [];
     foreach (self::$testFiles as $testFile) {
         $filename = basename($testFile);
         try {
             $cliValues = $this->getCliValues($filename);
             self::$phpcs->cli->setCommandLineValues($cliValues);
             $phpcsFile = self::$phpcs->processFile($testFile);
         } catch (Exception $e) {
             $this->fail('An unexpected exception has been caught: ' . $e->getMessage());
         }
         $failures = $this->generateFailureMessages($phpcsFile);
         $failureMessages = array_merge($failureMessages, $failures);
     }
     if (empty($failureMessages) === false) {
         $this->fail(implode(PHP_EOL, $failureMessages));
     }
 }
开发者ID:suitmedia,项目名称:php-code-standards,代码行数:31,代码来源:AbstractSniffUnitTest.php

示例7: runTest

 /**
  * Tests the extending classes Sniff class.
  *
  * @return void
  * @throws PHPUnit_Framework_Error
  */
 protected final function runTest()
 {
     // Skip this test if we can't run in this environment.
     if ($this->shouldSkipTest() === true) {
         $this->markTestSkipped();
     }
     // The basis for determining file locations.
     $basename = substr(get_class($this), 0, -8);
     // The name of the coding standard we are testing.
     $standardName = substr($basename, 0, strpos($basename, '_'));
     // The class name of the sniff we are testing.
     $sniffClass = str_replace('_Tests_', '_Sniffs_', $basename) . 'Sniff';
     if (is_file(dirname(__FILE__) . '/../../CodeSniffer.php') === true) {
         // We have not been installed.
         $standardsDir = realpath(dirname(__FILE__) . '/../../CodeSniffer/Standards');
         $testFileBase = $standardsDir . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $basename) . 'UnitTest.';
     } else {
         // The name of the dummy file we are testing.
         $testFileBase = dirname(__FILE__) . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $basename) . 'UnitTest.';
     }
     // Get a list of all test files to check. These will have the same base
     // name but different extensions. We ignore the .php file as it is the
     // class.
     $testFiles = array();
     $dir = substr($testFileBase, 0, strrpos($testFileBase, DIRECTORY_SEPARATOR));
     $di = new DirectoryIterator($dir);
     foreach ($di as $file) {
         $path = $file->getPathname();
         if (substr($path, 0, strlen($testFileBase)) === $testFileBase) {
             if ($path !== $testFileBase . 'php') {
                 $testFiles[] = $path;
             }
         }
     }
     // Get them in order.
     sort($testFiles);
     self::$phpcs->process(array(), $standardName, array($sniffClass));
     self::$phpcs->setIgnorePatterns(array());
     $failureMessages = array();
     foreach ($testFiles as $testFile) {
         try {
             self::$phpcs->processFile($testFile);
         } catch (Exception $e) {
             $this->fail('An unexpected exception has been caught: ' . $e->getMessage());
         }
         $files = self::$phpcs->getFiles();
         if (empty($files) === true) {
             // File was skipped for some reason.
             echo "Skipped: {$testFile}\n";
             $this->markTestSkipped();
         }
         $file = array_pop($files);
         $failures = $this->generateFailureMessages($file);
         $failureMessages = array_merge($failureMessages, $failures);
     }
     //end foreach
     if (empty($failureMessages) === false) {
         $this->fail(implode(PHP_EOL, $failureMessages));
     }
 }
开发者ID:austinpapp,项目名称:push-notifications-temp,代码行数:66,代码来源:AbstractSniffUnitTest.php

示例8: validate

 /**
  * Validate the current check
  *
  * Validate the check on the specified repository. Returns an array of 
  * found issues.
  * 
  * @param pchRepository $repository 
  * @return void
  */
 public function validate(pchRepository $repository)
 {
     $cs = new PHP_CodeSniffer();
     $cs->process(array(), $this->standard);
     foreach ($this->getChangedFiles($repository) as $file) {
         $cs->processFile($file, stream_get_contents($this->getFileContents($repository, $file)));
     }
     $issues = array();
     foreach ($cs->getFilesErrors() as $file => $messages) {
         foreach ($messages['errors'] as $errors) {
             foreach ($errors as $line => $lineErrors) {
                 foreach ($lineErrors as $error) {
                     $issues[] = new pchIssue(E_ERROR, $file, $line, $error['source'] . ': ' . $error['message']);
                 }
             }
         }
         foreach ($messages['warnings'] as $errors) {
             foreach ($errors as $line => $lineErrors) {
                 foreach ($lineErrors as $error) {
                     $issues[] = new pchIssue(E_WARNING, $file, $line, $error['source'] . ': ' . $error['message']);
                 }
             }
         }
     }
     return $issues;
 }
开发者ID:kore,项目名称:php-commit-hooks,代码行数:35,代码来源:code_sniffer.php

示例9: it_generates_the_expected_warnings_and_errors

 /**
  * @test
  * @dataProvider fixturesProvider
  */
 public function it_generates_the_expected_warnings_and_errors($file, array $expectedErrors, array $expectedWarnings)
 {
     $codeSniffer = new \PHP_CodeSniffer();
     $codeSniffer->process(array(), $this->getRulesetXmlPath(), array($this->getRuleName()));
     $sniffedFile = $codeSniffer->processFile($file);
     $this->fileHasExpectedErrors($sniffedFile, $expectedErrors);
     $this->fileHasExpectedWarnings($sniffedFile, $expectedWarnings);
 }
开发者ID:matthiasnoback,项目名称:php-coding-standard,代码行数:12,代码来源:AbstractSniffTest.php

示例10: sniffFile

 /**
  * @param $file string
  *
  * @return int ErrorCount
  */
 protected function sniffFile($file)
 {
     $phpCs = new \PHP_CodeSniffer();
     $phpCs->initStandard(realpath(__DIR__ . '/../Standards/Symfony2'));
     $result = $phpCs->processFile($file);
     $errors = $result->getErrorCount();
     return $errors;
 }
开发者ID:move-elevator,项目名称:symfony-coding-standard,代码行数:13,代码来源:PhpcsTestCase.php

示例11: executeOnPHPFile

 protected function executeOnPHPFile(File $file)
 {
     $code_sniffer = new \PHP_CodeSniffer($this->phpcs_verbosity, $this->phpcs_tab_width, $this->phpcs_encoding, self::PHPCS_NOT_INTERACTIVE_MODE);
     //Load the standard
     $code_sniffer->process(array(), $this->standard, array());
     $file_result = $code_sniffer->processFile($file->getPath(), $file->getContent());
     if ($file_result->getErrorCount()) {
         $this->handlePHPCSErrors($file, $file_result);
     }
 }
开发者ID:polishdeveloper,项目名称:stark,代码行数:10,代码来源:PHPCS.php

示例12: testSniff

 /**
  * Tests the extending classes Sniff class.
  */
 public final function testSniff()
 {
     // Skip this test if we can't run in this environment.
     if ($this->shouldSkipTest() === true) {
         $this->markTestSkipped();
     }
     $testFiles = $this->getTestFiles();
     $sniffCodes = $this->getSniffCodes();
     self::$phpcs->process(array(), 'coder_sniffer/Drupal', $sniffCodes);
     $failureMessages = array();
     foreach ($testFiles as $testFile) {
         try {
             $phpcsFile = self::$phpcs->processFile($testFile);
         } catch (Exception $e) {
             $this->fail('An unexpected exception has been caught: ' . $e->getMessage());
         }
         $failures = $this->generateFailureMessages($phpcsFile);
         $failureMessages = array_merge($failureMessages, $failures);
     }
     //end foreach
     if (empty($failureMessages) === false) {
         $this->fail(implode(PHP_EOL, $failureMessages));
     }
 }
开发者ID:MODCDE,项目名称:CDE_SS,代码行数:27,代码来源:CoderSniffUnitTest.php

示例13: processFile

 public function processFile($file, $contents = null)
 {
     if ($this->_cacheable) {
         // If we have cached results and they're not stale, don't bother processing
         $cacheTime = $this->_dbFiles->getTimeParsed($file);
         $mtime = filemtime($file);
         if ($cacheTime !== null && $cacheTime > $mtime) {
             return;
         }
     }
     parent::processFile($file, $contents);
     if ($this->_cacheable) {
         $this->_dbFiles->registerFile($file);
     }
 }
开发者ID:jpchristie,项目名称:Scisr,代码行数:15,代码来源:CodeSniffer.php

示例14: runTest

 /**
  * Tests the extending classes Sniff class.
  *
  * @return void
  * @throws PHPUnit_Framework_Error
  * @test
  */
 public final function runTest()
 {
     self::$_phpcs->process([], 'DWS', [$this->_getSniffName()]);
     self::$_phpcs->setIgnorePatterns([]);
     $testFile = dirname(__DIR__) . '/tests/' . str_replace('_', '/', get_class($this)) . '.inc';
     if (!file_exists($testFile)) {
         $this->markTestSkipped();
         return;
     }
     try {
         self::$_phpcs->processFile($testFile);
     } catch (Exception $e) {
         $this->fail("An unexpected exception has been caught: {$e->getMessage()}");
     }
     $files = self::$_phpcs->getFiles();
     if ($files === []) {
         echo "Skipped: {$testFile}\n";
         $this->markTestSkipped();
     }
     $failureMessages = $this->generateFailureMessages($files[0]);
     if (count($failureMessages) > 0) {
         $this->fail(implode("\n", $failureMessages));
     }
 }
开发者ID:ezzy1337,项目名称:dws-coding-standard,代码行数:31,代码来源:AbstractSniffUnitTest.php

示例15: runTest

 /**
  * Tests the extending classes Sniff class.
  *
  * @return void
  */
 protected final function runTest()
 {
     // Skip this test if we can't run in this environment.
     if ($this->shouldSkipTest() === true) {
         $this->markTestSkipped();
     }
     // The basis for determining file locations.
     $basename = substr(get_class($this), 0, -8);
     // The name of the coding standard we are testing.
     $standardName = substr($basename, 0, strpos($basename, '_'));
     // The code of the sniff we are testing.
     $parts = explode('_', $basename);
     $sniffCode = $parts[0] . '.' . $parts[2] . '.' . $parts[3];
     // The name of the dummy file we are testing.
     $testFileBase = dirname(__DIR__) . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $basename) . 'UnitTest.';
     // Get a list of all test files to check. These will have the same base
     // name but different extensions. We ignore the .php file as it is the class.
     $testFiles = array();
     $dir = substr($testFileBase, 0, strrpos($testFileBase, DIRECTORY_SEPARATOR));
     $iterator = new DirectoryIterator($dir);
     foreach ($iterator as $file) {
         $path = $file->getPathname();
         if (substr($path, 0, strlen($testFileBase)) === $testFileBase) {
             if ($path !== $testFileBase . 'php') {
                 $testFiles[] = $path;
             }
         }
     }
     // Get them in order.
     sort($testFiles);
     self::$phpcs->process(array(), $standardName . '/ruleset.phpunit.xml', array($sniffCode));
     self::$phpcs->setIgnorePatterns(array());
     $failureMessages = array();
     foreach ($testFiles as $testFile) {
         try {
             $phpcsFile = self::$phpcs->processFile($testFile);
         } catch (Exception $e) {
             $this->fail('An unexpected exception has been caught: ' . $e->getMessage());
         }
         $failures = $this->generateFailureMessages($phpcsFile);
         $failureMessages = array_merge($failureMessages, $failures);
     }
     if (empty($failureMessages) === false) {
         $this->fail(implode(PHP_EOL, $failureMessages));
     }
 }
开发者ID:contao-community-alliance,项目名称:coding-standard,代码行数:51,代码来源:AbstractSniffUnitTest.php


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