nubs /
sensible
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | #!/usr/bin/env php |
||
| 2 | <?php |
||
| 3 | require 'vendor/autoload.php'; |
||
| 4 | require 'vendor/squizlabs/php_codesniffer/autoload.php'; |
||
| 5 | |||
| 6 | use PHP_CodeSniffer\Config as PHPCSConfig; |
||
| 7 | use PHP_CodeSniffer\Files\FileList as PHPCSFileList; |
||
| 8 | use PHP_CodeSniffer\Reporter as PHPCSReporter; |
||
| 9 | use PHP_CodeSniffer\Ruleset as PHPCSRuleset; |
||
| 10 | use PHP_CodeSniffer\Util\Tokens as PHPCSTokens; |
||
| 11 | use PHPUnit\Util\Configuration as PHPUnitConfiguration; |
||
| 12 | use PHPUnit\TextUI\TestRunner as PHPUnitTestRunner; |
||
| 13 | |||
| 14 | $phpcsConfig = new PHPCSConfig(); |
||
| 15 | $phpcsConfig->standards = ['PSR1']; |
||
| 16 | $phpcsConfig->files = ['src', 'tests', 'build.php']; |
||
| 17 | $tokens = new PHPCSTokens(); |
||
| 18 | $phpcsRuleset = new PHPCSRuleset($phpcsConfig); |
||
| 19 | $phpcsReporter = new PHPCSReporter($phpcsConfig); |
||
| 20 | |||
| 21 | $phpcsFileList = new PHPCSFileList($phpcsConfig, $phpcsRuleset); |
||
| 22 | foreach ($phpcsFileList as $file) { |
||
| 23 | $file->process(); |
||
| 24 | $phpcsReporter->cacheFileReport($file, $phpcsConfig); |
||
|
0 ignored issues
–
show
|
|||
| 25 | $file->cleanUp(); |
||
| 26 | } |
||
| 27 | |||
| 28 | $phpcsReporter->printReports(); |
||
| 29 | |||
| 30 | $phpcsViolations = $phpcsReporter->totalErrors + $phpcsReporter->totalWarnings; |
||
| 31 | if ($phpcsViolations > 0) { |
||
| 32 | exit(1); |
||
| 33 | } |
||
| 34 | |||
| 35 | $phpunitConfiguration = PHPUnitConfiguration::getInstance(__DIR__ . '/phpunit.xml'); |
||
| 36 | $phpunitArguments = ['coverageHtml' => __DIR__ . '/coverage', 'configuration' => $phpunitConfiguration]; |
||
| 37 | $testRunner = new PHPUnitTestRunner(); |
||
| 38 | $result = $testRunner->doRun($phpunitConfiguration->getTestSuiteConfiguration(), $phpunitArguments, false); |
||
| 39 | if (!$result->wasSuccessful()) { |
||
| 40 | exit(1); |
||
| 41 | } |
||
| 42 | |||
| 43 | $coverageReport = $result->getCodeCoverage()->getReport(); |
||
| 44 | if ($coverageReport->getNumExecutedLines() !== $coverageReport->getNumExecutableLines()) { |
||
| 45 | file_put_contents('php://stderr', "Code coverage was NOT 100%\n"); |
||
| 46 | exit(1); |
||
| 47 | } |
||
| 48 | |||
| 49 | file_put_contents('php://stderr', "Code coverage was 100%\n"); |
||
| 50 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.