From 0d8f825395c3bc9645dc818495a3fbe15b3d00fa Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Thu, 28 Nov 2019 22:47:46 +0100 Subject: [PATCH 01/34] allow monolog 2.x closes GH-65 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4518c6b..874b4f2 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "require": { "php": "^7.1", "ext-dom": "*", - "monolog/monolog": "~1.7", + "monolog/monolog": "~1.7|~2.0", "phpunit/php-file-iterator": "~2.0", "symfony/console": "~2.1|~3.0|~4.0|~5.0" }, From daeda37c30dbe6ebe7fa46ccd8ccfc38508e77a7 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Fri, 29 Nov 2019 02:22:28 +0100 Subject: [PATCH 02/34] update phpstan --- .travis.yml | 2 +- composer.json | 2 +- phpstan.neon | 7 +++++++ phpstan_baseline.neon | 27 ++++++++++++++++++++++++++ src/PHPCodeBrowser/View/ViewReview.php | 3 ++- 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 phpstan.neon create mode 100644 phpstan_baseline.neon diff --git a/.travis.yml b/.travis.yml index 4391de5..181a1be 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,5 +17,5 @@ before_script: script: - vendor/bin/phpcs -s --standard=MO4 src/PHPCodeBrowser/ - - vendor/bin/phpstan analyse --no-progress --level=1 src/PHPCodeBrowser/ + - vendor/bin/phpstan analyse --no-progress - vendor/bin/phpunit diff --git a/composer.json b/composer.json index 874b4f2..be84fca 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "mayflower/mo4-coding-standard": "^3.0", "phploc/phploc": "*", "phpmd/phpmd": "1.5.*|~2.6", - "phpstan/phpstan": "^0.10.5", + "phpstan/phpstan": "^0.12.5", "phpunit/phpunit": "~7.3", "sebastian/phpcpd": "*" }, diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..4a10649 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,7 @@ +parameters: + level: 4 + paths: + - %rootDir%/../../../src/PHPCodeBrowser + +includes: + - phpstan_baseline.neon diff --git a/phpstan_baseline.neon b/phpstan_baseline.neon new file mode 100644 index 0000000..ccf5eef --- /dev/null +++ b/phpstan_baseline.neon @@ -0,0 +1,27 @@ +parameters: + ignoreErrors: + - + message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#" + count: 1 + path: src/PHPCodeBrowser/AbstractPlugin.php + + - + message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#" + count: 5 + path: src/PHPCodeBrowser/Plugins/ErrorCPD.php + + - + message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#" + count: 1 + path: src/PHPCodeBrowser/Plugins/ErrorCRAP.php + + - + message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#" + count: 2 + path: src/PHPCodeBrowser/Plugins/ErrorCoverage.php + + - + message: "#^Access to an undefined property DOMNode\\:\\:\\$wholeText\\.$#" + count: 1 + path: src/PHPCodeBrowser/View/ViewReview.php + diff --git a/src/PHPCodeBrowser/View/ViewReview.php b/src/PHPCodeBrowser/View/ViewReview.php index 2671d8a..8126ce0 100644 --- a/src/PHPCodeBrowser/View/ViewReview.php +++ b/src/PHPCodeBrowser/View/ViewReview.php @@ -325,8 +325,9 @@ private function formatSourceCode(string $filename, array $outputIssues): string $lineNumber = 0; $linePlaces = floor(log($lines->length, 10)) + 1; - /** @var DOMElement:: $line */ foreach ($lines as $line) { + /** @var DOMElement $line */ + $line = $line; ++$lineNumber; $line->setAttribute('id', 'line_'.$lineNumber); From a752b04c86bbbbca95273d47083b009e02358e24 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Fri, 29 Nov 2019 02:25:37 +0100 Subject: [PATCH 03/34] update MO4 CS --- .travis.yml | 2 +- composer.json | 2 +- src/PHPCodeBrowser/AbstractPlugin.php | 8 +++++++- src/PHPCodeBrowser/Application.php | 3 ++- src/PHPCodeBrowser/CLIController.php | 4 ++++ src/PHPCodeBrowser/Command/RunCommand.php | 6 ++++-- src/PHPCodeBrowser/File.php | 13 ++++++++----- src/PHPCodeBrowser/Helper/IOHelper.php | 9 +++++++-- src/PHPCodeBrowser/IssueXML.php | 2 ++ src/PHPCodeBrowser/Plugins/ErrorCPD.php | 2 ++ src/PHPCodeBrowser/Plugins/ErrorCRAP.php | 1 + src/PHPCodeBrowser/Plugins/ErrorCoverage.php | 4 ++++ src/PHPCodeBrowser/Plugins/ErrorPMD.php | 1 + src/PHPCodeBrowser/SourceHandler.php | 6 +++--- src/PHPCodeBrowser/Tests/AbstractTestCase.php | 4 ++++ src/PHPCodeBrowser/Tests/CLIControllerTest.php | 1 - src/PHPCodeBrowser/Tests/FileTest.php | 3 +-- src/PHPCodeBrowser/Tests/Fixtures/Bad.php | 1 - src/PHPCodeBrowser/Tests/Fixtures/Good.php | 1 - .../Tests/Helper/IOHelperTest.php | 5 +++-- src/PHPCodeBrowser/Tests/SourceHandlerTest.php | 2 ++ .../Tests/View/ViewReviewTest.php | 1 - src/PHPCodeBrowser/View/ViewAbstract.php | 13 +++++++++++-- src/PHPCodeBrowser/View/ViewReview.php | 18 ++++++++++++++++++ 24 files changed, 86 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index 181a1be..7143c74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,6 @@ before_script: - if [ "${DEPENDENCIES}" = "highest" ]; then composer update --prefer-dist --no-interaction --no-progress; fi; script: - - vendor/bin/phpcs -s --standard=MO4 src/PHPCodeBrowser/ + - vendor/bin/phpcs -s --standard=MO4 --exclude=SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions src/PHPCodeBrowser/ - vendor/bin/phpstan analyse --no-progress - vendor/bin/phpunit diff --git a/composer.json b/composer.json index be84fca..2200788 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ }, "require-dev": { "kherge/box": "~2.7", - "mayflower/mo4-coding-standard": "^3.0", + "mayflower/mo4-coding-standard": "^5.0", "phploc/phploc": "*", "phpmd/phpmd": "1.5.*|~2.6", "phpstan/phpstan": "^0.12.5", diff --git a/src/PHPCodeBrowser/AbstractPlugin.php b/src/PHPCodeBrowser/AbstractPlugin.php index 7ded64f..a8d64f0 100644 --- a/src/PHPCodeBrowser/AbstractPlugin.php +++ b/src/PHPCodeBrowser/AbstractPlugin.php @@ -51,6 +51,7 @@ * * @since File available since 0.1.0 */ + namespace PHPCodeBrowser; use \DOMElement; @@ -152,11 +153,12 @@ public function __construct(IssueXML $issueXml, array $options = []) /** * Gets a list of File objects, including their issues. * - * @return File[] List of files with issues. + * @return array List of files with issues. */ public function getFileList(): array { $files = []; + foreach ($this->getFilesWithIssues() as $name) { $files[] = new File($name, $this->getIssuesByFile($name)); } @@ -175,6 +177,7 @@ public function getFileList(): array public function getIssuesByFile(string $filename): array { $issues = []; + foreach ($this->getIssueNodes($filename) as $issueNode) { $issues = array_merge( $issues, @@ -196,6 +199,7 @@ public function getFilesWithIssues(): array $issueNodes = $this->issueXml->query( sprintf('/*/%s/file[@name]', $this->pluginName) ); + foreach ($issueNodes as $node) { $fileNames[] = $node->getAttribute('name'); } @@ -217,10 +221,12 @@ public function getFilesWithIssues(): array public function mapIssues(DOMNode $element, string $filename): array { $errorList = []; + foreach ($element->childNodes as $child) { if (!($child instanceof DOMElement)) { continue; } + $errorList[] = new Issue( $filename, $this->getLineStart($child), diff --git a/src/PHPCodeBrowser/Application.php b/src/PHPCodeBrowser/Application.php index 6b22cb6..66555d0 100644 --- a/src/PHPCodeBrowser/Application.php +++ b/src/PHPCodeBrowser/Application.php @@ -50,6 +50,7 @@ * * @since File available since 1.1 */ + namespace PHPCodeBrowser; use PHPCodeBrowser\Command\RunCommand; @@ -92,7 +93,7 @@ protected function getCommandName(InputInterface $input): string /** * Gets the default commands that should always be available. * - * @return Command[] An array of default Command instances + * @return array An array of default Command instances */ protected function getDefaultCommands(): array { diff --git a/src/PHPCodeBrowser/CLIController.php b/src/PHPCodeBrowser/CLIController.php index 6ba8b24..88976fb 100644 --- a/src/PHPCodeBrowser/CLIController.php +++ b/src/PHPCodeBrowser/CLIController.php @@ -62,6 +62,7 @@ if (!defined('PHPCB_ROOT_DIR')) { define('PHPCB_ROOT_DIR', \dirname(__FILE__, 2).'/'); } + if (!defined('PHPCB_TEMPLATE_DIR')) { define('PHPCB_TEMPLATE_DIR', \dirname(__FILE__, 3).'/templates'); } @@ -192,9 +193,11 @@ public function __construct(?string $logPath, ?array $projectSource, string $htm $this->htmlOutputDir = $htmlOutputDir; $this->excludeExpressions = $excludeExpressions; $this->excludePatterns = $excludePatterns; + foreach ($pluginOptions as $plugin => $options) { $this->pluginOptions["Error{$plugin}"] = $options; } + $this->ioHelper = $ioHelper; $this->debugLog = $debugLog; $this->registeredPlugins = []; @@ -238,6 +241,7 @@ public function run(): void } elseif (is_file($this->htmlOutputDir)) { $this->ioHelper->deleteFile($this->htmlOutputDir); } + $this->ioHelper->createDirectory($this->htmlOutputDir); // init needed classes diff --git a/src/PHPCodeBrowser/Command/RunCommand.php b/src/PHPCodeBrowser/Command/RunCommand.php index 5aaf04c..30240ed 100644 --- a/src/PHPCodeBrowser/Command/RunCommand.php +++ b/src/PHPCodeBrowser/Command/RunCommand.php @@ -205,7 +205,6 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int return 0; } - /** * @param InputInterface $input * @@ -245,7 +244,7 @@ protected function checkErrors(InputInterface $input): void * * Currently hard-coded. * - * @return string[] Class names of error plugins + * @return array Class names of error plugins */ protected function getAvailablePlugins(): array { @@ -274,6 +273,7 @@ protected function disablePlugins(array $disabledPlugins, array $plugins): array foreach ($plugins as $pluginKey => $plugin) { $name = substr($plugin, \strlen('Error')); + if (!\in_array(strtolower($name), $disabledPlugins)) { continue; } @@ -296,8 +296,10 @@ protected function disablePlugins(array $disabledPlugins, array $plugins): array protected function convertIgnores(array $ignored, array $excludePCRE): array { $dirSep = preg_quote(DIRECTORY_SEPARATOR, '/'); + foreach ($ignored as $ignore) { $ig = realpath($ignore); + if (!$ig) { error_log("[Warning] {$ignore} does not exists"); } else { diff --git a/src/PHPCodeBrowser/File.php b/src/PHPCodeBrowser/File.php index f2fb9fe..d563c69 100644 --- a/src/PHPCodeBrowser/File.php +++ b/src/PHPCodeBrowser/File.php @@ -87,15 +87,15 @@ class File /** * Issues associated with this file. * - * @var Issue[] + * @var array */ private $issues; /** * Default constructor. * - * @param string $name The name of the file. - * @param Issue[] $issues + * @param string $name The name of the file. + * @param array $issues */ public function __construct(string $name, array $issues = []) { @@ -121,13 +121,14 @@ public function addIssue(Issue $issue): void 'Tried to add issue to wrong file.' ); } + $this->issues[] = $issue; } /** * Gets an array containing the issues for this file. * - * @return Issue[] The issues. + * @return array The issues. */ public function getIssues(): array { @@ -182,6 +183,7 @@ public function getIssueCount(): int public function getErrorCount(): int { $count = 0; + foreach ($this->issues as $issue) { if (strcasecmp($issue->severity, 'error') !== 0) { continue; @@ -217,13 +219,14 @@ public function mergeWith(File $file): void 'Tried to merge different files' ); } + $this->issues = array_merge($this->issues, $file->issues); } /** * Sorts an array of Files. Key value association will be preserved. * - * @param File[] $files The files to sort. + * @param array $files The files to sort. */ public static function sort(array &$files): void { diff --git a/src/PHPCodeBrowser/Helper/IOHelper.php b/src/PHPCodeBrowser/Helper/IOHelper.php index 98e463b..a6c5f1a 100644 --- a/src/PHPCodeBrowser/Helper/IOHelper.php +++ b/src/PHPCodeBrowser/Helper/IOHelper.php @@ -51,7 +51,6 @@ * @since File available since 0.1.0 */ - namespace PHPCodeBrowser\Helper; use DirectoryIterator; @@ -79,7 +78,6 @@ */ class IOHelper { - /** * Creates a file with given name and content. * If directories to file do not exists they will be created. @@ -97,6 +95,7 @@ public function createFile(string $fileName, string $fileContent): void if (!empty($path)) { $this->createDirectory($path); } + file_put_contents(realpath($path).'/'.$realName, $fileContent); } @@ -194,6 +193,7 @@ public function createDirectory(string $target): void public function deleteDirectory(string $source): void { $iterator = new DirectoryIterator($source); + while ($iterator->valid()) { $src = realpath($source.'/'.$iterator->current()); @@ -209,6 +209,7 @@ public function deleteDirectory(string $source): void $iterator->next(); } + unset($iterator); // delete the source root folder as well @@ -231,6 +232,7 @@ public function copyDirectory(string $source, string $target, array $exclude = [ // first check for target itself $this->createDirectory($target); $iterator = new DirectoryIterator($source); + while ($iterator->valid()) { $item = $iterator->current(); @@ -249,6 +251,7 @@ public function copyDirectory(string $source, string $target, array $exclude = [ $target.'/'.$item ); } + $iterator->next(); } } @@ -264,7 +267,9 @@ public static function getCommonPathPrefix(array $fileNames): string if (empty($fileNames)) { return '/'; } + $prefix = \dirname(array_shift($fileNames)); + foreach ($fileNames as $filename) { $prefix = self::getCurrentCommonPathPrefix($prefix, $filename); } diff --git a/src/PHPCodeBrowser/IssueXML.php b/src/PHPCodeBrowser/IssueXML.php index b246315..5e5beed 100644 --- a/src/PHPCodeBrowser/IssueXML.php +++ b/src/PHPCodeBrowser/IssueXML.php @@ -138,6 +138,7 @@ public function addDirectory(string $directory): IssueXML $realFileName = realpath($current); $xml = new DOMDocument('1.0', 'UTF-8'); $xml->validateOnParse = true; + if (@$xml->load(realpath($current))) { $this->addXMLFile($xml); } else { @@ -145,6 +146,7 @@ public function addDirectory(string $directory): IssueXML "[Warning] Could not read file '{$realFileName}'. ".'Make sure it contains valid xml.' ); } + unset($xml); } diff --git a/src/PHPCodeBrowser/Plugins/ErrorCPD.php b/src/PHPCodeBrowser/Plugins/ErrorCPD.php index b4f6160..426bebe 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCPD.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCPD.php @@ -103,6 +103,7 @@ public function mapIssues(DOMNode $element, string $filename): array $lineCount = (int) $parentNode->getAttribute('lines'); $result = []; + foreach ($files as $file) { $result[] = new Issue( $file->getAttribute('path'), @@ -162,6 +163,7 @@ protected function getIssueNodes(string $filename): DOMNodeList protected function getCpdDescription(DOMNodeList $allNodes, DOMNode $currentNode): string { $source = []; + foreach ($allNodes as $node) { if (!($node instanceof DOMElement) || $node->isSameNode($currentNode) diff --git a/src/PHPCodeBrowser/Plugins/ErrorCRAP.php b/src/PHPCodeBrowser/Plugins/ErrorCRAP.php index 128df5b..9240fc8 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCRAP.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCRAP.php @@ -131,6 +131,7 @@ public function mapIssues(DOMNode $element, string $filename): array } $crap = $child->getAttribute('crap'); + if (!$crap) { continue; } diff --git a/src/PHPCodeBrowser/Plugins/ErrorCoverage.php b/src/PHPCodeBrowser/Plugins/ErrorCoverage.php index d979a3d..9b6fe47 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCoverage.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCoverage.php @@ -136,12 +136,16 @@ public function mapIssues(DOMNode $element, string $filename): array $end = $begin; ++$next; + while ($next < $childCount) { $child = $children->item($next); + if (!$child instanceof DOMElement) { ++$next; + continue; } + if (!$this->representsUncoveredLOC($child)) { break; } diff --git a/src/PHPCodeBrowser/Plugins/ErrorPMD.php b/src/PHPCodeBrowser/Plugins/ErrorPMD.php index 82f0dd8..1ea42ae 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorPMD.php +++ b/src/PHPCodeBrowser/Plugins/ErrorPMD.php @@ -89,6 +89,7 @@ class ErrorPMD extends AbstractPlugin * @var string */ protected $lineStartAttr = 'beginline'; + /** * Name of the attribute that holds the number of the last line * of the issue. diff --git a/src/PHPCodeBrowser/SourceHandler.php b/src/PHPCodeBrowser/SourceHandler.php index b628df7..845abd4 100644 --- a/src/PHPCodeBrowser/SourceHandler.php +++ b/src/PHPCodeBrowser/SourceHandler.php @@ -88,7 +88,7 @@ class SourceHandler /** * Files to be included in the report * - * @var File[] + * @var array */ protected $files = []; @@ -130,7 +130,7 @@ public function addPlugin(AbstractPlugin $plugin): void /** * Add source files to the list. * - * @param SplFileInfo[]|string[]|\AppendIterator $files The files to add + * @param array|array|\AppendIterator $files The files to add */ public function addSourceFiles($files): void { @@ -180,7 +180,7 @@ public function getCommonPathPrefix(): string /** * Returns a sorted array of the files that should be in the report. * - * @return File[] + * @return array */ public function getFiles(): array { diff --git a/src/PHPCodeBrowser/Tests/AbstractTestCase.php b/src/PHPCodeBrowser/Tests/AbstractTestCase.php index abea4db..90b14da 100644 --- a/src/PHPCodeBrowser/Tests/AbstractTestCase.php +++ b/src/PHPCodeBrowser/Tests/AbstractTestCase.php @@ -124,6 +124,7 @@ protected function setUp(): void realpath(PHPCB_SOURCE_DIR).DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR.'testData' ); } + if (!\defined('PHPCB_TEST_LOGS')) { \define('PHPCB_TEST_LOGS', PHPCB_TEST_DIR.'/logs'); } @@ -176,6 +177,7 @@ protected function getSerializedErrors(): array protected function cleanUp(string $dir): void { $iterator = new \DirectoryIterator($dir); + while ($iterator->valid()) { // delete file if ($iterator->isFile()) { @@ -187,8 +189,10 @@ protected function cleanUp(string $dir): void $this->cleanUp($dir.'/'.$iterator->current()); rmdir($dir.'/'.$iterator->current()); } + $iterator->next(); } + unset($iterator); } } diff --git a/src/PHPCodeBrowser/Tests/CLIControllerTest.php b/src/PHPCodeBrowser/Tests/CLIControllerTest.php index 26320e8..dd89a01 100644 --- a/src/PHPCodeBrowser/Tests/CLIControllerTest.php +++ b/src/PHPCodeBrowser/Tests/CLIControllerTest.php @@ -49,7 +49,6 @@ * @since File available since 0.1.0 */ - namespace PHPCodeBrowser\Tests; use Monolog\Logger; diff --git a/src/PHPCodeBrowser/Tests/FileTest.php b/src/PHPCodeBrowser/Tests/FileTest.php index a3a68ae..c7311e4 100644 --- a/src/PHPCodeBrowser/Tests/FileTest.php +++ b/src/PHPCodeBrowser/Tests/FileTest.php @@ -83,7 +83,7 @@ class FileTest extends AbstractTestCase /** * Some issues to work with. * - * @var Issue[] + * @var array */ protected $issues; @@ -152,7 +152,6 @@ public function testAddingIssueToWrongFile(): void $this->file->addIssue($issue); } - /** * Test the basename function * diff --git a/src/PHPCodeBrowser/Tests/Fixtures/Bad.php b/src/PHPCodeBrowser/Tests/Fixtures/Bad.php index 0a664c0..0506c29 100644 --- a/src/PHPCodeBrowser/Tests/Fixtures/Bad.php +++ b/src/PHPCodeBrowser/Tests/Fixtures/Bad.php @@ -4,5 +4,4 @@ class Bad { - } diff --git a/src/PHPCodeBrowser/Tests/Fixtures/Good.php b/src/PHPCodeBrowser/Tests/Fixtures/Good.php index 4874e9e..4ea4985 100644 --- a/src/PHPCodeBrowser/Tests/Fixtures/Good.php +++ b/src/PHPCodeBrowser/Tests/Fixtures/Good.php @@ -4,5 +4,4 @@ class Good { - } diff --git a/src/PHPCodeBrowser/Tests/Helper/IOHelperTest.php b/src/PHPCodeBrowser/Tests/Helper/IOHelperTest.php index 0c84927..b0db51e 100644 --- a/src/PHPCodeBrowser/Tests/Helper/IOHelperTest.php +++ b/src/PHPCodeBrowser/Tests/Helper/IOHelperTest.php @@ -49,7 +49,6 @@ * @since File available since 0.1.0 */ - namespace PHPCodeBrowser\Tests\Helper; use PHPCodeBrowser\Helper\IOHelper; @@ -191,6 +190,7 @@ public function testCopyFile(): void if (file_exists($srcFile)) { unlink($srcFile); } + if (file_exists($dstFile)) { rmdir($dstFile); } @@ -219,13 +219,14 @@ public function testLoadFileWithNonexistentFile(): void $this->expectException(\Exception::class); $sourceFile = self::$testOutputDir.'/doesNotExist'; + if (file_exists($sourceFile)) { unlink(self::$testOutputDir.'/doesNotExist'); } + $this->ioHelper->loadFile($sourceFile); } - /** * Test copyFile function for non-existent source file * diff --git a/src/PHPCodeBrowser/Tests/SourceHandlerTest.php b/src/PHPCodeBrowser/Tests/SourceHandlerTest.php index b7247ca..dcfbbb2 100644 --- a/src/PHPCodeBrowser/Tests/SourceHandlerTest.php +++ b/src/PHPCodeBrowser/Tests/SourceHandlerTest.php @@ -137,12 +137,14 @@ public function __construct() , ]; $issueXML = new IssueXML(); + foreach ($xmlStrings as $xmlString) { $xml = new \DOMDocument('1.0', 'UTF-8'); $xml->validateOnParse = true; $xml->loadXML($xmlString); $issueXML->addXMLFile($xml); } + $this->plugins = [ new ErrorCheckstyle($issueXML), new ErrorPMD($issueXML), diff --git a/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php b/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php index 5a8b950..3828725 100644 --- a/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php +++ b/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php @@ -49,7 +49,6 @@ * @since File available since 0.1.0 */ - namespace PHPCodeBrowser\Tests\View; use PHPCodeBrowser\File; diff --git a/src/PHPCodeBrowser/View/ViewAbstract.php b/src/PHPCodeBrowser/View/ViewAbstract.php index 90f0529..f58c486 100644 --- a/src/PHPCodeBrowser/View/ViewAbstract.php +++ b/src/PHPCodeBrowser/View/ViewAbstract.php @@ -122,6 +122,7 @@ class ViewAbstract public function __construct(string $templateDir, string $outputDir, IOHelper $ioHelper) { $this->templateDir = $templateDir; + if (!$this->templateDir) { throw new Exception( "Specified template directory '{$templateDir}' does not exist" @@ -129,11 +130,13 @@ public function __construct(string $templateDir, string $outputDir, IOHelper $io } $this->outputDir = $outputDir; + if (!$this->outputDir) { throw new Exception( "Specified output directory '{$outputDir}' does not exist" ); } + $this->outputDir .= DIRECTORY_SEPARATOR; $this->ioHelper = $ioHelper; @@ -215,8 +218,8 @@ public static function hasFileAnyIssues(File $file): bool /** * Convert a list of files to a html fragment for jstree. * - * @param File[] $fileList The files, format: array('name' => File). - * @param string $hrefPrefix The prefix to put before all href= tags. + * @param array $fileList The files, format: array('name' => File). + * @param string $hrefPrefix The prefix to put before all href= tags. * * @return string The html fragment. */ @@ -233,6 +236,7 @@ protected function getTreeListHtml(array $fileList, string $hrefPrefix = ''): st $indentStep = 4; $indent = $indentStep; $ret = '
    '.PHP_EOL; + foreach ($fileList as $name => $file) { $dir = \dirname($name).DIRECTORY_SEPARATOR; @@ -263,6 +267,7 @@ protected function getTreeListHtml(array $fileList, string $hrefPrefix = ''): st //TODO: Optimize this. Counts get recalculated for subDirs. $errors = 0; $warnings = 0; + foreach (array_keys($fileList) as $fName) { if (strncmp($fName, $curDir, \strlen($curDir)) !== 0) { continue; @@ -271,13 +276,16 @@ protected function getTreeListHtml(array $fileList, string $hrefPrefix = ''): st $errors += $fileList[$fName]->getErrorCount(); $warnings += $fileList[$fName]->getWarningCount(); } + $count = ''; + if (0 !== $errors || 0 !== $warnings) { $count .= '('; $count .= $errors; $count .= '|'; $count .= $warnings.')'; } + $ret .= str_pad(' ', $indent); $ret .= "
  • {$dirName} {$count}".PHP_EOL; $indent += $indentStep; @@ -290,6 +298,7 @@ protected function getTreeListHtml(array $fileList, string $hrefPrefix = ''): st $shortName = substr($name, $preLen); $fileName = basename($name); $count = ''; + if (0 !== $file->getErrorCount() || 0 !== $file->getWarningCount()) { $count .= '('; $count .= $file->getErrorCount(); diff --git a/src/PHPCodeBrowser/View/ViewReview.php b/src/PHPCodeBrowser/View/ViewReview.php index 8126ce0..d7eacc4 100644 --- a/src/PHPCodeBrowser/View/ViewReview.php +++ b/src/PHPCodeBrowser/View/ViewReview.php @@ -159,6 +159,7 @@ public function generate(array $issueList, string $fileName, string $commonPathP if ($excludeOK && !$data['issues']) { return; } + $this->ioHelper->createFile( $this->outputDir.$shortFilename.'.html', $this->render('review', $data) @@ -179,14 +180,17 @@ public function generate(array $issueList, string $fileName, string $commonPathP protected function highlightPhpCode(string $sourceCode): DOMDocument { $code = highlight_string($sourceCode, true); + if (\extension_loaded('mbstring') && !mb_check_encoding($code, 'UTF-8')) { $detectOrder = mb_detect_order(); $detectOrder[] = 'iso-8859-1'; $encoding = mb_detect_encoding($code, $detectOrder, true); + if (false === $encoding) { error_log('Error detecting file encoding'); } + $code = mb_convert_encoding( $code, 'UTF-8', @@ -216,6 +220,7 @@ protected function highlightPhpCode(string $sourceCode): DOMDocument $span = $targetDom->createElement('span'); $span->nodeValue = htmlspecialchars($sourceElement->wholeText); $liElement->appendChild($span); + continue; } @@ -223,6 +228,7 @@ protected function highlightPhpCode(string $sourceCode): DOMDocument // create new li and new line $liElement = $targetDom->createElement('li'); $targetNode->appendChild($liElement); + continue; } @@ -338,6 +344,7 @@ private function formatSourceCode(string $filename, array $outputIssues): string if (isset($outputIssues[$lineNumber])) { $lineClasses[] = 'hasIssues'; $message = '|'; + foreach ($outputIssues[$lineNumber] as $issue) { $message .= sprintf( ' @@ -351,15 +358,18 @@ private function formatSourceCode(string $filename, array $outputIssues): string $issue->description ); } + $line->setAttribute('title', utf8_encode($message)); } // Add line number $nuSpan = $sourceDom->createElement('span'); $nuSpan->setAttribute('class', 'lineNumber'); + for ($i = 0; $i < $linePlaces - \strlen((string) $lineNumber); ++$i) { $nuSpan->appendChild($sourceDom->createEntityReference('nbsp')); } + $nuSpan->appendChild($sourceDom->createTextNode((string) $lineNumber)); $nuSpan->appendChild($sourceDom->createEntityReference('nbsp')); $line->insertBefore($nuSpan, $line->firstChild); @@ -377,16 +387,21 @@ private function formatSourceCode(string $filename, array $outputIssues): string break; case 1: $lineClasses[] = $outputIssues[$lineNumber][0]->foundBy; + break; case 1 < $tmp: $lineClasses[] = 'moreErrors'; + break; + // This can't happen, count always returns >= 0 // @codeCoverageIgnoreStart default: break; + // @codeCoverageIgnoreEnd } + $line->setAttribute('class', implode(' ', $lineClasses)); } @@ -404,6 +419,7 @@ private function formatSourceCode(string $filename, array $outputIssues): string private function formatIssues(array $issueList): array { $outputIssues = []; + foreach ($issueList as $issue) { for ($i = $issue->lineStart; $i <= $issue->lineEnd; ++$i) { $outputIssues[$i][] = $issue; @@ -431,8 +447,10 @@ private function stripInvalidXml(string $value): string } $length = \strlen($value); + for ($i = 0; $i < $length; ++$i) { $current = \ord($value{$i}); + if ((0x9 === $current) || (0xA === $current) || (0xD === $current) From 91472f5a246b31247013c3699f1ea39cb828fc34 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Fri, 29 Nov 2019 02:29:32 +0100 Subject: [PATCH 04/34] update some dependencies --- .travis.yml | 8 ++++---- composer.json | 6 +++--- src/PHPCodeBrowser/Tests/View/ViewReviewTest.php | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7143c74..85f201c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,14 @@ language: php matrix: include: - - php: 7.1 - env: DEPENDENCIES=lowest - - php: 7.1 - env: DEPENDENCIES=highest - php: 7.2 env: DEPENDENCIES=lowest - php: 7.2 env: DEPENDENCIES=highest + - php: 7.3 + env: DEPENDENCIES=lowest + - php: 7.3 + env: DEPENDENCIES=highest before_script: - phpenv config-rm xdebug.ini diff --git a/composer.json b/composer.json index 2200788..aeb34c3 100644 --- a/composer.json +++ b/composer.json @@ -16,11 +16,11 @@ } ], "require": { - "php": "^7.1", + "php": "^7.2", "ext-dom": "*", "monolog/monolog": "~1.7|~2.0", "phpunit/php-file-iterator": "~2.0", - "symfony/console": "~2.1|~3.0|~4.0|~5.0" + "symfony/console": "~3.4|~4.0|~5.0" }, "require-dev": { "kherge/box": "~2.7", @@ -28,7 +28,7 @@ "phploc/phploc": "*", "phpmd/phpmd": "1.5.*|~2.6", "phpstan/phpstan": "^0.12.5", - "phpunit/phpunit": "~7.3", + "phpunit/phpunit": "~8.4", "sebastian/phpcpd": "*" }, "autoload": { diff --git a/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php b/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php index 3828725..8ea0bd6 100644 --- a/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php +++ b/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php @@ -56,6 +56,7 @@ use PHPCodeBrowser\Issue; use PHPCodeBrowser\Tests\AbstractTestCase; use PHPCodeBrowser\View\ViewReview; +use PHPUnit\Framework\MockObject\MockObject; /** * ViewReviewTest @@ -86,7 +87,7 @@ class ViewReviewTest extends AbstractTestCase /** * IOHelper mock to simulate filesystem interaction. * - * @var \PHPUnit_Framework_MockObject_MockObject + * @var MockObject */ protected $ioMock; From cbd182b2b920a48554f8b9b48a0e446819696ace Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Fri, 29 Nov 2019 02:38:46 +0100 Subject: [PATCH 05/34] microoptimizations --- src/PHPCodeBrowser/Command/RunCommand.php | 2 +- src/PHPCodeBrowser/Tests/View/ViewReviewTest.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/PHPCodeBrowser/Command/RunCommand.php b/src/PHPCodeBrowser/Command/RunCommand.php index 30240ed..608962e 100644 --- a/src/PHPCodeBrowser/Command/RunCommand.php +++ b/src/PHPCodeBrowser/Command/RunCommand.php @@ -80,7 +80,7 @@ class RunCommand extends Command protected function configure(): void { $plugins = array_map( - function ($class) { + static function ($class) { return '"'.substr($class, \strlen('Error')).'"'; }, $this->getAvailablePlugins() diff --git a/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php b/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php index 8ea0bd6..d7f858c 100644 --- a/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php +++ b/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php @@ -120,7 +120,7 @@ public function testGenerateNoIssues(): void $this->ioMock->expects($this->once()) ->method('loadFile') ->with($this->equalTo(__FILE__)) - ->will($this->returnValue(file_get_contents(__FILE__))); + ->willReturn(file_get_contents(__FILE__)); $this->ioMock->expects($this->once()) ->method('createFile') ->with($this->equalTo($expectedFile)); @@ -154,7 +154,7 @@ public function testGenerate(): void $this->ioMock->expects($this->once()) ->method('loadFile') ->with($this->equalTo(__FILE__)) - ->will($this->returnValue(file_get_contents(__FILE__))); + ->willReturn(file_get_contents(__FILE__)); $this->ioMock->expects($this->once()) ->method('createFile') ->with($this->equalTo($expectedFile)); @@ -182,7 +182,7 @@ public function testGenerateMultiple(): void $this->ioMock->expects($this->once()) ->method('loadFile') ->with($this->equalTo(__FILE__)) - ->will($this->returnValue(file_get_contents(__FILE__))); + ->willReturn(file_get_contents(__FILE__)); $this->ioMock->expects($this->once()) ->method('createFile') ->with($this->equalTo($expectedFile)); @@ -222,7 +222,7 @@ public function testGenerateWithTextHighlighter(): void $this->ioMock->expects($this->once()) ->method('loadFile') ->with($this->equalTo($fileName)) - ->will($this->returnValue($html)); + ->willReturn($html); $this->ioMock->expects($this->once()) ->method('createFile') ->with($this->equalTo($expectedFile)); From 9c0fcfb9b86c72a5fd735500348f48af2ee2bf03 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Sun, 19 Jan 2020 21:17:58 +0100 Subject: [PATCH 06/34] switch to humbug/box --- box.json | 43 ------------------------------------------- composer.json | 2 +- 2 files changed, 1 insertion(+), 44 deletions(-) delete mode 100644 box.json diff --git a/box.json b/box.json deleted file mode 100644 index c720920..0000000 --- a/box.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "alias": "phpcb.phar", - "chmod": "0755", - "compactors": [ - "Herrera\\Box\\Compactor\\Json", - "Herrera\\Box\\Compactor\\Php" - ], - "directories": ["src", "templates"], - "extract": true, - "files": [ - "LICENSE", - "vendor/autoload.php" - ], - "finder": [ - { - "name": "*.php", - "path": [ - "composer", - "herrera-io/json", - "herrera-io/phar-update", - "monolog/monolog", - "myclabs/deep-copy", - "phpseclib/phpseclib", - "phpunit/php-file-iterator", - "psr/log", - "symfony/console", - "symfony/polyfill-mbstring", - "symfony/polyfill-ctype" - ], - "notPath": [ - "Tests", - "test", - "tests" - ], - "in": "vendor" - } - ], - "git-commit": "git-commit", - "git-version": "git-version", - "main": "bin/phpcb", - "output": "phpcb-@git-version@.phar", - "stub": true -} diff --git a/composer.json b/composer.json index aeb34c3..9b36000 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "symfony/console": "~3.4|~4.0|~5.0" }, "require-dev": { - "kherge/box": "~2.7", + "humbug/box": "^3.8.3", "mayflower/mo4-coding-standard": "^5.0", "phploc/phploc": "*", "phpmd/phpmd": "1.5.*|~2.6", From 4a98e46c25578bed4196e9b7b61b5d3bce244990 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Sun, 19 Jan 2020 21:19:25 +0100 Subject: [PATCH 07/34] test on PHP 7.4 --- .travis.yml | 5 +++++ src/PHPCodeBrowser/View/ViewReview.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 85f201c..9ab492a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,11 @@ matrix: env: DEPENDENCIES=lowest - php: 7.3 env: DEPENDENCIES=highest + - php: 7.4 + env: DEPENDENCIES=lowest + - php: 7.4 + env: DEPENDENCIES=highest + before_script: - phpenv config-rm xdebug.ini diff --git a/src/PHPCodeBrowser/View/ViewReview.php b/src/PHPCodeBrowser/View/ViewReview.php index d7eacc4..790e5bc 100644 --- a/src/PHPCodeBrowser/View/ViewReview.php +++ b/src/PHPCodeBrowser/View/ViewReview.php @@ -449,7 +449,7 @@ private function stripInvalidXml(string $value): string $length = \strlen($value); for ($i = 0; $i < $length; ++$i) { - $current = \ord($value{$i}); + $current = \ord($value[$i]); if ((0x9 === $current) || (0xA === $current) From ef2e22ffe88929cbdbe0722bdb79162754b528a2 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Sun, 19 Jan 2020 21:31:30 +0100 Subject: [PATCH 08/34] Don't test lowest deps for now --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9ab492a..a2672c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,16 @@ language: php matrix: include: - - php: 7.2 - env: DEPENDENCIES=lowest +# - php: 7.2 +# env: DEPENDENCIES=lowest - php: 7.2 env: DEPENDENCIES=highest - - php: 7.3 - env: DEPENDENCIES=lowest +# - php: 7.3 +# env: DEPENDENCIES=lowest - php: 7.3 env: DEPENDENCIES=highest - - php: 7.4 - env: DEPENDENCIES=lowest +# - php: 7.4 +# env: DEPENDENCIES=lowest - php: 7.4 env: DEPENDENCIES=highest From 79342b7b7ba8e1ff194cb511ed080362aa1bd7fb Mon Sep 17 00:00:00 2001 From: Christian Albrecht Date: Fri, 24 Jan 2020 13:22:21 +0100 Subject: [PATCH 09/34] Fix phar build #69 (#71) * Fix phar build #69 templates folder was missing in the resulting pharchive. cleaned the finder paths to the necessary minimum. * Set version to 2.3.1 --- box.json | 33 +++++++++++++++++++++++++++++++++ composer.json | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 box.json diff --git a/box.json b/box.json new file mode 100644 index 0000000..35b7be1 --- /dev/null +++ b/box.json @@ -0,0 +1,33 @@ +{ + "alias": "phpcb.phar", + "compactors": [ + "KevinGH\\Box\\Compactor\\Json", + "KevinGH\\Box\\Compactor\\Php" + ], + "directories": ["src", "templates"], + "files": [ + "LICENSE", + "vendor/autoload.php" + ], + "finder": [ + { + "name": "*.php", + "path": [ + "monolog/monolog", + "phpunit/php-file-iterator", + "psr/log", + "symfony/console", + "symfony/service-contracts" + ], + "notPath": [ + "Tests", + "test", + "tests" + ], + "in": "vendor" + } + ], + "git-commit": "git-commit", + "git-version": "git-version", + "output": "phpcb-2.3.1.phar" +} diff --git a/composer.json b/composer.json index 9b36000..69b10ce 100644 --- a/composer.json +++ b/composer.json @@ -57,6 +57,6 @@ ], "clean": "rm -rf build/logs/* build/code-browser", "browser": "bin/phpcb -l build/logs -o build/code-browser -s src", - "phar": "php -d phar.readonly=0 vendor/bin/box build" + "phar": "php vendor/bin/box compile" } } From 17f8bce3b45ff12b1286aa687bdcbe2602a60904 Mon Sep 17 00:00:00 2001 From: Christian Albrecht Date: Sat, 23 Jan 2021 19:41:13 +0100 Subject: [PATCH 10/34] Composer update #72 & fix semver OR condition (#73) * Composer update #72 & fix semver OR condition phpunit ^9.0 php-file-iterator ^3.0 in composer OR condition is represented through double pipes (||). https://getcomposer.org/doc/articles/versions.md#version-range * Remove travis check * Enable github actions for ci check on php 7.3 and 7.4 --- .github/flake.lock | 24 ++++ .github/flake.nix | 43 +++++++ .github/workflows/ci.yml | 37 ++++++ .travis.yml | 26 ----- box.json | 2 +- composer.json | 21 ++-- phpstan_baseline.neon | 15 --- src/PHPCodeBrowser/AbstractPlugin.php | 52 +++++---- src/PHPCodeBrowser/Application.php | 13 ++- src/PHPCodeBrowser/CLIController.php | 55 ++++----- src/PHPCodeBrowser/Command/RunCommand.php | 51 ++++---- src/PHPCodeBrowser/File.php | 47 ++++---- src/PHPCodeBrowser/Helper/IOHelper.php | 73 ++++++------ src/PHPCodeBrowser/Issue.php | 29 ++--- src/PHPCodeBrowser/IssueXML.php | 47 ++++---- src/PHPCodeBrowser/Plugins/ErrorCPD.php | 41 +++---- src/PHPCodeBrowser/Plugins/ErrorCRAP.php | 35 +++--- .../Plugins/ErrorCheckstyle.php | 41 ++++--- src/PHPCodeBrowser/Plugins/ErrorCoverage.php | 39 ++++--- src/PHPCodeBrowser/Plugins/ErrorPMD.php | 41 ++++--- src/PHPCodeBrowser/Plugins/ErrorPadawan.php | 40 ++++--- src/PHPCodeBrowser/SourceHandler.php | 55 ++++----- src/PHPCodeBrowser/Tests/AbstractTestCase.php | 49 ++++---- .../Tests/CLIControllerTest.php | 39 ++++--- src/PHPCodeBrowser/Tests/FileTest.php | 36 +++--- .../Tests/Helper/IOHelperTest.php | 92 ++++++++------- src/PHPCodeBrowser/Tests/IssueTest.php | 31 ++--- .../Tests/Plugins/ErrorCPDTest.php | 32 ++--- .../Tests/Plugins/ErrorCRAPTest.php | 34 +++--- .../Tests/Plugins/ErrorCheckstyleTest.php | 32 ++--- .../Tests/Plugins/ErrorCoverageTest.php | 32 ++--- .../Tests/Plugins/ErrorPMDTest.php | 32 ++--- .../Tests/SourceHandlerTest.php | 34 +++--- .../Tests/View/ViewReviewTest.php | 110 +++++++++--------- src/PHPCodeBrowser/View/ViewAbstract.php | 81 ++++++------- src/PHPCodeBrowser/View/ViewReview.php | 89 +++++++------- 36 files changed, 840 insertions(+), 710 deletions(-) create mode 100644 .github/flake.lock create mode 100644 .github/flake.nix create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/flake.lock b/.github/flake.lock new file mode 100644 index 0000000..e112b3c --- /dev/null +++ b/.github/flake.lock @@ -0,0 +1,24 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1611219034, + "narHash": "sha256-bgp8G3LcpvKs22/z5Cj4XQkmZq05Aa0vaP1bKl7X0zM=", + "path": "/nix/store/pl5nzbz7s187b7x2scj27b4wpkm1g93h-source", + "rev": "f217c0ea7c148ddc0103347051555c7c252dcafb", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/.github/flake.nix b/.github/flake.nix new file mode 100644 index 0000000..682e70c --- /dev/null +++ b/.github/flake.nix @@ -0,0 +1,43 @@ +{ + description = "A php test environment flake"; + + outputs = { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages."${system}"; + + phpEnv = phpPackage: (phpPackage.buildEnv { + extensions = { enabled, all }: (enabled ++ [ all.xdebug ]); + extraConfig = '' + memory_limit=-1 + xdebug.mode=coverage + '' + + pkgs.lib.optionalString (pkgs.lib.versionOlder phpPackage.version "8.0") '' + xdebug.coverage_enable=1 + ''; + }); + + phpVersions = [ + "php73" + "php74" + "php80" + ]; + in + { + packages."${system}" = builtins.listToAttrs + (builtins.map + (name: + { + name = "env-${name}"; + value = pkgs.symlinkJoin { + name = "env-${name}"; + paths = [ + (phpEnv pkgs."${name}") + (phpEnv pkgs."${name}").packages.composer2 + ]; + }; + } + ) + phpVersions); + }; +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c66bdfc --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: Simple Nix Flakes powered php ci. + +on: [push, pull_request] + +jobs: + ci: + + runs-on: ubuntu-latest + + strategy: + matrix: + php: [php73, php74] + + steps: + - uses: actions/checkout@v2 + with: + # Nix Flakes doesn't work on shallow clones + fetch-depth: 0 + + - uses: cachix/install-nix-action@v12 + with: + install_url: https://github.com/numtide/nix-flakes-installer/releases/download/nix-2.4pre20201221_9fab14a/install + extra_nix_config: | + experimental-features = nix-command flakes + + - name: Cache Composer dependencies + uses: actions/cache@v2 + with: + path: /home/runner/.cache/composer + key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - run: | + rm -fr vendor + nix shell .github#env-${{ matrix.php }} --command composer ci-prepare + nix shell .github#env-${{ matrix.php }} --command composer ci diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a2672c2..0000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -language: php -matrix: - include: -# - php: 7.2 -# env: DEPENDENCIES=lowest - - php: 7.2 - env: DEPENDENCIES=highest -# - php: 7.3 -# env: DEPENDENCIES=lowest - - php: 7.3 - env: DEPENDENCIES=highest -# - php: 7.4 -# env: DEPENDENCIES=lowest - - php: 7.4 - env: DEPENDENCIES=highest - - -before_script: - - phpenv config-rm xdebug.ini - - if [ "${DEPENDENCIES}" = "lowest" ]; then composer update --prefer-lowest --prefer-dist --no-interaction --no-progress; fi; - - if [ "${DEPENDENCIES}" = "highest" ]; then composer update --prefer-dist --no-interaction --no-progress; fi; - -script: - - vendor/bin/phpcs -s --standard=MO4 --exclude=SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions src/PHPCodeBrowser/ - - vendor/bin/phpstan analyse --no-progress - - vendor/bin/phpunit diff --git a/box.json b/box.json index 35b7be1..a138a0d 100644 --- a/box.json +++ b/box.json @@ -29,5 +29,5 @@ ], "git-commit": "git-commit", "git-version": "git-version", - "output": "phpcb-2.3.1.phar" + "output": "phpcb-2.3.2.phar" } diff --git a/composer.json b/composer.json index 69b10ce..eee6994 100644 --- a/composer.json +++ b/composer.json @@ -16,19 +16,19 @@ } ], "require": { - "php": "^7.2", + "php": "^7.3", "ext-dom": "*", - "monolog/monolog": "~1.7|~2.0", - "phpunit/php-file-iterator": "~2.0", - "symfony/console": "~3.4|~4.0|~5.0" + "monolog/monolog": "~1.7||~2.0", + "phpunit/php-file-iterator": "~2.0||^3.0", + "symfony/console": "~3.4||~4.0||~5.0" }, "require-dev": { "humbug/box": "^3.8.3", - "mayflower/mo4-coding-standard": "^5.0", + "mayflower/mo4-coding-standard": "^6.0", "phploc/phploc": "*", - "phpmd/phpmd": "1.5.*|~2.6", + "phpmd/phpmd": "1.5.*||~2.6", "phpstan/phpstan": "^0.12.5", - "phpunit/phpunit": "~8.4", + "phpunit/phpunit": "~8.4||^9.0", "sebastian/phpcpd": "*" }, "autoload": { @@ -50,9 +50,12 @@ "phploc -q --log-xml=build/logs/phploc.xml src || true", "@browser" ], - "travis": [ + "ci-prepare": [ + "composer update --prefer-dist --no-interaction --no-progress" + ], + "ci": [ "phpcs -s --standard=MO4 src/PHPCodeBrowser/", - "phpstan analyse --no-progress --level=1 src/PHPCodeBrowser/", + "phpstan analyse --no-progress", "phpunit" ], "clean": "rm -rf build/logs/* build/code-browser", diff --git a/phpstan_baseline.neon b/phpstan_baseline.neon index ccf5eef..401dfb0 100644 --- a/phpstan_baseline.neon +++ b/phpstan_baseline.neon @@ -3,25 +3,10 @@ parameters: - message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#" count: 1 - path: src/PHPCodeBrowser/AbstractPlugin.php - - - - message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#" - count: 5 path: src/PHPCodeBrowser/Plugins/ErrorCPD.php - message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#" count: 1 - path: src/PHPCodeBrowser/Plugins/ErrorCRAP.php - - - - message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#" - count: 2 path: src/PHPCodeBrowser/Plugins/ErrorCoverage.php - - - message: "#^Access to an undefined property DOMNode\\:\\:\\$wholeText\\.$#" - count: 1 - path: src/PHPCodeBrowser/View/ViewReview.php - diff --git a/src/PHPCodeBrowser/AbstractPlugin.php b/src/PHPCodeBrowser/AbstractPlugin.php index a8d64f0..cee48da 100644 --- a/src/PHPCodeBrowser/AbstractPlugin.php +++ b/src/PHPCodeBrowser/AbstractPlugin.php @@ -1,4 +1,5 @@ - * @author Michel Hartmann + * @author Elger Thiele + * @author Michel Hartmann * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 0.1.0 + * @since File available since 0.1.0 */ namespace PHPCodeBrowser; -use \DOMElement; -use \DOMNode; -use \DOMNodeList; +use DOMElement; +use DOMNode; +use DOMNodeList; /** * AbstractPlugin * - * @category PHP_CodeBrowser + * @category PHP_CodeBrowser * - * @author Elger Thiele - * @author Michel Hartmann + * @author Elger Thiele + * @author Michel Hartmann * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ abstract class AbstractPlugin { @@ -179,7 +180,7 @@ public function getIssuesByFile(string $filename): array $issues = []; foreach ($this->getIssueNodes($filename) as $issueNode) { - $issues = array_merge( + $issues = \array_merge( $issues, $this->mapIssues($issueNode, $filename) ); @@ -197,14 +198,14 @@ public function getFilesWithIssues(): array { $fileNames = []; $issueNodes = $this->issueXml->query( - sprintf('/*/%s/file[@name]', $this->pluginName) + \sprintf('/*/%s/file[@name]', $this->pluginName) ); foreach ($issueNodes as $node) { $fileNames[] = $node->getAttribute('name'); } - return array_unique($fileNames); + return \array_unique($fileNames); } /** @@ -250,12 +251,13 @@ public function mapIssues(DOMNode $element, string $filename): array protected function getIssueNodes(string $filename): DOMNodeList { return $this->issueXml->query( - sprintf('/*/%s/file[@name="%s"]', $this->pluginName, $filename) + \sprintf('/*/%s/file[@name="%s"]', $this->pluginName, $filename) ); } /** * Default method for retrieving the first line of an issue. + * * @see self::mapIssues * * @param DOMElement $element @@ -269,6 +271,7 @@ protected function getLineStart(DOMElement $element): int /** * Default method for retrieving the last line of an issue. + * * @see self::mapIssues * * @param DOMElement $element @@ -282,6 +285,7 @@ protected function getLineEnd(DOMElement $element): int /** * Default method for retrieving the source of an issue. + * * @see self::mapIssues * * @return string @@ -293,6 +297,7 @@ protected function getSource(): string /** * Default method for retrieving the description of an issue. + * * @see self::mapIssues * * @param DOMElement $element @@ -301,11 +306,12 @@ protected function getSource(): string */ protected function getDescription(DOMElement $element): string { - return htmlentities($element->getAttribute($this->descriptionAttr)); + return \htmlentities($element->getAttribute($this->descriptionAttr)); } /** * Default method for retrieving the severity of an issue. + * * @see self::mapIssues * * @param DOMElement $element @@ -314,6 +320,6 @@ protected function getDescription(DOMElement $element): string */ protected function getSeverity(DOMElement $element): string { - return htmlentities($element->getAttribute($this->severityAttr)); + return \htmlentities($element->getAttribute($this->severityAttr)); } } diff --git a/src/PHPCodeBrowser/Application.php b/src/PHPCodeBrowser/Application.php index 66555d0..7463b97 100644 --- a/src/PHPCodeBrowser/Application.php +++ b/src/PHPCodeBrowser/Application.php @@ -1,4 +1,5 @@ + * @author Robin Gloster * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 1.1 + * @since File available since 1.1 */ namespace PHPCodeBrowser; diff --git a/src/PHPCodeBrowser/CLIController.php b/src/PHPCodeBrowser/CLIController.php index 88976fb..a8c1ad4 100644 --- a/src/PHPCodeBrowser/CLIController.php +++ b/src/PHPCodeBrowser/CLIController.php @@ -1,4 +1,5 @@ - * @author Simon Kohlmeyer + * @author Elger Thiele + * @author Simon Kohlmeyer * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 0.1.0 + * @since File available since 0.1.0 */ namespace PHPCodeBrowser; @@ -59,32 +60,24 @@ use PHPCodeBrowser\View\ViewReview; use SebastianBergmann\FileIterator\Factory as FileIteratorFactory; -if (!defined('PHPCB_ROOT_DIR')) { - define('PHPCB_ROOT_DIR', \dirname(__FILE__, 2).'/'); -} - -if (!defined('PHPCB_TEMPLATE_DIR')) { - define('PHPCB_TEMPLATE_DIR', \dirname(__FILE__, 3).'/templates'); -} - /** * CLIController * - * @category PHP_CodeBrowser + * @category PHP_CodeBrowser * - * @author Elger Thiele - * @author Michel Hartmann - * @author Simon Kohlmeyer + * @author Elger Thiele + * @author Michel Hartmann + * @author Simon Kohlmeyer * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class CLIController { @@ -236,9 +229,9 @@ public function addErrorPlugins($classNames): void public function run(): void { // clear and create output directory - if (is_dir($this->htmlOutputDir)) { + if (\is_dir($this->htmlOutputDir)) { $this->ioHelper->deleteDirectory($this->htmlOutputDir); - } elseif (is_file($this->htmlOutputDir)) { + } elseif (\is_file($this->htmlOutputDir)) { $this->ioHelper->deleteFile($this->htmlOutputDir); } @@ -246,7 +239,7 @@ public function run(): void // init needed classes $viewReview = new ViewReview( - PHPCB_TEMPLATE_DIR, + \getenv('PHPCB_TEMPLATE_DIR') ?: \dirname(__FILE__, 3).'/templates', $this->htmlOutputDir, $this->ioHelper, $this->phpSuffixes @@ -262,7 +255,7 @@ public function run(): void // conversion of XML file cc to cb format foreach ($this->registeredPlugins as $className) { - $plugin = array_key_exists($className, $this->pluginOptions) ? new $className( + $plugin = \array_key_exists($className, $this->pluginOptions) ? new $className( $issueXml, $this->pluginOptions[$className] ) : new $className($issueXml); @@ -272,10 +265,10 @@ public function run(): void if (null !== $this->projectSource) { foreach ($this->projectSource as $source) { - if (is_dir($source)) { + if (\is_dir($source)) { $factory = new FileIteratorFactory(); - $suffixes = array_merge( + $suffixes = \array_merge( $this->phpSuffixes, ['php', 'js', 'css', 'html'] ); @@ -292,11 +285,11 @@ public function run(): void } } - array_walk( + \array_walk( $this->excludeExpressions, [$sourceHandler, 'excludeMatchingPCRE'] ); - array_walk( + \array_walk( $this->excludePatterns, [$sourceHandler, 'excludeMatchingPattern'] ); diff --git a/src/PHPCodeBrowser/Command/RunCommand.php b/src/PHPCodeBrowser/Command/RunCommand.php index 608962e..e81ffc7 100644 --- a/src/PHPCodeBrowser/Command/RunCommand.php +++ b/src/PHPCodeBrowser/Command/RunCommand.php @@ -1,4 +1,5 @@ + * @author Robin Gloster * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 1.1 + * @since File available since 1.1 */ namespace PHPCodeBrowser\Command; @@ -79,9 +80,9 @@ class RunCommand extends Command */ protected function configure(): void { - $plugins = array_map( + $plugins = \array_map( static function ($class) { - return '"'.substr($class, \strlen('Error')).'"'; + return '"'.\substr($class, \strlen('Error')).'"'; }, $this->getAvailablePlugins() ); @@ -139,7 +140,7 @@ static function ($class) { 'disablePlugin', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, - 'Disable single Plugins. Can be one of '.implode(', ', $plugins) + 'Disable single Plugins. Can be one of '.\implode(', ', $plugins) )->addOption( 'crapThreshold', null, @@ -182,7 +183,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int ['CRAP' => ['threshold' => $input->getOption('crapThreshold')]], new IOHelper(), $logger, - array_merge($extensions, ['php']), + \array_merge($extensions, ['php']), (bool) $input->getOption('excludeOK') ); @@ -193,7 +194,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int try { $controller->run(); } catch (Exception $e) { - error_log( + \error_log( <<getMessage()} @@ -216,15 +217,15 @@ protected function checkErrors(InputInterface $input): void if (!$input->getOption('source')) { throw new \InvalidArgumentException('Missing log or source argument.'); } - } elseif (!file_exists((string) $input->getOption('log'))) { + } elseif (!\file_exists((string) $input->getOption('log'))) { throw new \InvalidArgumentException('Log directory does not exist.'); - } elseif (!is_dir((string) $input->getOption('log'))) { + } elseif (!\is_dir((string) $input->getOption('log'))) { throw new \InvalidArgumentException('Log argument must be a directory, a file was given.'); } if ($input->getOption('source')) { foreach ($input->getOption('source') as $s) { - if (!file_exists($s)) { + if (!\file_exists($s)) { throw new \InvalidArgumentException("Source '{$s}' does not exist"); } } @@ -234,7 +235,7 @@ protected function checkErrors(InputInterface $input): void throw new \InvalidArgumentException('Missing output argument.'); } - if (file_exists((string) $input->getOption('output')) && !is_dir((string) $input->getOption('output'))) { + if (\file_exists((string) $input->getOption('output')) && !\is_dir((string) $input->getOption('output'))) { throw new \InvalidArgumentException('Output argument must be a directory, a file was given.'); } } @@ -266,15 +267,15 @@ protected function getAvailablePlugins(): array */ protected function disablePlugins(array $disabledPlugins, array $plugins): array { - $disabledPlugins = array_map( + $disabledPlugins = \array_map( 'strtolower', $disabledPlugins ); foreach ($plugins as $pluginKey => $plugin) { - $name = substr($plugin, \strlen('Error')); + $name = \substr($plugin, \strlen('Error')); - if (!\in_array(strtolower($name), $disabledPlugins)) { + if (!\in_array(\strtolower($name), $disabledPlugins)) { continue; } @@ -295,15 +296,15 @@ protected function disablePlugins(array $disabledPlugins, array $plugins): array */ protected function convertIgnores(array $ignored, array $excludePCRE): array { - $dirSep = preg_quote(DIRECTORY_SEPARATOR, '/'); + $dirSep = \preg_quote(DIRECTORY_SEPARATOR, '/'); foreach ($ignored as $ignore) { - $ig = realpath($ignore); + $ig = \realpath($ignore); if (!$ig) { - error_log("[Warning] {$ignore} does not exists"); + \error_log("[Warning] {$ignore} does not exists"); } else { - $ig = preg_quote($ig, '/'); + $ig = \preg_quote($ig, '/'); $excludePCRE[] = "/^{$ig}({$dirSep}|$)/"; } } @@ -320,9 +321,9 @@ protected function convertIgnores(array $ignored, array $excludePCRE): array */ private function handleBackwardCompatibility(array $option): array { - if (\count($option) === 1 && strpos($option[0], ',') !== false) { - $option = explode(',', $option[0]); - error_log('Usage of comma-separated options is deprecated, specify them one-by-one.', E_DEPRECATED); + if (\count($option) === 1 && \strpos($option[0], ',') !== false) { + $option = \explode(',', $option[0]); + \error_log('Usage of comma-separated options is deprecated, specify them one-by-one.', E_DEPRECATED); } return $option; diff --git a/src/PHPCodeBrowser/File.php b/src/PHPCodeBrowser/File.php index d563c69..a75ee8a 100644 --- a/src/PHPCodeBrowser/File.php +++ b/src/PHPCodeBrowser/File.php @@ -1,4 +1,5 @@ + * @author Simon Kohlmeyer * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 0.2.0 + * @since File available since 0.2.0 */ namespace PHPCodeBrowser; @@ -61,19 +62,19 @@ * An object of this class represents a single source file * with it's issues, if any. * - * @category PHP_CodeBrowser + * @category PHP_CodeBrowser * - * @author Simon Kohlmeyer + * @author Simon Kohlmeyer * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://github.com/mayflowergmbh + * @link http://github.com/mayflowergmbh * - * @since Class available since 0.2.0 + * @since Class available since 0.2.0 */ class File { @@ -100,7 +101,7 @@ class File public function __construct(string $name, array $issues = []) { if (DIRECTORY_SEPARATOR !== '/') { - $name = str_replace('/', DIRECTORY_SEPARATOR, $name); + $name = \str_replace('/', DIRECTORY_SEPARATOR, $name); } $this->name = $name; @@ -152,7 +153,7 @@ public function name(): string */ public function basename(): string { - return basename($this->name); + return \basename($this->name); } /** @@ -185,7 +186,7 @@ public function getErrorCount(): int $count = 0; foreach ($this->issues as $issue) { - if (strcasecmp($issue->severity, 'error') !== 0) { + if (\strcasecmp($issue->severity, 'error') !== 0) { continue; } @@ -220,7 +221,7 @@ public function mergeWith(File $file): void ); } - $this->issues = array_merge($this->issues, $file->issues); + $this->issues = \array_merge($this->issues, $file->issues); } /** @@ -230,7 +231,7 @@ public function mergeWith(File $file): void */ public static function sort(array &$files): void { - uasort($files, 'PHPCodeBrowser\File::internalSort'); + \uasort($files, 'PHPCodeBrowser\File::internalSort'); } /** @@ -249,16 +250,16 @@ protected static function internalSort(File $first, File $second): int $prefix = IOHelper::getCommonPathPrefix([$firstName, $secondName]); $prefixLength = \strlen($prefix); - $firstSubName = substr($firstName, $prefixLength); - $secondSubName = substr($secondName, $prefixLength); + $firstSubName = \substr($firstName, $prefixLength); + $secondSubName = \substr($secondName, $prefixLength); - $firstIsInSubDir = (substr_count($firstSubName, DIRECTORY_SEPARATOR) !== 0); - $secondIsInSubDir = (substr_count($secondSubName, DIRECTORY_SEPARATOR) !== 0); + $firstIsInSubDir = (\substr_count($firstSubName, DIRECTORY_SEPARATOR) !== 0); + $secondIsInSubDir = (\substr_count($secondSubName, DIRECTORY_SEPARATOR) !== 0); if ($firstIsInSubDir) { - return $secondIsInSubDir ? strcmp($firstSubName, $secondSubName) : -1; + return $secondIsInSubDir ? \strcmp($firstSubName, $secondSubName) : -1; } - return $secondIsInSubDir ? 1 : strcmp($firstSubName, $secondSubName); + return $secondIsInSubDir ? 1 : \strcmp($firstSubName, $secondSubName); } } diff --git a/src/PHPCodeBrowser/Helper/IOHelper.php b/src/PHPCodeBrowser/Helper/IOHelper.php index a6c5f1a..108c09c 100644 --- a/src/PHPCodeBrowser/Helper/IOHelper.php +++ b/src/PHPCodeBrowser/Helper/IOHelper.php @@ -1,4 +1,5 @@ + * @author Elger Thiele * * @copyright 2007-2009 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 0.1.0 + * @since File available since 0.1.0 */ namespace PHPCodeBrowser\Helper; @@ -61,20 +62,20 @@ * Input output helper class provides several methods for writing and * reading files or directories. * - * @category PHP_CodeBrowser + * @category PHP_CodeBrowser * - * @author Elger Thiele - * @author Christopher Weckerle + * @author Elger Thiele + * @author Christopher Weckerle * * @copyright 2007-2009 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class IOHelper { @@ -89,14 +90,14 @@ class IOHelper */ public function createFile(string $fileName, string $fileContent): void { - $realName = basename($fileName); - $path = substr($fileName, 0, - 1 * (\strlen($realName))); + $realName = \basename($fileName); + $path = \substr($fileName, 0, - 1 * (\strlen($realName))); if (!empty($path)) { $this->createDirectory($path); } - file_put_contents(realpath($path).'/'.$realName, $fileContent); + \file_put_contents(\realpath($path).'/'.$realName, $fileContent); } /** @@ -110,11 +111,11 @@ public function createFile(string $fileName, string $fileContent): void */ public function deleteFile(string $fileName): void { - if (!file_exists($fileName)) { + if (!\file_exists($fileName)) { return; } - unlink($fileName); + \unlink($fileName); } /** @@ -130,11 +131,11 @@ public function deleteFile(string $fileName): void */ public function copyFile(string $fileSource, string $sourceFolder): void { - if (!file_exists($fileSource)) { - throw new \Exception(sprintf('File %s does not exist!', $fileSource)); + if (!\file_exists($fileSource)) { + throw new \Exception(\sprintf('File %s does not exist!', $fileSource)); } - $fileName = basename($fileSource); + $fileName = \basename($fileSource); $this->createFile( $sourceFolder.'/'.$fileName, $this->loadFile($fileSource) @@ -152,11 +153,11 @@ public function copyFile(string $fileSource, string $sourceFolder): void */ public function loadFile(string $fileName): string { - if (!file_exists($fileName)) { - throw new \Exception(sprintf('File %s does not exist!', $fileName)); + if (!\file_exists($fileName)) { + throw new \Exception(\sprintf('File %s does not exist!', $fileName)); } - return trim(file_get_contents($fileName)); + return \trim(\file_get_contents($fileName)); } /** @@ -169,14 +170,14 @@ public function loadFile(string $fileName): string */ public function createDirectory(string $target): void { - $target = rtrim($target, DIRECTORY_SEPARATOR); + $target = \rtrim($target, DIRECTORY_SEPARATOR); - if (is_dir($target)) { + if (\is_dir($target)) { return; } - if (!mkdir($target, 0777, true) && !is_dir($target)) { - throw new \RuntimeException(sprintf('Directory "%s" was not created', $target)); + if (!\mkdir($target, 0777, true) && !\is_dir($target)) { + throw new \RuntimeException(\sprintf('Directory "%s" was not created', $target)); } } @@ -195,7 +196,7 @@ public function deleteDirectory(string $source): void $iterator = new DirectoryIterator($source); while ($iterator->valid()) { - $src = realpath($source.'/'.$iterator->current()); + $src = \realpath($source.'/'.$iterator->current()); // delete file if ($iterator->isFile()) { @@ -213,8 +214,8 @@ public function deleteDirectory(string $source): void unset($iterator); // delete the source root folder as well - if (!rmdir($source)) { - throw new \Exception(sprintf('Could not delete directory %s', $source)); + if (!\rmdir($source)) { + throw new \Exception(\sprintf('Could not delete directory %s', $source)); } } @@ -258,6 +259,7 @@ public function copyDirectory(string $source, string $target, array $exclude = [ /** * Get the prefix all paths in an array of paths have in common. + * * @param array $fileNames * * @return string @@ -268,13 +270,13 @@ public static function getCommonPathPrefix(array $fileNames): string return '/'; } - $prefix = \dirname(array_shift($fileNames)); + $prefix = \dirname(\array_shift($fileNames)); foreach ($fileNames as $filename) { $prefix = self::getCurrentCommonPathPrefix($prefix, $filename); } - if (substr($prefix, -1, 1) !== DIRECTORY_SEPARATOR) { + if (\substr($prefix, -1, 1) !== DIRECTORY_SEPARATOR) { $prefix .= DIRECTORY_SEPARATOR; } @@ -283,6 +285,7 @@ public static function getCommonPathPrefix(array $fileNames): string /** * Get the part of currentPrefix that currentPrefix and path have in common. + * * @param string $currentPrefix * @param string $path * @@ -290,11 +293,11 @@ public static function getCommonPathPrefix(array $fileNames): string */ protected static function getCurrentCommonPathPrefix(string $currentPrefix, string $path): string { - if (0 === strpos($path, $currentPrefix.DIRECTORY_SEPARATOR) + if (0 === \strpos($path, $currentPrefix.DIRECTORY_SEPARATOR) || DIRECTORY_SEPARATOR === $currentPrefix || '' === $currentPrefix || '.' === $currentPrefix - || preg_match('/^[A-Z]\:\\\\$/', $currentPrefix) === 1 + || \preg_match('/^[A-Z]\:\\\\$/', $currentPrefix) === 1 ) { return $currentPrefix; } diff --git a/src/PHPCodeBrowser/Issue.php b/src/PHPCodeBrowser/Issue.php index 9bd01ab..0f56148 100644 --- a/src/PHPCodeBrowser/Issue.php +++ b/src/PHPCodeBrowser/Issue.php @@ -1,4 +1,5 @@ - * @author Michel Hartmann + * @author Elger Thiele + * @author Michel Hartmann * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 0.1.2 + * @since File available since 0.1.2 */ namespace PHPCodeBrowser; @@ -60,20 +61,20 @@ * Object Model for issues. * This object is used for working with common issues types. * - * @category PHP_CodeBrowser + * @category PHP_CodeBrowser * - * @author Elger Thiele - * @author Michel Hartmann + * @author Elger Thiele + * @author Michel Hartmann * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://github.com/mayflowergmbh + * @link http://github.com/mayflowergmbh * - * @since Class available since 0.1.2 + * @since Class available since 0.1.2 */ class Issue { diff --git a/src/PHPCodeBrowser/IssueXML.php b/src/PHPCodeBrowser/IssueXML.php index 5e5beed..f58e1f2 100644 --- a/src/PHPCodeBrowser/IssueXML.php +++ b/src/PHPCodeBrowser/IssueXML.php @@ -1,4 +1,5 @@ - * @author Michel Hartmann + * @author Elger Thiele + * @author Michel Hartmann * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 0.1.0 + * @since File available since 0.1.0 */ namespace PHPCodeBrowser; -use \DOMDocument; -use \DOMNode; -use \DOMNodeList; -use \DOMXPath; +use DOMDocument; +use DOMNode; +use DOMNodeList; +use DOMXPath; use SebastianBergmann\FileIterator\Factory as FileIteratorFactory; /** @@ -68,20 +69,20 @@ * It is used to merge issue XML files and execute plugins * against it to retrieve the issues from them. * - * @category PHP_CodeBrowser + * @category PHP_CodeBrowser * - * @author Elger Thiele - * @author Michel Hartmann + * @author Elger Thiele + * @author Michel Hartmann * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class IssueXML extends DOMDocument { @@ -94,6 +95,7 @@ class IssueXML extends DOMDocument /** * Do not preserve white spaces. + * * @see DOMDocument * * @var bool @@ -135,14 +137,14 @@ public function addDirectory(string $directory): IssueXML $iterator = $factory->getFileIterator($directory, 'xml'); foreach ($iterator as $current) { - $realFileName = realpath($current); + $realFileName = \realpath($current); $xml = new DOMDocument('1.0', 'UTF-8'); $xml->validateOnParse = true; - if (@$xml->load(realpath($current))) { + if (@$xml->load(\realpath($current))) { $this->addXMLFile($xml); } else { - error_log( + \error_log( "[Warning] Could not read file '{$realFileName}'. ".'Make sure it contains valid xml.' ); } @@ -151,7 +153,7 @@ public function addDirectory(string $directory): IssueXML } if (!$this->documentElement->hasChildNodes()) { - error_log("[Warning] No valid log files found in '{$directory}'"); + \error_log("[Warning] No valid log files found in '{$directory}'"); } return $this; @@ -173,6 +175,7 @@ public function addXMLFile(DOMDocument $domDocument): void /** * Perform a XPath-Query on the document. + * * @see DOMXPath::query * * @param string $expression Xpath expression to query for. diff --git a/src/PHPCodeBrowser/Plugins/ErrorCPD.php b/src/PHPCodeBrowser/Plugins/ErrorCPD.php index 426bebe..e3fb55a 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCPD.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCPD.php @@ -1,4 +1,5 @@ - * @author Michel Hartmann + * @author Elger Thiele + * @author Michel Hartmann * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 0.1.0 + * @since File available since 0.1.0 */ namespace PHPCodeBrowser\Plugins; @@ -63,20 +64,20 @@ /** * ErrorCPD * - * @category PHP_CodeBrowser + * @category PHP_CodeBrowser * - * @author Elger Thiele - * @author Michel Hartmann + * @author Elger Thiele + * @author Michel Hartmann * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class ErrorCPD extends AbstractPlugin { @@ -110,7 +111,7 @@ public function mapIssues(DOMNode $element, string $filename): array (int) $file->getAttribute('line'), (int) $file->getAttribute('line') + $lineCount, 'Duplication', - htmlentities( + \htmlentities( $this->getCpdDescription($parentNode->childNodes, $file) ), 'notice' @@ -134,7 +135,7 @@ public function getFilesWithIssues(): array $fileNames[] = $node->getAttribute('path'); } - return array_unique($fileNames); + return \array_unique($fileNames); } /** @@ -171,13 +172,13 @@ protected function getCpdDescription(DOMNodeList $allNodes, DOMNode $currentNode continue; } - $source[] = sprintf( + $source[] = \sprintf( '%s (%d)', $node->getAttribute('path'), $node->getAttribute('line') ); } - return "Copy paste from:\n".implode("\n", $source); + return "Copy paste from:\n".\implode("\n", $source); } } diff --git a/src/PHPCodeBrowser/Plugins/ErrorCRAP.php b/src/PHPCodeBrowser/Plugins/ErrorCRAP.php index 9240fc8..0d38028 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCRAP.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCRAP.php @@ -1,4 +1,5 @@ + * @author Simon Kohlmeyer * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 0.2.0 + * @since File available since 0.2.0 */ namespace PHPCodeBrowser\Plugins; @@ -62,19 +63,19 @@ /** * ErrorCRAP * - * @category PHP_CodeBrowser + * @category PHP_CodeBrowser * - * @author Simon Kohlmeyer + * @author Simon Kohlmeyer * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.2.0 + * @since Class available since 0.2.0 */ class ErrorCRAP extends AbstractPlugin { @@ -97,12 +98,14 @@ class ErrorCRAP extends AbstractPlugin /** * Name of the attribute that holds the number of the last line * of the issue. + * * @var string */ protected $lineEndAttr = 'num'; /** * Default string to use as source for issue. + * * @var string */ protected $source = 'CRAP'; @@ -136,7 +139,7 @@ public function mapIssues(DOMNode $element, string $filename): array continue; } - if (array_key_exists('threshold', $this->options) + if (\array_key_exists('threshold', $this->options) && $crap <= $this->options['threshold'] ) { continue; @@ -171,7 +174,7 @@ public function getFilesWithIssues(): array $fileNames[] = $node->getAttribute('name'); } - return array_unique($fileNames); + return \array_unique($fileNames); } /** diff --git a/src/PHPCodeBrowser/Plugins/ErrorCheckstyle.php b/src/PHPCodeBrowser/Plugins/ErrorCheckstyle.php index 0909939..dc84b7f 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCheckstyle.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCheckstyle.php @@ -1,4 +1,5 @@ - * @author Michel Hartmann + * @author Elger Thiele + * @author Michel Hartmann * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 0.1.0 + * @since File available since 0.1.0 */ namespace PHPCodeBrowser\Plugins; @@ -59,27 +60,28 @@ /** * ErrorCheckstyle * - * @category PHP_CodeBrowser + * @category PHP_CodeBrowser * - * @author Elger Thiele - * @author Christopher Weckerle - * @author Michel Hartmann + * @author Elger Thiele + * @author Christopher Weckerle + * @author Michel Hartmann * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class ErrorCheckstyle extends AbstractPlugin { /** * Name of this plugin. * Used to read issues from XML. + * * @var string */ public $pluginName = 'checkstyle'; @@ -87,6 +89,7 @@ class ErrorCheckstyle extends AbstractPlugin /** * Name of the attribute that holds the number of the first line * of the issue. + * * @var string */ protected $lineStartAttr = 'line'; @@ -94,24 +97,28 @@ class ErrorCheckstyle extends AbstractPlugin /** * Name of the attribute that holds the number of the last line * of the issue. + * * @var string */ protected $lineEndAttr = 'line'; /** * Name of the attribute that holds message of the issue. + * * @var string */ protected $descriptionAttr = 'message'; /** * Name of the attribute that holds severity of the issue. + * * @var string */ protected $severityAttr = 'severity'; /** * Default string to use as source for issue. + * * @var string */ protected $source = 'Checkstyle'; diff --git a/src/PHPCodeBrowser/Plugins/ErrorCoverage.php b/src/PHPCodeBrowser/Plugins/ErrorCoverage.php index 9b6fe47..94813d1 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCoverage.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCoverage.php @@ -1,4 +1,5 @@ - * @author Michel Hartmann + * @author Elger Thiele + * @author Michel Hartmann * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 0.1.0 + * @since File available since 0.1.0 */ namespace PHPCodeBrowser\Plugins; @@ -63,26 +64,27 @@ /** * ErrorCoverage * - * @category PHP_CodeBrowser + * @category PHP_CodeBrowser * - * @author Elger Thiele - * @author Michel Hartmann + * @author Elger Thiele + * @author Michel Hartmann * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class ErrorCoverage extends AbstractPlugin { /** * Name of this plugin. * Used to read issues from XML. + * * @var string */ public $pluginName = 'coverage'; @@ -90,6 +92,7 @@ class ErrorCoverage extends AbstractPlugin /** * Name of the attribute that holds the number of the first line * of the issue. + * * @var string */ protected $lineStartAttr = 'num'; @@ -97,12 +100,14 @@ class ErrorCoverage extends AbstractPlugin /** * Name of the attribute that holds the number of the last line * of the issue. + * * @var string */ protected $lineEndAttr = 'num'; /** * Default string to use as source for issue. + * * @var string */ protected $source = 'Coverage'; @@ -183,7 +188,7 @@ public function getFilesWithIssues(): array $fileNames[] = $node->getAttribute('name'); } - return array_unique($fileNames); + return \array_unique($fileNames); } /** diff --git a/src/PHPCodeBrowser/Plugins/ErrorPMD.php b/src/PHPCodeBrowser/Plugins/ErrorPMD.php index 1ea42ae..4139a8d 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorPMD.php +++ b/src/PHPCodeBrowser/Plugins/ErrorPMD.php @@ -1,4 +1,5 @@ - * @author Michel Hartmann + * @author Elger Thiele + * @author Michel Hartmann * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 0.1.0 + * @since File available since 0.1.0 */ namespace PHPCodeBrowser\Plugins; @@ -58,27 +59,28 @@ /** * ErrorPMD * - * @category PHP_CodeBrowser + * @category PHP_CodeBrowser * - * @author Elger Thiele - * @author Christopher Weckerle - * @author Michel Hartmann + * @author Elger Thiele + * @author Christopher Weckerle + * @author Michel Hartmann * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class ErrorPMD extends AbstractPlugin { /** * Name of this plugin. * Used to read issues from XML. + * * @var string */ public $pluginName = 'pmd'; @@ -86,6 +88,7 @@ class ErrorPMD extends AbstractPlugin /** * Name of the attribute that holds the number of the first line * of the issue. + * * @var string */ protected $lineStartAttr = 'beginline'; @@ -93,12 +96,14 @@ class ErrorPMD extends AbstractPlugin /** * Name of the attribute that holds the number of the last line * of the issue. + * * @var string */ protected $lineEndAttr = 'endline'; /** * Default string to use as source for issue. + * * @var string */ protected $source = 'PMD'; @@ -126,10 +131,10 @@ protected function getSeverity(DOMElement $element): string */ protected function getDescription(DOMElement $element): string { - return str_replace( + return \str_replace( ' ', '', - htmlentities($element->textContent) + \htmlentities($element->textContent) ); } } diff --git a/src/PHPCodeBrowser/Plugins/ErrorPadawan.php b/src/PHPCodeBrowser/Plugins/ErrorPadawan.php index 88b534e..c0c2b02 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorPadawan.php +++ b/src/PHPCodeBrowser/Plugins/ErrorPadawan.php @@ -1,4 +1,5 @@ - * @author Michel Hartmann + * @author Elger Thiele + * @author Michel Hartmann * - * @copyright 2007-2009 Mayflower GmbH + * @copyright 2007-2009 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 0.1.0 + * @since File available since 0.1.0 */ namespace PHPCodeBrowser\Plugins; @@ -59,21 +60,21 @@ /** * ErrorPadawan * - * @category PHP_CodeBrowser + * @category PHP_CodeBrowser * - * @author Elger Thiele - * @author Christopher Weckerle - * @author Michel Hartmann + * @author Elger Thiele + * @author Christopher Weckerle + * @author Michel Hartmann * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class ErrorPadawan extends AbstractPlugin { @@ -87,6 +88,7 @@ class ErrorPadawan extends AbstractPlugin /** * Name of the attribute that holds the number of the first line * of the issue. + * * @var string */ protected $lineStartAttr = 'line'; @@ -94,24 +96,28 @@ class ErrorPadawan extends AbstractPlugin /** * Name of the attribute that holds the number of the last line * of the issue. + * * @var string */ protected $lineEndAttr = 'line'; /** * Name of the attribute that holds message of the issue. + * * @var string */ protected $descriptionAttr = 'message'; /** * Name of the attribute that holds severity of the issue. + * * @var string */ protected $severityAttr = 'severity'; /** * Default string to use as source for issue. + * * @var string */ protected $source = 'Padawan'; diff --git a/src/PHPCodeBrowser/SourceHandler.php b/src/PHPCodeBrowser/SourceHandler.php index 845abd4..deb3ae1 100644 --- a/src/PHPCodeBrowser/SourceHandler.php +++ b/src/PHPCodeBrowser/SourceHandler.php @@ -1,4 +1,5 @@ - * @author Michel Hartmann - * @author Simon Kohlmeyer + * @author Elger Thiele + * @author Michel Hartmann + * @author Simon Kohlmeyer * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 0.2.0 + * @since File available since 0.2.0 */ namespace PHPCodeBrowser; @@ -66,22 +67,22 @@ * This class manages lists of source files and their issues. * For providing these lists the prior generated IssueXML is parsed. * - * @category PHP_CodeBrowser + * @category PHP_CodeBrowser * - * @author Elger Thiele - * @author Christopher Weckerle - * @author Michel Hartmann - * @author Simon Kohlmeyer + * @author Elger Thiele + * @author Christopher Weckerle + * @author Michel Hartmann + * @author Simon Kohlmeyer * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.2.0 + * @since Class available since 0.2.0 */ class SourceHandler { @@ -108,7 +109,7 @@ class SourceHandler public function __construct(Logger $debugLog, array $plugins = []) { $this->debugLog = $debugLog; - array_walk($plugins, [$this, 'addPlugin']); + \array_walk($plugins, [$this, 'addPlugin']); } /** @@ -119,7 +120,7 @@ public function __construct(Logger $debugLog, array $plugins = []) public function addPlugin(AbstractPlugin $plugin): void { foreach ($plugin->getFileList() as $file) { - if (array_key_exists($file->name(), $this->files)) { + if (\array_key_exists($file->name(), $this->files)) { $this->files[$file->name()]->mergeWith($file); } else { $this->files[$file->name()] = $file; @@ -150,7 +151,7 @@ public function addSourceFile($file): void { if (\is_string($file)) { $filename = $file; - $file = realpath($file); + $file = \realpath($file); } else { $filename = $file->getPathName(); $file = $file->getRealPath(); @@ -160,7 +161,7 @@ public function addSourceFile($file): void throw new Exception("{$filename} is no regular file"); } - if (array_key_exists($file, $this->files)) { + if (\array_key_exists($file, $this->files)) { return; } @@ -174,7 +175,7 @@ public function addSourceFile($file): void */ public function getCommonPathPrefix(): string { - return IOHelper::getCommonPathPrefix(array_keys($this->files)); + return IOHelper::getCommonPathPrefix(\array_keys($this->files)); } /** @@ -196,7 +197,7 @@ public function getFiles(): array */ public function getFilesWithIssues(): array { - return array_keys($this->files); + return \array_keys($this->files); } /** @@ -208,8 +209,8 @@ public function getFilesWithIssues(): array */ public function excludeMatchingPCRE(string $expr): void { - foreach (array_keys($this->files) as $filename) { - if (!preg_match($expr, $filename)) { + foreach (\array_keys($this->files) as $filename) { + if (!\preg_match($expr, $filename)) { continue; } @@ -230,8 +231,8 @@ public function excludeMatchingPCRE(string $expr): void */ public function excludeMatchingPattern(string $pattern): void { - foreach (array_keys($this->files) as $filename) { - if (!fnmatch($pattern, $filename)) { + foreach (\array_keys($this->files) as $filename) { + if (!\fnmatch($pattern, $filename)) { continue; } diff --git a/src/PHPCodeBrowser/Tests/AbstractTestCase.php b/src/PHPCodeBrowser/Tests/AbstractTestCase.php index 90b14da..2679f40 100644 --- a/src/PHPCodeBrowser/Tests/AbstractTestCase.php +++ b/src/PHPCodeBrowser/Tests/AbstractTestCase.php @@ -1,4 +1,5 @@ + * @author Elger Thiele * - * @copyright 2007-2009 Mayflower GmbH + * @copyright 2007-2009 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 0.1.0 + * @since File available since 0.1.0 */ namespace PHPCodeBrowser\Tests; @@ -54,19 +55,19 @@ /** * AbstractTests * - * @category PHP_CodeBrowser + * @category PHP_CodeBrowser * - * @author Elger Thiele + * @author Elger Thiele * - * @copyright 2007-2009 Mayflower GmbH + * @copyright 2007-2009 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class AbstractTestCase extends \PHPUnit\Framework\TestCase { @@ -115,13 +116,13 @@ protected function setUp(): void parent::setUp(); if (!\defined('PHPCB_SOURCE_DIR')) { - \define('PHPCB_SOURCE_DIR', realpath(__DIR__.'/../')); + \define('PHPCB_SOURCE_DIR', \realpath(__DIR__.'/../')); } if (!\defined('PHPCB_TEST_DIR')) { \define( 'PHPCB_TEST_DIR', - realpath(PHPCB_SOURCE_DIR).DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR.'testData' + \realpath(PHPCB_SOURCE_DIR).DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR.'testData' ); } @@ -131,16 +132,16 @@ protected function setUp(): void self::$xmlBasic = PHPCB_TEST_LOGS.'/basic.xml'; - self::$phpcbSourceDir = realpath(__DIR__.'/Fixtures'); + self::$phpcbSourceDir = \realpath(__DIR__.'/Fixtures'); self::$testOutputDir = PHPCB_TEST_DIR.DIRECTORY_SEPARATOR.'output'; - if (is_dir(self::$testOutputDir)) { + if (\is_dir(self::$testOutputDir)) { $this->cleanUp(self::$testOutputDir); - rmdir(self::$testOutputDir); + \rmdir(self::$testOutputDir); } - mkdir(self::$testOutputDir); + \mkdir(self::$testOutputDir); } /** @@ -154,7 +155,7 @@ protected function tearDown(): void parent::tearDown(); $this->cleanUp(self::$testOutputDir); - rmdir(self::$testOutputDir); + \rmdir(self::$testOutputDir); } /** @@ -164,7 +165,7 @@ protected function tearDown(): void */ protected function getSerializedErrors(): array { - return unserialize(file_get_contents(self::$serializedErrors)); + return \unserialize(\file_get_contents(self::$serializedErrors)); } /** @@ -181,13 +182,13 @@ protected function cleanUp(string $dir): void while ($iterator->valid()) { // delete file if ($iterator->isFile()) { - unlink($dir.'/'.$iterator->current()); + \unlink($dir.'/'.$iterator->current()); } // delete folder recursive if (!$iterator->isDot() && $iterator->isDir()) { $this->cleanUp($dir.'/'.$iterator->current()); - rmdir($dir.'/'.$iterator->current()); + \rmdir($dir.'/'.$iterator->current()); } $iterator->next(); diff --git a/src/PHPCodeBrowser/Tests/CLIControllerTest.php b/src/PHPCodeBrowser/Tests/CLIControllerTest.php index dd89a01..736d53e 100644 --- a/src/PHPCodeBrowser/Tests/CLIControllerTest.php +++ b/src/PHPCodeBrowser/Tests/CLIControllerTest.php @@ -1,4 +1,5 @@ + * @author Simon Kohlmeyer * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class CLIControllerTest extends AbstractTestCase { @@ -139,9 +140,9 @@ public function testRunCreatesFilesAndDirs(): void */ public function testRunCleansExistingOutputDir(): void { - mkdir(self::$testOutputDir.'/clear-directory'); - touch(self::$testOutputDir.'/clear-file'); - touch(self::$testOutputDir.'/clear-directory/clear-file'); + \mkdir(self::$testOutputDir.'/clear-directory'); + \touch(self::$testOutputDir.'/clear-file'); + \touch(self::$testOutputDir.'/clear-directory/clear-file'); $this->controller->run(); @@ -155,8 +156,8 @@ public function testRunCleansExistingOutputDir(): void */ public function testRunCleansExistingOutputFile(): void { - rmdir(self::$testOutputDir); - touch(self::$testOutputDir); + \rmdir(self::$testOutputDir); + \touch(self::$testOutputDir); $this->controller->run(); diff --git a/src/PHPCodeBrowser/Tests/FileTest.php b/src/PHPCodeBrowser/Tests/FileTest.php index c7311e4..7376c0c 100644 --- a/src/PHPCodeBrowser/Tests/FileTest.php +++ b/src/PHPCodeBrowser/Tests/FileTest.php @@ -1,4 +1,5 @@ + * @author Simon Kohlmeyer * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class FileTest extends AbstractTestCase { @@ -102,6 +103,7 @@ public function __construct() /** * (non-PHPDoc) + * * @see AbstractTests#setUp() */ protected function setUp(): void @@ -236,8 +238,8 @@ public function testMergeWith(): void $this->assertEquals(2, $this->file->getErrorCount()); $this->assertEquals(1, $this->file->getWarningCount()); $this->assertEquals( - array_values($this->issues), - array_values($this->file->getIssues()) + \array_values($this->issues), + \array_values($this->file->getIssues()) ); } @@ -301,7 +303,7 @@ public function testSort(): void ]; File::sort($mixed); - $mixed = array_values($mixed); + $mixed = \array_values($mixed); $this->assertEquals($sorted, $mixed); } } diff --git a/src/PHPCodeBrowser/Tests/Helper/IOHelperTest.php b/src/PHPCodeBrowser/Tests/Helper/IOHelperTest.php index b0db51e..71c9298 100644 --- a/src/PHPCodeBrowser/Tests/Helper/IOHelperTest.php +++ b/src/PHPCodeBrowser/Tests/Helper/IOHelperTest.php @@ -1,4 +1,5 @@ + * @author Simon Kohlmeyer * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class IOHelperTest extends AbstractTestCase { @@ -82,6 +83,7 @@ class IOHelperTest extends AbstractTestCase /** * (non-PHPDoc) + * * @see AbstractTestCase::setUp() */ protected function setUp(): void @@ -101,15 +103,15 @@ public function testFileCreation(): void $filename = self::$testOutputDir.'/tmpfile'; $content = 'Lorem ipsum'; - if (file_exists($filename)) { - unlink($filename); + if (\file_exists($filename)) { + \unlink($filename); } $this->ioHelper->createFile($filename, $content); $this->assertFileExists($filename); - $this->assertEquals($content, file_get_contents($filename)); + $this->assertEquals($content, \file_get_contents($filename)); - unlink($filename); + \unlink($filename); } /** @@ -123,20 +125,20 @@ public function testCreationOfFileWithPath(): void $filename = $dirName.'/tmpfile'; $content = 'Lorem ipsum'; - if (file_exists($filename)) { - unlink($filename); - rmdir($dirName); - } elseif (file_exists($dirName)) { - rmdir($dirName); + if (\file_exists($filename)) { + \unlink($filename); + \rmdir($dirName); + } elseif (\file_exists($dirName)) { + \rmdir($dirName); } $this->ioHelper->createFile($filename, $content); $this->assertFileExists($dirName); $this->assertFileExists($filename); - $this->assertEquals($content, file_get_contents($filename)); + $this->assertEquals($content, \file_get_contents($filename)); - unlink($filename); - rmdir($dirName); + \unlink($filename); + \rmdir($dirName); } /** @@ -148,8 +150,8 @@ public function testFileDeletion(): void { $filename = self::$testOutputDir.'/tmpfile'; - if (!file_exists($filename)) { - file_put_contents($filename, 'Lorem ipsum'); + if (!\file_exists($filename)) { + \file_put_contents($filename, 'Lorem ipsum'); } $this->ioHelper->deleteFile($filename); @@ -167,9 +169,9 @@ public function testDirectoryDeletion(): void $file = $dir.'/file'; $subDir = $dir.'/subDir'; - mkdir($dir); - mkdir($subDir); - touch($file); + \mkdir($dir); + \mkdir($subDir); + \touch($file); $this->ioHelper->deleteDirectory($dir); $this->assertFileNotExists($dir); @@ -187,26 +189,26 @@ public function testCopyFile(): void $dstFile = $dstDir.'/tmpfile'; $content = 'Lorem ipsum'; - if (file_exists($srcFile)) { - unlink($srcFile); + if (\file_exists($srcFile)) { + \unlink($srcFile); } - if (file_exists($dstFile)) { - rmdir($dstFile); + if (\file_exists($dstFile)) { + \rmdir($dstFile); } - file_put_contents($srcFile, $content); + \file_put_contents($srcFile, $content); $this->ioHelper->copyFile($srcFile, $dstDir); $this->assertFileExists($srcFile); $this->assertFileExists($dstDir); $this->assertFileExists($dstFile); - $this->assertEquals($content, file_get_contents($dstFile)); - $this->assertEquals($content, file_get_contents($srcFile)); + $this->assertEquals($content, \file_get_contents($dstFile)); + $this->assertEquals($content, \file_get_contents($srcFile)); - unlink($dstFile); - rmdir($dstDir); - unlink($srcFile); + \unlink($dstFile); + \rmdir($dstDir); + \unlink($srcFile); } /** @@ -220,8 +222,8 @@ public function testLoadFileWithNonexistentFile(): void $sourceFile = self::$testOutputDir.'/doesNotExist'; - if (file_exists($sourceFile)) { - unlink(self::$testOutputDir.'/doesNotExist'); + if (\file_exists($sourceFile)) { + \unlink(self::$testOutputDir.'/doesNotExist'); } $this->ioHelper->loadFile($sourceFile); @@ -239,8 +241,8 @@ public function testCopyFileNonExisting(): void $file = self::$testOutputDir.'/tmpfile'; $dstDir = self::$testOutputDir.'/tmpdir'; - if (file_exists($file)) { - unlink($file); + if (\file_exists($file)) { + \unlink($file); } $this->ioHelper->copyFile($file, $dstDir); diff --git a/src/PHPCodeBrowser/Tests/IssueTest.php b/src/PHPCodeBrowser/Tests/IssueTest.php index e0a013e..5e46b2f 100644 --- a/src/PHPCodeBrowser/Tests/IssueTest.php +++ b/src/PHPCodeBrowser/Tests/IssueTest.php @@ -1,4 +1,5 @@ + * @author Simon Kohlmeyer * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class IssueTest extends AbstractTestCase { @@ -81,6 +82,7 @@ class IssueTest extends AbstractTestCase /** * (non-PHPDoc) + * * @see tests/cbAbstractTests#setUp() */ protected function setUp(): void @@ -98,6 +100,7 @@ protected function setUp(): void /** * (non-PHPDoc) + * * @see tests/cbAbstractTests#tearDown() */ protected function tearDown(): void diff --git a/src/PHPCodeBrowser/Tests/Plugins/ErrorCPDTest.php b/src/PHPCodeBrowser/Tests/Plugins/ErrorCPDTest.php index 1c4698d..f8e0dfb 100644 --- a/src/PHPCodeBrowser/Tests/Plugins/ErrorCPDTest.php +++ b/src/PHPCodeBrowser/Tests/Plugins/ErrorCPDTest.php @@ -1,4 +1,5 @@ + * @author Simon Kohlmeyer * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.9.0 + * @since Class available since 0.9.0 */ class ErrorCPDTest extends AbstractTestCase { @@ -104,6 +105,7 @@ class ErrorCPDTest extends AbstractTestCase /** * (non-PHPDoc) + * * @see tests/cbAbstractTests#setUp() */ protected function setUp(): void @@ -119,7 +121,7 @@ protected function setUp(): void /** * Test getFileList * - * @return void + * @return void */ public function testGettingFileList(): void { diff --git a/src/PHPCodeBrowser/Tests/Plugins/ErrorCRAPTest.php b/src/PHPCodeBrowser/Tests/Plugins/ErrorCRAPTest.php index 73fe2ac..fd720d0 100644 --- a/src/PHPCodeBrowser/Tests/Plugins/ErrorCRAPTest.php +++ b/src/PHPCodeBrowser/Tests/Plugins/ErrorCRAPTest.php @@ -1,4 +1,5 @@ + * @author Simon Kohlmeyer * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.9.0 + * @since Class available since 0.9.0 */ class ErrorCRAPTest extends AbstractTestCase { @@ -129,6 +130,7 @@ class ErrorCRAPTest extends AbstractTestCase /** * (non-PHPDoc) + * * @see tests/cbAbstractTests#setUp() */ protected function setUp(): void @@ -144,7 +146,7 @@ protected function setUp(): void /** * Test getFileList * - * @return void + * @return void */ public function testGettingFileList(): void { @@ -182,7 +184,7 @@ public function testGettingFileList(): void /** * Test getFileList with limit set * - * @return void + * @return void */ public function testGetFileListWithLimit(): void { diff --git a/src/PHPCodeBrowser/Tests/Plugins/ErrorCheckstyleTest.php b/src/PHPCodeBrowser/Tests/Plugins/ErrorCheckstyleTest.php index 82e9054..ed90b5b 100644 --- a/src/PHPCodeBrowser/Tests/Plugins/ErrorCheckstyleTest.php +++ b/src/PHPCodeBrowser/Tests/Plugins/ErrorCheckstyleTest.php @@ -1,4 +1,5 @@ + * @author Simon Kohlmeyer * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.9.0 + * @since Class available since 0.9.0 */ class ErrorCheckstyleTest extends AbstractTestCase { @@ -118,6 +119,7 @@ class ErrorCheckstyleTest extends AbstractTestCase /** * (non-PHPDoc) + * * @see tests/cbAbstractTests#setUp() */ protected function setUp(): void @@ -134,7 +136,7 @@ protected function setUp(): void /** * Test getFileList * - * @return void + * @return void */ public function testGettingFileList(): void { diff --git a/src/PHPCodeBrowser/Tests/Plugins/ErrorCoverageTest.php b/src/PHPCodeBrowser/Tests/Plugins/ErrorCoverageTest.php index 8ae78fb..a228929 100644 --- a/src/PHPCodeBrowser/Tests/Plugins/ErrorCoverageTest.php +++ b/src/PHPCodeBrowser/Tests/Plugins/ErrorCoverageTest.php @@ -1,4 +1,5 @@ + * @author Simon Kohlmeyer * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.9.0 + * @since Class available since 0.9.0 */ class ErrorCoverageTest extends AbstractTestCase { @@ -130,6 +131,7 @@ class ErrorCoverageTest extends AbstractTestCase /** * (non-PHPDoc) + * * @see tests/cbAbstractTests#setUp() */ protected function setUp(): void @@ -145,7 +147,7 @@ protected function setUp(): void /** * Test getFileList * - * @return void + * @return void */ public function testGettingFileList(): void { diff --git a/src/PHPCodeBrowser/Tests/Plugins/ErrorPMDTest.php b/src/PHPCodeBrowser/Tests/Plugins/ErrorPMDTest.php index 87bd051..9c7a629 100644 --- a/src/PHPCodeBrowser/Tests/Plugins/ErrorPMDTest.php +++ b/src/PHPCodeBrowser/Tests/Plugins/ErrorPMDTest.php @@ -1,4 +1,5 @@ + * @author Simon Kohlmeyer * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.9.0 + * @since Class available since 0.9.0 */ class ErrorPMDTest extends AbstractTestCase { @@ -120,6 +121,7 @@ class="SomeClass" /** * (non-PHPDoc) + * * @see tests/cbAbstractTests#setUp() */ protected function setUp(): void @@ -135,7 +137,7 @@ protected function setUp(): void /** * Test getFileList * - * @return void + * @return void */ public function testGettingFileList(): void { diff --git a/src/PHPCodeBrowser/Tests/SourceHandlerTest.php b/src/PHPCodeBrowser/Tests/SourceHandlerTest.php index dcfbbb2..0fd1dce 100644 --- a/src/PHPCodeBrowser/Tests/SourceHandlerTest.php +++ b/src/PHPCodeBrowser/Tests/SourceHandlerTest.php @@ -1,4 +1,5 @@ + * @author Simon Kohlmeyer * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class SourceHandlerTest extends AbstractTestCase { @@ -153,6 +154,7 @@ public function __construct() /** * (non-PHPDoc) + * * @see AbstractTests#setUp() */ protected function setUp(): void @@ -163,7 +165,7 @@ protected function setUp(): void $this->logger->pushHandler(new NullHandler()); $this->sourceHandler = new SourceHandler($this->logger); - array_walk( + \array_walk( $this->plugins, [$this->sourceHandler, 'addPlugin'] ); @@ -237,7 +239,7 @@ public function testAddSourceFiles(): void $this->sourceHandler->addSourceFiles( [new SplFileInfo(__FILE__), __FILE__] ); - $this->assertContains(__FILE__, array_keys($this->sourceHandler->getFiles())); + $this->assertContains(__FILE__, \array_keys($this->sourceHandler->getFiles())); } /** diff --git a/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php b/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php index d7f858c..c9eb738 100644 --- a/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php +++ b/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php @@ -1,4 +1,5 @@ + * @author Simon Kohlmeyer * - * @copyright 2007-2010 Mayflower GmbH + * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class ViewReviewTest extends AbstractTestCase { @@ -93,6 +94,7 @@ class ViewReviewTest extends AbstractTestCase /** * (non-PHPDoc) + * * @see tests/cbAbstractTests#setUp() */ protected function setUp(): void @@ -102,7 +104,7 @@ protected function setUp(): void $this->ioMock = $this->createMock(IOHelper::class); $this->viewReview = new ViewReview( - PHPCB_ROOT_DIR.'/../templates/', + \getenv('PHPCB_TEMPLATE_DIR') ?: \dirname(__FILE__, 5).'/templates', self::$testOutputDir, $this->ioMock ); @@ -115,15 +117,15 @@ protected function setUp(): void */ public function testGenerateNoIssues(): void { - $expectedFile = self::$testOutputDir.DIRECTORY_SEPARATOR.basename(__FILE__).'.html'; + $expectedFile = self::$testOutputDir.DIRECTORY_SEPARATOR.\basename(__FILE__).'.html'; $this->ioMock->expects($this->once()) - ->method('loadFile') - ->with($this->equalTo(__FILE__)) - ->willReturn(file_get_contents(__FILE__)); + ->method('loadFile') + ->with($this->equalTo(__FILE__)) + ->willReturn(\file_get_contents(__FILE__)); $this->ioMock->expects($this->once()) - ->method('createFile') - ->with($this->equalTo($expectedFile)); + ->method('createFile') + ->with($this->equalTo($expectedFile)); $this->viewReview->generate( [], @@ -150,14 +152,14 @@ public function testGenerate(): void ), ]; - $expectedFile = self::$testOutputDir.DIRECTORY_SEPARATOR.basename(__FILE__).'.html'; + $expectedFile = self::$testOutputDir.DIRECTORY_SEPARATOR.\basename(__FILE__).'.html'; $this->ioMock->expects($this->once()) - ->method('loadFile') - ->with($this->equalTo(__FILE__)) - ->willReturn(file_get_contents(__FILE__)); + ->method('loadFile') + ->with($this->equalTo(__FILE__)) + ->willReturn(\file_get_contents(__FILE__)); $this->ioMock->expects($this->once()) - ->method('createFile') - ->with($this->equalTo($expectedFile)); + ->method('createFile') + ->with($this->equalTo($expectedFile)); $this->viewReview->generate( $issueList, @@ -178,14 +180,14 @@ public function testGenerateMultiple(): void new Issue(__FILE__, 80, 80, 'other finder', 'other description', 'more severe'), ]; - $expectedFile = self::$testOutputDir.DIRECTORY_SEPARATOR.basename(__FILE__).'.html'; + $expectedFile = self::$testOutputDir.DIRECTORY_SEPARATOR.\basename(__FILE__).'.html'; $this->ioMock->expects($this->once()) - ->method('loadFile') - ->with($this->equalTo(__FILE__)) - ->willReturn(file_get_contents(__FILE__)); + ->method('loadFile') + ->with($this->equalTo(__FILE__)) + ->willReturn(\file_get_contents(__FILE__)); $this->ioMock->expects($this->once()) - ->method('createFile') - ->with($this->equalTo($expectedFile)); + ->method('createFile') + ->with($this->equalTo($expectedFile)); $this->viewReview->generate( $issueList, @@ -201,7 +203,7 @@ public function testGenerateMultiple(): void */ public function testGenerateWithTextHighlighter(): void { - if (!class_exists('Text_Highlighter')) { + if (!\class_exists('Text_Highlighter')) { $this->markTestIncomplete(); } @@ -220,12 +222,12 @@ public function testGenerateWithTextHighlighter(): void $expectedFile = self::$testOutputDir.'/file.html.html'; $this->ioMock->expects($this->once()) - ->method('loadFile') - ->with($this->equalTo($fileName)) - ->willReturn($html); + ->method('loadFile') + ->with($this->equalTo($fileName)) + ->willReturn($html); $this->ioMock->expects($this->once()) - ->method('createFile') - ->with($this->equalTo($expectedFile)); + ->method('createFile') + ->with($this->equalTo($expectedFile)); $issues = [ new Issue($fileName, 5, 5, 'finder', 'description', 'severity'), @@ -241,11 +243,11 @@ public function testGenerateWithTextHighlighter(): void */ public function testGenerateUnknownType(): void { - $expectedFile = self::$testOutputDir.DIRECTORY_SEPARATOR.basename(self::$xmlBasic).'.html'; + $expectedFile = self::$testOutputDir.DIRECTORY_SEPARATOR.\basename(self::$xmlBasic).'.html'; $this->ioMock->expects($this->once()) - ->method('createFile') - ->with($this->equalTo($expectedFile)); + ->method('createFile') + ->with($this->equalTo($expectedFile)); $issueList = [ new Issue(self::$xmlBasic, 5, 5, 'finder', 'description', 'severity'), @@ -266,12 +268,12 @@ public function testGenerateUnknownType(): void public function testCopyResourceFolders(): void { $this->ioMock->expects($this->exactly(3)) - ->method('copyDirectory') - ->with( - $this->matchesRegularExpression( - '|^'.realpath(__DIR__.'/../../../templates/').'|' - ) - ); + ->method('copyDirectory') + ->with( + $this->matchesRegularExpression( + '|^'.\realpath(__DIR__.'/../../../templates/').'|' + ) + ); $this->viewReview->copyResourceFolders(); } @@ -289,12 +291,12 @@ public function testGenerateIndex(): void ]; $this->ioMock->expects($this->once()) - ->method('createFile') - ->with( - $this->logicalAnd( - $this->stringEndsWith('index.html') - ) - ); + ->method('createFile') + ->with( + $this->logicalAnd( + $this->stringEndsWith('index.html') + ) + ); $this->viewReview->generateIndex($files); } } diff --git a/src/PHPCodeBrowser/View/ViewAbstract.php b/src/PHPCodeBrowser/View/ViewAbstract.php index f58c486..c41f3a7 100644 --- a/src/PHPCodeBrowser/View/ViewAbstract.php +++ b/src/PHPCodeBrowser/View/ViewAbstract.php @@ -1,4 +1,5 @@ - * @author Jan Mergler - * @author Simon Kohlmeyer + * @author Elger Thiele + * @author Jan Mergler + * @author Simon Kohlmeyer * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 0.1.0 + * @since File available since 0.1.0 */ namespace PHPCodeBrowser\View; @@ -64,21 +65,21 @@ * * This class is generating the highlighted and formatted html view for file. * - * @category PHP_CodeBrowser + * @category PHP_CodeBrowser * - * @author Elger Thiele - * @author Jan Mergler - * @author Simon Kohlmeyer + * @author Elger Thiele + * @author Jan Mergler + * @author Simon Kohlmeyer * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class ViewAbstract { @@ -187,7 +188,7 @@ public function generateIndex(array $fileList, bool $excludeOK = false): void { //we want to exclude files without issues if ($excludeOK) { - $fileList = array_filter($fileList, [ViewAbstract::class, 'hasFileAnyIssues']); + $fileList = \array_filter($fileList, [ViewAbstract::class, 'hasFileAnyIssues']); } $data = []; @@ -230,7 +231,7 @@ protected function getTreeListHtml(array $fileList, string $hrefPrefix = ''): st * This is important so that $curDir doesn't become empty if we go * up to the root directory ('/' on linux) */ - $curDir = IOHelper::getCommonPathPrefix(array_keys($fileList)); + $curDir = IOHelper::getCommonPathPrefix(\array_keys($fileList)); $preLen = \strlen($curDir); $indentStep = 4; @@ -241,25 +242,25 @@ protected function getTreeListHtml(array $fileList, string $hrefPrefix = ''): st $dir = \dirname($name).DIRECTORY_SEPARATOR; // Go back until the file is somewhere below curDir - while (strpos($dir, $curDir) !== 0) { + while (\strpos($dir, $curDir) !== 0) { // chop off one subDir from $curDir - $curDir = substr( + $curDir = \substr( $curDir, 0, - strrpos($curDir, DIRECTORY_SEPARATOR, -2) + 1 + \strrpos($curDir, DIRECTORY_SEPARATOR, -2) + 1 ); - $ret .= str_pad(' ', $indent); + $ret .= \str_pad(' ', $indent); $ret .= '
'.PHP_EOL; $indent -= $indentStep; - $ret .= str_pad(' ', $indent); + $ret .= \str_pad(' ', $indent); $ret .= ''.PHP_EOL; } if ($dir !== $curDir) { // File is in a subDir of current directory // relDir has no leading or trailing slash. - $relDir = substr($dir, \strlen($curDir), -1); - $relDirs = explode(DIRECTORY_SEPARATOR, $relDir); + $relDir = \substr($dir, \strlen($curDir), -1); + $relDirs = \explode(DIRECTORY_SEPARATOR, $relDir); foreach ($relDirs as $dirName) { $curDir .= $dirName.DIRECTORY_SEPARATOR; @@ -268,8 +269,8 @@ protected function getTreeListHtml(array $fileList, string $hrefPrefix = ''): st $errors = 0; $warnings = 0; - foreach (array_keys($fileList) as $fName) { - if (strncmp($fName, $curDir, \strlen($curDir)) !== 0) { + foreach (\array_keys($fileList) as $fName) { + if (\strncmp($fName, $curDir, \strlen($curDir)) !== 0) { continue; } @@ -286,17 +287,17 @@ protected function getTreeListHtml(array $fileList, string $hrefPrefix = ''): st $count .= $warnings.')'; } - $ret .= str_pad(' ', $indent); + $ret .= \str_pad(' ', $indent); $ret .= "
  • {$dirName} {$count}".PHP_EOL; $indent += $indentStep; - $ret .= str_pad(' ', $indent); + $ret .= \str_pad(' ', $indent); $ret .= '
      '.PHP_EOL; } } - $name = str_replace('\\', '/', $name); - $shortName = substr($name, $preLen); - $fileName = basename($name); + $name = \str_replace('\\', '/', $name); + $shortName = \substr($name, $preLen); + $fileName = \basename($name); $count = ''; if (0 !== $file->getErrorCount() || 0 !== $file->getWarningCount()) { @@ -307,7 +308,7 @@ protected function getTreeListHtml(array $fileList, string $hrefPrefix = ''): st $count .= ')'; } - $ret .= str_pad(' ', $indent); + $ret .= \str_pad(' ', $indent); $ret .= '
    • '; $ret .= "{$fileName} {$count}
    • ".PHP_EOL; @@ -315,10 +316,10 @@ protected function getTreeListHtml(array $fileList, string $hrefPrefix = ''): st while ($indent > $indentStep) { $indent -= $indentStep; - $ret .= str_pad(' ', $indent); + $ret .= \str_pad(' ', $indent); $ret .= '
    '.PHP_EOL; $indent -= $indentStep; - $ret .= str_pad(' ', $indent); + $ret .= \str_pad(' ', $indent); $ret .= '
  • '.PHP_EOL; } @@ -342,12 +343,12 @@ protected function render(string $templateName, array $data): string { $filePath = $this->templateDir.DIRECTORY_SEPARATOR.$templateName.'.tpl'; - extract($data, EXTR_SKIP); + \extract($data, EXTR_SKIP); - ob_start(); - include($filePath); - $contents = ob_get_contents(); - ob_end_clean(); + \ob_start(); + include $filePath; + $contents = \ob_get_contents(); + \ob_end_clean(); return $contents; } diff --git a/src/PHPCodeBrowser/View/ViewReview.php b/src/PHPCodeBrowser/View/ViewReview.php index 790e5bc..230b3d0 100644 --- a/src/PHPCodeBrowser/View/ViewReview.php +++ b/src/PHPCodeBrowser/View/ViewReview.php @@ -1,4 +1,5 @@ - * @author Jan Mergler - * @author Simon Kohlmeyer + * @author Elger Thiele + * @author Jan Mergler + * @author Simon Kohlmeyer * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version SVN: $Id$ + * @version SVN: $Id$ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since File available since 0.1.0 + * @since File available since 0.1.0 */ namespace PHPCodeBrowser\View; @@ -65,21 +66,21 @@ * * This class is generating the highlighted and formatted html view for file. * - * @category PHP_CodeBrowser + * @category PHP_CodeBrowser * - * @author Elger Thiele - * @author Jan Mergler - * @author Simon Kohlmeyer + * @author Elger Thiele + * @author Jan Mergler + * @author Simon Kohlmeyer * * @copyright 2007-2010 Mayflower GmbH * - * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @license http://www.opensource.org/licenses/bsd-license.php BSD License * - * @version Release: @package_version@ + * @version Release: @package_version@ * - * @link http://www.phpunit.de/ + * @link http://www.phpunit.de/ * - * @since Class available since 0.1.0 + * @since Class available since 0.1.0 */ class ViewReview extends ViewAbstract { @@ -112,11 +113,11 @@ public function __construct(string $templateDir, string $outputDir, IOHelper $io parent::__construct($templateDir, $outputDir, $ioHelper); $this->phpHighlightColorMap = [ - ini_get('highlight.string') => 'string', - ini_get('highlight.comment') => 'comment', - ini_get('highlight.keyword') => 'keyword', - ini_get('highlight.default') => 'default', - ini_get('highlight.html') => 'html', + \ini_get('highlight.string') => 'string', + \ini_get('highlight.comment') => 'comment', + \ini_get('highlight.keyword') => 'keyword', + \ini_get('highlight.default') => 'default', + \ini_get('highlight.html') => 'html', ]; $this->phpSuffixes = $phpSuffixes; @@ -144,7 +145,7 @@ public function __construct(string $templateDir, string $outputDir, IOHelper $io public function generate(array $issueList, string $fileName, string $commonPathPrefix, bool $excludeOK = false): void { $issues = $this->formatIssues($issueList); - $shortFilename = substr($fileName, \strlen($commonPathPrefix)); + $shortFilename = \substr($fileName, \strlen($commonPathPrefix)); $data = []; @@ -152,8 +153,8 @@ public function generate(array $issueList, string $fileName, string $commonPathP $data['filepath'] = $shortFilename; $data['source'] = $this->formatSourceCode($fileName, $issues); - $depth = substr_count($shortFilename, DIRECTORY_SEPARATOR); - $data['csspath'] = str_repeat('../', $depth - 1 >= 0 ? $depth - 1 : 0); + $depth = \substr_count($shortFilename, DIRECTORY_SEPARATOR); + $data['csspath'] = \str_repeat('../', $depth - 1 >= 0 ? $depth - 1 : 0); //we want to exclude files without issues and there are no issues in this one if ($excludeOK && !$data['issues']) { @@ -179,19 +180,19 @@ public function generate(array $issueList, string $fileName, string $commonPathP */ protected function highlightPhpCode(string $sourceCode): DOMDocument { - $code = highlight_string($sourceCode, true); + $code = \highlight_string($sourceCode, true); - if (\extension_loaded('mbstring') && !mb_check_encoding($code, 'UTF-8')) { - $detectOrder = mb_detect_order(); + if (\extension_loaded('mbstring') && !\mb_check_encoding($code, 'UTF-8')) { + $detectOrder = \mb_detect_order(); $detectOrder[] = 'iso-8859-1'; - $encoding = mb_detect_encoding($code, $detectOrder, true); + $encoding = \mb_detect_encoding($code, $detectOrder, true); if (false === $encoding) { - error_log('Error detecting file encoding'); + \error_log('Error detecting file encoding'); } - $code = mb_convert_encoding( + $code = \mb_convert_encoding( $code, 'UTF-8', $encoding @@ -203,7 +204,7 @@ protected function highlightPhpCode(string $sourceCode): DOMDocument //fetch ->->children from php generated html $sourceElements = $sourceDom->getElementsByTagname('code')->item(0) - ->childNodes->item(0)->childNodes; + ->childNodes->item(0)->childNodes; //create target dom $targetDom = new DOMDocument(); @@ -218,7 +219,7 @@ protected function highlightPhpCode(string $sourceCode): DOMDocument foreach ($sourceElements as $sourceElement) { if (!$sourceElement instanceof DOMElement) { $span = $targetDom->createElement('span'); - $span->nodeValue = htmlspecialchars($sourceElement->wholeText); + $span->nodeValue = \htmlspecialchars($sourceElement->wholeText); $liElement->appendChild($span); continue; @@ -246,7 +247,7 @@ protected function highlightPhpCode(string $sourceCode): DOMDocument } else { // append content to current li element $span = $targetDom->createElement('span'); - $span->nodeValue = htmlspecialchars($sourceChildElement->textContent); + $span->nodeValue = \htmlspecialchars($sourceChildElement->textContent); $span->setAttribute('class', $elementClass); $liElement->appendChild($span); } @@ -265,7 +266,7 @@ protected function highlightPhpCode(string $sourceCode): DOMDocument */ protected function mapPhpColors(string $style): string { - $color = substr($style, 7); + $color = \substr($style, 7); return $this->phpHighlightColorMap[$color]; } @@ -284,18 +285,18 @@ protected function mapPhpColors(string $style): string protected function highlightCode(string $file): DOMDocument { $sourceCode = $this->ioHelper->loadFile($file); - $extension = pathinfo($file, PATHINFO_EXTENSION); + $extension = \pathinfo($file, PATHINFO_EXTENSION); if (\in_array($extension, $this->phpSuffixes)) { return $this->highlightPhpCode($sourceCode); } - $sourceCode = preg_replace( + $sourceCode = \preg_replace( '/^.*$/m', '
  • $0
  • ', - htmlentities($sourceCode) + \htmlentities($sourceCode) ); - $sourceCode = preg_replace('/ /', ' ', $sourceCode); + $sourceCode = \preg_replace('/ /', ' ', $sourceCode); $sourceCode = '
      '.$sourceCode.'
    '; $sourceCode = $this->stripInvalidXml($sourceCode); @@ -329,10 +330,12 @@ private function formatSourceCode(string $filename, array $outputIssues): string } $lineNumber = 0; - $linePlaces = floor(log($lines->length, 10)) + 1; + $linePlaces = \floor(\log($lines->length, 10)) + 1; foreach ($lines as $line) { - /** @var DOMElement $line */ + /** + * @var DOMElement $line +*/ $line = $line; ++$lineNumber; $line->setAttribute('id', 'line_'.$lineNumber); @@ -346,7 +349,7 @@ private function formatSourceCode(string $filename, array $outputIssues): string $message = '|'; foreach ($outputIssues[$lineNumber] as $issue) { - $message .= sprintf( + $message .= \sprintf( '
    %s
    @@ -359,7 +362,7 @@ private function formatSourceCode(string $filename, array $outputIssues): string ); } - $line->setAttribute('title', utf8_encode($message)); + $line->setAttribute('title', \utf8_encode($message)); } // Add line number @@ -402,7 +405,7 @@ private function formatSourceCode(string $filename, array $outputIssues): string // @codeCoverageIgnoreEnd } - $line->setAttribute('class', implode(' ', $lineClasses)); + $line->setAttribute('class', \implode(' ', $lineClasses)); } return $sourceDom->saveHTML(); From ae293d5ed2bc5dd7424c1a33e66df8be18253b51 Mon Sep 17 00:00:00 2001 From: Christian Albrecht Date: Sat, 23 Jan 2021 19:55:43 +0100 Subject: [PATCH 11/34] Release 2.4.0 Increase minimum required php version to 7.3 Enable on phpunit 9.0 Enable with php-file-iterator 3.0 --- box.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/box.json b/box.json index a138a0d..0c99fa9 100644 --- a/box.json +++ b/box.json @@ -29,5 +29,5 @@ ], "git-commit": "git-commit", "git-version": "git-version", - "output": "phpcb-2.3.2.phar" + "output": "phpcb-2.4.0.phar" } From f9f802c5288980fa38c51141d9be1268e8d91bb2 Mon Sep 17 00:00:00 2001 From: Christian Albrecht Date: Tue, 15 Jun 2021 19:06:03 +0200 Subject: [PATCH 12/34] Update dependencies for php80 humbug/box has a dependency that requires minimum-stability = dev --- composer.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index eee6994..7240321 100644 --- a/composer.json +++ b/composer.json @@ -15,16 +15,18 @@ "role": "developer" } ], + "minimum-stability": "dev", + "prefer-stable": true, "require": { - "php": "^7.3", + "php": "^7.3||^8.0", "ext-dom": "*", "monolog/monolog": "~1.7||~2.0", "phpunit/php-file-iterator": "~2.0||^3.0", "symfony/console": "~3.4||~4.0||~5.0" }, "require-dev": { - "humbug/box": "^3.8.3", - "mayflower/mo4-coding-standard": "^6.0", + "humbug/box": "^3.13", + "mayflower/mo4-coding-standard": "^7.0", "phploc/phploc": "*", "phpmd/phpmd": "1.5.*||~2.6", "phpstan/phpstan": "^0.12.5", From bb260fc6c54861f921e3bba696fe0192ed01fb30 Mon Sep 17 00:00:00 2001 From: Christian Albrecht Date: Tue, 15 Jun 2021 19:08:11 +0200 Subject: [PATCH 13/34] Autofix new phpcs issues --- src/PHPCodeBrowser/Tests/AbstractTestCase.php | 4 +++- src/PHPCodeBrowser/Tests/ApplicationTest.php | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/PHPCodeBrowser/Tests/AbstractTestCase.php b/src/PHPCodeBrowser/Tests/AbstractTestCase.php index 2679f40..98ab92d 100644 --- a/src/PHPCodeBrowser/Tests/AbstractTestCase.php +++ b/src/PHPCodeBrowser/Tests/AbstractTestCase.php @@ -52,6 +52,8 @@ namespace PHPCodeBrowser\Tests; +use PHPUnit\Framework\TestCase; + /** * AbstractTests * @@ -69,7 +71,7 @@ * * @since Class available since 0.1.0 */ -class AbstractTestCase extends \PHPUnit\Framework\TestCase +class AbstractTestCase extends TestCase { /** * PHP_CodeBrowser test output dir diff --git a/src/PHPCodeBrowser/Tests/ApplicationTest.php b/src/PHPCodeBrowser/Tests/ApplicationTest.php index a54fb78..8873345 100644 --- a/src/PHPCodeBrowser/Tests/ApplicationTest.php +++ b/src/PHPCodeBrowser/Tests/ApplicationTest.php @@ -4,12 +4,13 @@ use PHPCodeBrowser\Application; use PHPCodeBrowser\Command\RunCommand; +use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Input\InputArgument; /** * Class ApplicationTest */ -class ApplicationTest extends \PHPUnit\Framework\TestCase +class ApplicationTest extends TestCase { /** * @var Application From 4f5f466fd84c7508c637576d5c322ac570941306 Mon Sep 17 00:00:00 2001 From: Christian Albrecht Date: Tue, 15 Jun 2021 19:08:45 +0200 Subject: [PATCH 14/34] Fix phpcs Squiz.PHP.DisallowMultipleAssignments --- src/PHPCodeBrowser/View/ViewReview.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/PHPCodeBrowser/View/ViewReview.php b/src/PHPCodeBrowser/View/ViewReview.php index 230b3d0..455b65e 100644 --- a/src/PHPCodeBrowser/View/ViewReview.php +++ b/src/PHPCodeBrowser/View/ViewReview.php @@ -382,17 +382,19 @@ private function formatSourceCode(string $filename, array $outputIssues): string $anchor->setAttribute('name', 'line_'.$lineNumber); $line->appendChild($anchor); + $lineErrorCount = (isset($outputIssues[$lineNumber]) + ? \count($outputIssues[$lineNumber]) + : 0); + // set li css class depending on line errors - switch ($tmp = (isset($outputIssues[$lineNumber]) - ? \count($outputIssues[$lineNumber]) - : 0)) { + switch ($lineErrorCount) { case 0: break; case 1: $lineClasses[] = $outputIssues[$lineNumber][0]->foundBy; break; - case 1 < $tmp: + case 1 < $lineErrorCount: $lineClasses[] = 'moreErrors'; break; From 6322ae8dd0649b3f9e7934c4ee9f4533c5584e50 Mon Sep 17 00:00:00 2001 From: Christian Albrecht Date: Tue, 15 Jun 2021 20:53:00 +0200 Subject: [PATCH 15/34] Disable phpcs unused parameters rule where needed --- src/PHPCodeBrowser/Application.php | 2 ++ src/PHPCodeBrowser/Command/RunCommand.php | 2 ++ src/PHPCodeBrowser/Plugins/ErrorPMD.php | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/PHPCodeBrowser/Application.php b/src/PHPCodeBrowser/Application.php index 7463b97..ad448f4 100644 --- a/src/PHPCodeBrowser/Application.php +++ b/src/PHPCodeBrowser/Application.php @@ -84,6 +84,8 @@ public function getDefinition(): InputDefinition * * @param InputInterface $input * + * @phpcs:disable SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter + * * @return string The command name */ protected function getCommandName(InputInterface $input): string diff --git a/src/PHPCodeBrowser/Command/RunCommand.php b/src/PHPCodeBrowser/Command/RunCommand.php index e81ffc7..246ee3f 100644 --- a/src/PHPCodeBrowser/Command/RunCommand.php +++ b/src/PHPCodeBrowser/Command/RunCommand.php @@ -155,6 +155,8 @@ static function ($class) { * @param InputInterface $input An InputInterface instance * @param OutputInterface $output * + * @phpcs:disable SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter + * * @return int|null null or 0 if everything went fine, or an error code */ protected function execute(InputInterface $input, OutputInterface $output): ?int diff --git a/src/PHPCodeBrowser/Plugins/ErrorPMD.php b/src/PHPCodeBrowser/Plugins/ErrorPMD.php index 4139a8d..37aae4c 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorPMD.php +++ b/src/PHPCodeBrowser/Plugins/ErrorPMD.php @@ -114,6 +114,8 @@ class ErrorPMD extends AbstractPlugin * * @param DOMElement $element * + * @phpcs:disable SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter + * * @return string */ protected function getSeverity(DOMElement $element): string From 61427286469854c2801200e4a13f1fd00f2a6c39 Mon Sep 17 00:00:00 2001 From: Christian Albrecht Date: Tue, 15 Jun 2021 20:46:40 +0200 Subject: [PATCH 16/34] Fix most phpstan errrors regarding DOM* API --- phpstan_baseline.neon | 5 ----- src/PHPCodeBrowser/AbstractPlugin.php | 11 +++++++---- src/PHPCodeBrowser/Plugins/ErrorCPD.php | 19 +++++++++++++------ src/PHPCodeBrowser/Plugins/ErrorCRAP.php | 11 +++++++---- src/PHPCodeBrowser/Plugins/ErrorCoverage.php | 10 +++++++--- src/PHPCodeBrowser/View/ViewReview.php | 5 ++++- 6 files changed, 38 insertions(+), 23 deletions(-) diff --git a/phpstan_baseline.neon b/phpstan_baseline.neon index 401dfb0..4c0ee84 100644 --- a/phpstan_baseline.neon +++ b/phpstan_baseline.neon @@ -1,10 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#" - count: 1 - path: src/PHPCodeBrowser/Plugins/ErrorCPD.php - - message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#" count: 1 diff --git a/src/PHPCodeBrowser/AbstractPlugin.php b/src/PHPCodeBrowser/AbstractPlugin.php index cee48da..c590ea4 100644 --- a/src/PHPCodeBrowser/AbstractPlugin.php +++ b/src/PHPCodeBrowser/AbstractPlugin.php @@ -56,7 +56,6 @@ namespace PHPCodeBrowser; use DOMElement; -use DOMNode; use DOMNodeList; /** @@ -202,6 +201,10 @@ public function getFilesWithIssues(): array ); foreach ($issueNodes as $node) { + if (!($node instanceof DOMElement)) { + continue; + } + $fileNames[] = $node->getAttribute('name'); } @@ -214,12 +217,12 @@ public function getFilesWithIssues(): array * This method provides a default behaviour an can be overloaded to * implement special behavior for other plugins. * - * @param DOMNode $element The XML plugin node with its errors - * @param string $filename Name of the file to return issues for. + * @param DOMElement $element The XML plugin node with its errors + * @param string $filename Name of the file to return issues for. * * @return array array of issue objects. */ - public function mapIssues(DOMNode $element, string $filename): array + public function mapIssues(DOMElement $element, string $filename): array { $errorList = []; diff --git a/src/PHPCodeBrowser/Plugins/ErrorCPD.php b/src/PHPCodeBrowser/Plugins/ErrorCPD.php index e3fb55a..12572f3 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCPD.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCPD.php @@ -56,7 +56,6 @@ namespace PHPCodeBrowser\Plugins; use DOMElement; -use DOMNode; use DOMNodeList; use PHPCodeBrowser\AbstractPlugin; use PHPCodeBrowser\Issue; @@ -89,12 +88,12 @@ class ErrorCPD extends AbstractPlugin /** * Mapper method for this plugin. * - * @param DOMNode $element The XML plugin node with its errors - * @param string $filename + * @param DOMElement $element The XML plugin node with its errors + * @param string $filename * * @return array */ - public function mapIssues(DOMNode $element, string $filename): array + public function mapIssues(DOMElement $element, string $filename): array { $parentNode = $element->parentNode; $files = $this->issueXml->query( @@ -106,6 +105,10 @@ public function mapIssues(DOMNode $element, string $filename): array $result = []; foreach ($files as $file) { + if (!($file instanceof DOMElement)) { + continue; + } + $result[] = new Issue( $file->getAttribute('path'), (int) $file->getAttribute('line'), @@ -132,6 +135,10 @@ public function getFilesWithIssues(): array ); foreach ($nodes as $node) { + if (!($node instanceof DOMElement)) { + continue; + } + $fileNames[] = $node->getAttribute('path'); } @@ -157,11 +164,11 @@ protected function getIssueNodes(string $filename): DOMNodeList * to find duplicates. * * @param DOMNodeList $allNodes - * @param DOMNode $currentNode + * @param DOMElement $currentNode * * @return string */ - protected function getCpdDescription(DOMNodeList $allNodes, DOMNode $currentNode): string + protected function getCpdDescription(DOMNodeList $allNodes, DOMElement $currentNode): string { $source = []; diff --git a/src/PHPCodeBrowser/Plugins/ErrorCRAP.php b/src/PHPCodeBrowser/Plugins/ErrorCRAP.php index 0d38028..801744c 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCRAP.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCRAP.php @@ -55,7 +55,6 @@ namespace PHPCodeBrowser\Plugins; use DOMElement; -use DOMNode; use DOMNodeList; use PHPCodeBrowser\AbstractPlugin; use PHPCodeBrowser\Issue; @@ -116,12 +115,12 @@ class ErrorCRAP extends AbstractPlugin * This method provides a default behaviour an can be overloaded to * implement special behavior for other plugins. * - * @param DOMNode $element The XML plugin node with its errors - * @param string $filename Name of the file to return issues for. + * @param DOMElement $element The XML plugin node with its errors + * @param string $filename Name of the file to return issues for. * * @return array array of issue objects. */ - public function mapIssues(DOMNode $element, string $filename): array + public function mapIssues(DOMElement $element, string $filename): array { $errorList = []; @@ -171,6 +170,10 @@ public function getFilesWithIssues(): array ); foreach ($issueNodes as $node) { + if (!($node instanceof DOMElement)) { + continue; + } + $fileNames[] = $node->getAttribute('name'); } diff --git a/src/PHPCodeBrowser/Plugins/ErrorCoverage.php b/src/PHPCodeBrowser/Plugins/ErrorCoverage.php index 94813d1..fb0fea1 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCoverage.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCoverage.php @@ -118,12 +118,12 @@ class ErrorCoverage extends AbstractPlugin * This method provides a default behaviour an can be overloaded to * implement special behavior for other plugins. * - * @param DOMNode $element The XML plugin node with its errors - * @param string $filename Name of the file to return issues for. + * @param DOMElement $element The XML plugin node with its errors + * @param string $filename Name of the file to return issues for. * * @return array array of issue objects. */ - public function mapIssues(DOMNode $element, string $filename): array + public function mapIssues(DOMElement $element, string $filename): array { $errorList = []; @@ -185,6 +185,10 @@ public function getFilesWithIssues(): array ); foreach ($issueNodes as $node) { + if (!($node instanceof DOMElement)) { + continue; + } + $fileNames[] = $node->getAttribute('name'); } diff --git a/src/PHPCodeBrowser/View/ViewReview.php b/src/PHPCodeBrowser/View/ViewReview.php index 455b65e..6895773 100644 --- a/src/PHPCodeBrowser/View/ViewReview.php +++ b/src/PHPCodeBrowser/View/ViewReview.php @@ -58,6 +58,7 @@ use DOMDocument; use DOMElement; +use DOMText; use DOMXPath; use PHPCodeBrowser\Helper\IOHelper; @@ -217,11 +218,13 @@ protected function highlightPhpCode(string $sourceCode): DOMDocument // iterate through all elements foreach ($sourceElements as $sourceElement) { - if (!$sourceElement instanceof DOMElement) { + if ($sourceElement instanceof DOMText) { $span = $targetDom->createElement('span'); $span->nodeValue = \htmlspecialchars($sourceElement->wholeText); $liElement->appendChild($span); + } + if (!$sourceElement instanceof DOMElement) { continue; } From fb6e08581522bc33e926d63c7f97f14d7c4788b3 Mon Sep 17 00:00:00 2001 From: Christian Albrecht Date: Tue, 15 Jun 2021 19:10:10 +0200 Subject: [PATCH 17/34] Include php80 in github workflow closes GH-74 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c66bdfc..bed05ea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: - php: [php73, php74] + php: [php73, php74, php80] steps: - uses: actions/checkout@v2 From ed9871861d51af948c37d9084c6b3a84e0a6d085 Mon Sep 17 00:00:00 2001 From: Christian Albrecht Date: Tue, 15 Jun 2021 21:36:02 +0200 Subject: [PATCH 18/34] Release 3.0.0 (#75) Support php8 --- box.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/box.json b/box.json index 0c99fa9..bacb97b 100644 --- a/box.json +++ b/box.json @@ -29,5 +29,5 @@ ], "git-commit": "git-commit", "git-version": "git-version", - "output": "phpcb-2.4.0.phar" + "output": "phpcb-3.0.0.phar" } From 80ce9b3ba617f26fb7e5188a25dcf004741409b6 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Tue, 15 Jun 2021 21:55:28 +0200 Subject: [PATCH 19/34] fix super minor nitpicks (#77) * fix super minor nitpicks * Fully update PHPUnit to latest 9.x --- composer.json | 2 +- phpunit.xml.dist | 25 +++++++++++-------- src/PHPCodeBrowser/IssueXML.php | 6 ++--- src/PHPCodeBrowser/SourceHandler.php | 2 +- .../Tests/CLIControllerTest.php | 14 +++++------ .../Tests/Helper/IOHelperTest.php | 4 +-- src/PHPCodeBrowser/View/ViewReview.php | 4 +-- 7 files changed, 30 insertions(+), 27 deletions(-) diff --git a/composer.json b/composer.json index 7240321..c4eb293 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "phploc/phploc": "*", "phpmd/phpmd": "1.5.*||~2.6", "phpstan/phpstan": "^0.12.5", - "phpunit/phpunit": "~8.4||^9.0", + "phpunit/phpunit": "^9.5", "sebastian/phpcpd": "*" }, "autoload": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 422b86d..676ec30 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,4 @@ - @@ -16,19 +17,21 @@ - - + + ./src - - ./src/PHPCodeBrowser/Tests - - - + + + ./src/PHPCodeBrowser/Tests + + + + + - - - + + diff --git a/src/PHPCodeBrowser/IssueXML.php b/src/PHPCodeBrowser/IssueXML.php index f58e1f2..4e9191a 100644 --- a/src/PHPCodeBrowser/IssueXML.php +++ b/src/PHPCodeBrowser/IssueXML.php @@ -178,10 +178,10 @@ public function addXMLFile(DOMDocument $domDocument): void * * @see DOMXPath::query * - * @param string $expression Xpath expression to query for. - * @param DOMNode $contextNode Node to use as context (optional) + * @param string $expression Xpath expression to query for. + * @param DOMNode|null $contextNode Node to use as context (optional) * - * @return DOMNodeList List of all matching nodes. + * @return DOMNodeList List of all matching nodes. */ public function query(string $expression, ?DOMNode $contextNode = null): DOMNodeList { diff --git a/src/PHPCodeBrowser/SourceHandler.php b/src/PHPCodeBrowser/SourceHandler.php index deb3ae1..a9187b0 100644 --- a/src/PHPCodeBrowser/SourceHandler.php +++ b/src/PHPCodeBrowser/SourceHandler.php @@ -131,7 +131,7 @@ public function addPlugin(AbstractPlugin $plugin): void /** * Add source files to the list. * - * @param array|array|\AppendIterator $files The files to add + * @param array|\AppendIterator $files The files to add */ public function addSourceFiles($files): void { diff --git a/src/PHPCodeBrowser/Tests/CLIControllerTest.php b/src/PHPCodeBrowser/Tests/CLIControllerTest.php index 736d53e..e7aa39e 100644 --- a/src/PHPCodeBrowser/Tests/CLIControllerTest.php +++ b/src/PHPCodeBrowser/Tests/CLIControllerTest.php @@ -147,8 +147,8 @@ public function testRunCleansExistingOutputDir(): void $this->controller->run(); $this->assertOutputIsPresent(); - $this->assertDirectoryNotExists(self::$testOutputDir.'/clear-directory'); - $this->assertFileNotExists(self::$testOutputDir.'/clear-file'); + $this->assertDirectoryDoesNotExist(self::$testOutputDir.'/clear-directory'); + $this->assertFileDoesNotExist(self::$testOutputDir.'/clear-file'); } /** @@ -184,10 +184,10 @@ public function testRunExcludingAllSources(): void $this->controller->run(); $this->assertFileExists(self::$testOutputDir.'/index.html'); - $this->assertFileNotExists(self::$testOutputDir.'/Bad.php.html'); - $this->assertFileNotExists(self::$testOutputDir.'/Good.php.html'); - $this->assertDirectoryNotExists(self::$testOutputDir.'/css'); - $this->assertDirectoryNotExists(self::$testOutputDir.'/img'); - $this->assertDirectoryNotExists(self::$testOutputDir.'/js'); + $this->assertFileDoesNotExist(self::$testOutputDir.'/Bad.php.html'); + $this->assertFileDoesNotExist(self::$testOutputDir.'/Good.php.html'); + $this->assertDirectoryDoesNotExist(self::$testOutputDir.'/css'); + $this->assertDirectoryDoesNotExist(self::$testOutputDir.'/img'); + $this->assertDirectoryDoesNotExist(self::$testOutputDir.'/js'); } } diff --git a/src/PHPCodeBrowser/Tests/Helper/IOHelperTest.php b/src/PHPCodeBrowser/Tests/Helper/IOHelperTest.php index 71c9298..0fbb55d 100644 --- a/src/PHPCodeBrowser/Tests/Helper/IOHelperTest.php +++ b/src/PHPCodeBrowser/Tests/Helper/IOHelperTest.php @@ -155,7 +155,7 @@ public function testFileDeletion(): void } $this->ioHelper->deleteFile($filename); - $this->assertFileNotExists($filename); + $this->assertFileDoesNotExist($filename); } /** @@ -174,7 +174,7 @@ public function testDirectoryDeletion(): void \touch($file); $this->ioHelper->deleteDirectory($dir); - $this->assertFileNotExists($dir); + $this->assertFileDoesNotExist($dir); } /** diff --git a/src/PHPCodeBrowser/View/ViewReview.php b/src/PHPCodeBrowser/View/ViewReview.php index 6895773..b1a46dc 100644 --- a/src/PHPCodeBrowser/View/ViewReview.php +++ b/src/PHPCodeBrowser/View/ViewReview.php @@ -337,8 +337,8 @@ private function formatSourceCode(string $filename, array $outputIssues): string foreach ($lines as $line) { /** - * @var DOMElement $line -*/ + * @var DOMElement $line + */ $line = $line; ++$lineNumber; $line->setAttribute('id', 'line_'.$lineNumber); From 016d40c101b516593ffce8ea9dc2628b9939171c Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Mon, 27 Jun 2022 17:46:40 +0200 Subject: [PATCH 20/34] prevent errors on php 8.1 --- composer.json | 7 ++++++- src/PHPCodeBrowser/IssueXML.php | 18 ++---------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index c4eb293..d2b7dbd 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "ext-dom": "*", "monolog/monolog": "~1.7||~2.0", "phpunit/php-file-iterator": "~2.0||^3.0", - "symfony/console": "~3.4||~4.0||~5.0" + "symfony/console": "~3.4||~4.0||~5.0||~6.0" }, "require-dev": { "humbug/box": "^3.13", @@ -63,5 +63,10 @@ "clean": "rm -rf build/logs/* build/code-browser", "browser": "bin/phpcb -l build/logs -o build/code-browser -s src", "phar": "php vendor/bin/box compile" + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/src/PHPCodeBrowser/IssueXML.php b/src/PHPCodeBrowser/IssueXML.php index 4e9191a..8c60339 100644 --- a/src/PHPCodeBrowser/IssueXML.php +++ b/src/PHPCodeBrowser/IssueXML.php @@ -93,22 +93,6 @@ class IssueXML extends DOMDocument */ protected $xpath; - /** - * Do not preserve white spaces. - * - * @see DOMDocument - * - * @var bool - */ - public $preserveWhiteSpace = false; - - /** - * Provide nice output. - * - * @var bool - */ - public $formatOutput = true; - /** * Default constructor * @@ -121,6 +105,8 @@ public function __construct(string $version = '1.0', string $encoding = 'UTF-8') $this->appendChild( $this->createElement('codebrowser') ); + $this->preserveWhiteSpace = false; + $this->formatOutput = true; } /** From 6e0009809a27fad5b0a8680e6200aaa9e74e8890 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Tue, 17 Jan 2023 13:38:22 +0100 Subject: [PATCH 21/34] fix CI closes GH-81 --- .github/workflows/ci.yml | 6 +----- src/PHPCodeBrowser/IssueXML.php | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bed05ea..dbcedc8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,11 +17,7 @@ jobs: # Nix Flakes doesn't work on shallow clones fetch-depth: 0 - - uses: cachix/install-nix-action@v12 - with: - install_url: https://github.com/numtide/nix-flakes-installer/releases/download/nix-2.4pre20201221_9fab14a/install - extra_nix_config: | - experimental-features = nix-command flakes + - uses: cachix/install-nix-action@v18 - name: Cache Composer dependencies uses: actions/cache@v2 diff --git a/src/PHPCodeBrowser/IssueXML.php b/src/PHPCodeBrowser/IssueXML.php index 8c60339..0afd8b0 100644 --- a/src/PHPCodeBrowser/IssueXML.php +++ b/src/PHPCodeBrowser/IssueXML.php @@ -106,7 +106,7 @@ public function __construct(string $version = '1.0', string $encoding = 'UTF-8') $this->createElement('codebrowser') ); $this->preserveWhiteSpace = false; - $this->formatOutput = true; + $this->formatOutput = true; } /** From 1490f3f77cdef66d95253d6e6f80aa242c531b5c Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Tue, 17 Jan 2023 17:45:50 +0100 Subject: [PATCH 22/34] bump Version to 3.0.1 --- bin/phpcb | 2 +- box.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/phpcb b/bin/phpcb index 7ee5aa1..58f5e16 100755 --- a/bin/phpcb +++ b/bin/phpcb @@ -53,5 +53,5 @@ if (file_exists(__DIR__ . '/../../../autoload.php')) { include_once __DIR__ . '/../vendor/autoload.php'; } -$app = new PHPCodeBrowser\Application('PHP_CodeBrowser', '1.1.4'); +$app = new PHPCodeBrowser\Application('PHP_CodeBrowser', '3.0.1'); $app->run(); diff --git a/box.json b/box.json index bacb97b..7de85f9 100644 --- a/box.json +++ b/box.json @@ -29,5 +29,5 @@ ], "git-commit": "git-commit", "git-version": "git-version", - "output": "phpcb-3.0.0.phar" + "output": "phpcb-3.0.1.phar" } From b135a4915381886028a9f5fcfec62cc25ced11b9 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Mon, 23 Jan 2023 11:54:01 +0100 Subject: [PATCH 23/34] fix built phar --- bin/phpcb | 2 +- box.json | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/phpcb b/bin/phpcb index 58f5e16..ef1ac2e 100755 --- a/bin/phpcb +++ b/bin/phpcb @@ -53,5 +53,5 @@ if (file_exists(__DIR__ . '/../../../autoload.php')) { include_once __DIR__ . '/../vendor/autoload.php'; } -$app = new PHPCodeBrowser\Application('PHP_CodeBrowser', '3.0.1'); +$app = new PHPCodeBrowser\Application('PHP_CodeBrowser', '3.0.2'); $app->run(); diff --git a/box.json b/box.json index 7de85f9..cdb4023 100644 --- a/box.json +++ b/box.json @@ -17,7 +17,8 @@ "phpunit/php-file-iterator", "psr/log", "symfony/console", - "symfony/service-contracts" + "symfony/service-contracts", + "symfony/string" ], "notPath": [ "Tests", @@ -29,5 +30,5 @@ ], "git-commit": "git-commit", "git-version": "git-version", - "output": "phpcb-3.0.1.phar" + "output": "phpcb-3.0.2.phar" } From 264d11e902102d83c7c7da1e3d4bd4c61864d3e7 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Mon, 16 Jan 2023 11:19:55 +0100 Subject: [PATCH 24/34] bump version to 4.0.0 --- bin/phpcb | 2 +- box.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/phpcb b/bin/phpcb index ef1ac2e..72ddbe8 100755 --- a/bin/phpcb +++ b/bin/phpcb @@ -53,5 +53,5 @@ if (file_exists(__DIR__ . '/../../../autoload.php')) { include_once __DIR__ . '/../vendor/autoload.php'; } -$app = new PHPCodeBrowser\Application('PHP_CodeBrowser', '3.0.2'); +$app = new PHPCodeBrowser\Application('PHP_CodeBrowser', '4.0.0'); $app->run(); diff --git a/box.json b/box.json index cdb4023..11a976c 100644 --- a/box.json +++ b/box.json @@ -30,5 +30,5 @@ ], "git-commit": "git-commit", "git-version": "git-version", - "output": "phpcb-3.0.2.phar" + "output": "phpcb-4.0.0.phar" } From 3753f2e08cf79aa0b2873d2ba920881d27076e31 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Mon, 16 Jan 2023 11:26:44 +0100 Subject: [PATCH 25/34] drop PHP 7.x --- .github/flake.lock | 11 ++++++----- .github/flake.nix | 6 +++--- .github/workflows/ci.yml | 2 +- composer.json | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/flake.lock b/.github/flake.lock index e112b3c..df035e8 100644 --- a/.github/flake.lock +++ b/.github/flake.lock @@ -2,11 +2,12 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1611219034, - "narHash": "sha256-bgp8G3LcpvKs22/z5Cj4XQkmZq05Aa0vaP1bKl7X0zM=", - "path": "/nix/store/pl5nzbz7s187b7x2scj27b4wpkm1g93h-source", - "rev": "f217c0ea7c148ddc0103347051555c7c252dcafb", - "type": "path" + "lastModified": 1673606088, + "narHash": "sha256-wdYD41UwNwPhTdMaG0AIe7fE1bAdyHe6bB4HLUqUvck=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "37b97ae3dd714de9a17923d004a2c5b5543dfa6d", + "type": "github" }, "original": { "id": "nixpkgs", diff --git a/.github/flake.nix b/.github/flake.nix index 682e70c..9bb3e54 100644 --- a/.github/flake.nix +++ b/.github/flake.nix @@ -18,9 +18,9 @@ }); phpVersions = [ - "php73" - "php74" "php80" + "php81" + "php82" ]; in { @@ -33,7 +33,7 @@ name = "env-${name}"; paths = [ (phpEnv pkgs."${name}") - (phpEnv pkgs."${name}").packages.composer2 + (phpEnv pkgs."${name}").packages.composer ]; }; } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dbcedc8..71a96f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: - php: [php73, php74, php80] + php: [php80, php81, php82] steps: - uses: actions/checkout@v2 diff --git a/composer.json b/composer.json index d2b7dbd..1e56d21 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": "^7.3||^8.0", + "php": "^8.0", "ext-dom": "*", "monolog/monolog": "~1.7||~2.0", "phpunit/php-file-iterator": "~2.0||^3.0", From b31c54a580aa976eae8d9cae7b7771d3f689ad62 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Tue, 17 Jan 2023 12:09:14 +0100 Subject: [PATCH 26/34] update mo4-coding-standard --- composer.json | 6 +- phpcs.xml.dist | 9 +++ src/PHPCodeBrowser/AbstractPlugin.php | 2 +- src/PHPCodeBrowser/Command/RunCommand.php | 1 - src/PHPCodeBrowser/File.php | 4 +- src/PHPCodeBrowser/Issue.php | 60 +++++++++++++++++-- src/PHPCodeBrowser/Plugins/ErrorCPD.php | 2 +- src/PHPCodeBrowser/Plugins/ErrorCRAP.php | 2 +- .../Plugins/ErrorCheckstyle.php | 2 +- src/PHPCodeBrowser/Plugins/ErrorCoverage.php | 2 +- src/PHPCodeBrowser/Plugins/ErrorPMD.php | 2 +- src/PHPCodeBrowser/Plugins/ErrorPadawan.php | 2 +- .../Tests/CLIControllerTest.php | 2 +- src/PHPCodeBrowser/Tests/IssueTest.php | 12 ++-- src/PHPCodeBrowser/View/ViewReview.php | 10 ++-- templates/index.tpl | 4 +- templates/review.tpl | 18 +++--- 17 files changed, 98 insertions(+), 42 deletions(-) create mode 100644 phpcs.xml.dist diff --git a/composer.json b/composer.json index 1e56d21..65c3fb8 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ }, "require-dev": { "humbug/box": "^3.13", - "mayflower/mo4-coding-standard": "^7.0", + "mayflower/mo4-coding-standard": "^9.0", "phploc/phploc": "*", "phpmd/phpmd": "1.5.*||~2.6", "phpstan/phpstan": "^0.12.5", @@ -43,7 +43,7 @@ "php -c php.ini vendor/bin/phpunit -c phpunit.xml.dist", "phpcpd -q --log-pmd=build/logs/pmd-cpd.xml src || true", "phpmd src xml cleancode,codesize,controversial,design,naming,unusedcode --reportfile build/logs/pmd.xml || true", - "phpcs -q --standard=MO4 --report-checkstyle=build/logs/checkstyle.xml src || true", + "phpcs -q --report-checkstyle=build/logs/checkstyle.xml || true", "@browser" ], "nope": [ @@ -56,7 +56,7 @@ "composer update --prefer-dist --no-interaction --no-progress" ], "ci": [ - "phpcs -s --standard=MO4 src/PHPCodeBrowser/", + "phpcs -s", "phpstan analyse --no-progress", "phpunit" ], diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..e8a5c50 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,9 @@ + + + The coding standard. + + src + + + + diff --git a/src/PHPCodeBrowser/AbstractPlugin.php b/src/PHPCodeBrowser/AbstractPlugin.php index c590ea4..ee1028b 100644 --- a/src/PHPCodeBrowser/AbstractPlugin.php +++ b/src/PHPCodeBrowser/AbstractPlugin.php @@ -85,7 +85,7 @@ abstract class AbstractPlugin * * @var string */ - public $pluginName; + protected $pluginName; /** * The IssueXML object diff --git a/src/PHPCodeBrowser/Command/RunCommand.php b/src/PHPCodeBrowser/Command/RunCommand.php index 246ee3f..ea52128 100644 --- a/src/PHPCodeBrowser/Command/RunCommand.php +++ b/src/PHPCodeBrowser/Command/RunCommand.php @@ -87,7 +87,6 @@ static function ($class) { $this->getAvailablePlugins() ); - $this->setName('phpcb') ->setHelp( 'A Code browser for PHP files with syntax highlighting and colored error-sections found by quality assurance tools like PHPUnit, PHPMD or PHP_CodeSniffer.' diff --git a/src/PHPCodeBrowser/File.php b/src/PHPCodeBrowser/File.php index a75ee8a..ce0de35 100644 --- a/src/PHPCodeBrowser/File.php +++ b/src/PHPCodeBrowser/File.php @@ -117,7 +117,7 @@ public function __construct(string $name, array $issues = []) */ public function addIssue(Issue $issue): void { - if ($issue->fileName !== $this->name) { + if ($issue->getFileName() !== $this->name) { throw new \InvalidArgumentException( 'Tried to add issue to wrong file.' ); @@ -186,7 +186,7 @@ public function getErrorCount(): int $count = 0; foreach ($this->issues as $issue) { - if (\strcasecmp($issue->severity, 'error') !== 0) { + if (\strcasecmp($issue->getSeverity(), 'error') !== 0) { continue; } diff --git a/src/PHPCodeBrowser/Issue.php b/src/PHPCodeBrowser/Issue.php index 0f56148..7d58329 100644 --- a/src/PHPCodeBrowser/Issue.php +++ b/src/PHPCodeBrowser/Issue.php @@ -83,21 +83,21 @@ class Issue * * @var string */ - public $fileName; + private $fileName; /** * Starting Line of the Issue. * * @var int */ - public $lineStart; + private $lineStart; /** * Ending Line of the Issue. * * @var int */ - public $lineEnd; + private $lineEnd; /** * Name of the Plugin that found the Issue. @@ -105,21 +105,21 @@ class Issue * * @var string */ - public $foundBy; + private $foundBy; /** * Issue Description text. * * @var string */ - public $description; + private $description; /** * Severity of the issue. * * @var string */ - public $severity; + private $severity; /** * Default constructor @@ -140,4 +140,52 @@ public function __construct(string $fileName, int $lineStart, int $lineEnd, stri $this->description = $description; $this->severity = $severity; } + + /** + * @return string + */ + public function getFileName(): string + { + return $this->fileName; + } + + /** + * @return int + */ + public function getLineStart(): int + { + return $this->lineStart; + } + + /** + * @return int + */ + public function getLineEnd(): int + { + return $this->lineEnd; + } + + /** + * @return string + */ + public function getFoundBy(): string + { + return $this->foundBy; + } + + /** + * @return string + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @return string + */ + public function getSeverity(): string + { + return $this->severity; + } } diff --git a/src/PHPCodeBrowser/Plugins/ErrorCPD.php b/src/PHPCodeBrowser/Plugins/ErrorCPD.php index 12572f3..65a28cb 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCPD.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCPD.php @@ -83,7 +83,7 @@ class ErrorCPD extends AbstractPlugin /** * @var string $pluginName */ - public $pluginName = 'pmd-cpd'; + protected $pluginName = 'pmd-cpd'; /** * Mapper method for this plugin. diff --git a/src/PHPCodeBrowser/Plugins/ErrorCRAP.php b/src/PHPCodeBrowser/Plugins/ErrorCRAP.php index 801744c..53b32fc 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCRAP.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCRAP.php @@ -84,7 +84,7 @@ class ErrorCRAP extends AbstractPlugin * * @var string */ - public $pluginName = 'coverage'; + protected $pluginName = 'coverage'; /** * Name of the attribute that holds the number of the first line diff --git a/src/PHPCodeBrowser/Plugins/ErrorCheckstyle.php b/src/PHPCodeBrowser/Plugins/ErrorCheckstyle.php index dc84b7f..4ed5d45 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCheckstyle.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCheckstyle.php @@ -84,7 +84,7 @@ class ErrorCheckstyle extends AbstractPlugin * * @var string */ - public $pluginName = 'checkstyle'; + protected $pluginName = 'checkstyle'; /** * Name of the attribute that holds the number of the first line diff --git a/src/PHPCodeBrowser/Plugins/ErrorCoverage.php b/src/PHPCodeBrowser/Plugins/ErrorCoverage.php index fb0fea1..f867062 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCoverage.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCoverage.php @@ -87,7 +87,7 @@ class ErrorCoverage extends AbstractPlugin * * @var string */ - public $pluginName = 'coverage'; + protected $pluginName = 'coverage'; /** * Name of the attribute that holds the number of the first line diff --git a/src/PHPCodeBrowser/Plugins/ErrorPMD.php b/src/PHPCodeBrowser/Plugins/ErrorPMD.php index 37aae4c..659c984 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorPMD.php +++ b/src/PHPCodeBrowser/Plugins/ErrorPMD.php @@ -83,7 +83,7 @@ class ErrorPMD extends AbstractPlugin * * @var string */ - public $pluginName = 'pmd'; + protected $pluginName = 'pmd'; /** * Name of the attribute that holds the number of the first line diff --git a/src/PHPCodeBrowser/Plugins/ErrorPadawan.php b/src/PHPCodeBrowser/Plugins/ErrorPadawan.php index c0c2b02..ad83969 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorPadawan.php +++ b/src/PHPCodeBrowser/Plugins/ErrorPadawan.php @@ -83,7 +83,7 @@ class ErrorPadawan extends AbstractPlugin * * @var string */ - public $pluginName = 'padawan'; + protected $pluginName = 'padawan'; /** * Name of the attribute that holds the number of the first line diff --git a/src/PHPCodeBrowser/Tests/CLIControllerTest.php b/src/PHPCodeBrowser/Tests/CLIControllerTest.php index e7aa39e..dd9c0b7 100644 --- a/src/PHPCodeBrowser/Tests/CLIControllerTest.php +++ b/src/PHPCodeBrowser/Tests/CLIControllerTest.php @@ -79,7 +79,7 @@ class CLIControllerTest extends AbstractTestCase /** * @var CLIController $controller */ - public $controller; + private $controller; /** * Create and configure a CLIController instance. diff --git a/src/PHPCodeBrowser/Tests/IssueTest.php b/src/PHPCodeBrowser/Tests/IssueTest.php index 5e46b2f..365ec3f 100644 --- a/src/PHPCodeBrowser/Tests/IssueTest.php +++ b/src/PHPCodeBrowser/Tests/IssueTest.php @@ -115,11 +115,11 @@ protected function tearDown(): void */ public function testInstantiation(): void { - $this->assertSame($this->issue->fileName, 'testFileName'); - $this->assertSame($this->issue->lineStart, 23); - $this->assertSame($this->issue->lineEnd, 27); - $this->assertSame($this->issue->foundBy, 'testFinder'); - $this->assertSame($this->issue->description, 'testDescription'); - $this->assertSame($this->issue->severity, 'notice'); + $this->assertSame($this->issue->getFileName(), 'testFileName'); + $this->assertSame($this->issue->getLineStart(), 23); + $this->assertSame($this->issue->getLineEnd(), 27); + $this->assertSame($this->issue->getFoundBy(), 'testFinder'); + $this->assertSame($this->issue->getDescription(), 'testDescription'); + $this->assertSame($this->issue->getSeverity(), 'notice'); } } diff --git a/src/PHPCodeBrowser/View/ViewReview.php b/src/PHPCodeBrowser/View/ViewReview.php index b1a46dc..aca9b20 100644 --- a/src/PHPCodeBrowser/View/ViewReview.php +++ b/src/PHPCodeBrowser/View/ViewReview.php @@ -359,9 +359,9 @@ private function formatSourceCode(string $filename, array $outputIssues): string
    %s
    ', - $issue->foundBy, - $issue->foundBy, - $issue->description + $issue->getFoundBy(), + $issue->getFoundBy(), + $issue->getDescription() ); } @@ -394,7 +394,7 @@ private function formatSourceCode(string $filename, array $outputIssues): string case 0: break; case 1: - $lineClasses[] = $outputIssues[$lineNumber][0]->foundBy; + $lineClasses[] = $outputIssues[$lineNumber][0]->getFoundBy(); break; case 1 < $lineErrorCount: @@ -429,7 +429,7 @@ private function formatIssues(array $issueList): array $outputIssues = []; foreach ($issueList as $issue) { - for ($i = $issue->lineStart; $i <= $issue->lineEnd; ++$i) { + for ($i = $issue->getLineStart(); $i <= $issue->getLineEnd(); ++$i) { $outputIssues[$i][] = $issue; } } diff --git a/templates/index.tpl b/templates/index.tpl index 7cf59e0..ec719b8 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -52,7 +52,7 @@ $occuringErrorTypes = array ( foreach ($fileList as $file) { /** @var $file PHPCodeBrowser\File */ foreach ($file->getIssues() as $issue) { - $occuringErrorTypes[$issue->foundBy] = true; + $occuringErrorTypes[$issue->getFoundBy()] = true; } } @@ -85,7 +85,7 @@ foreach ($fileList as $filename => $f) { $counts = array_fill_keys($occuringErrorTypes, 0); foreach ($f->getIssues() as $issue) { - $counts[$issue->foundBy] += 1; + $counts[$issue->getFoundBy()] += 1; } echo " " . PHP_EOL; diff --git a/templates/review.tpl b/templates/review.tpl index 4c98bdb..c51b4c8 100644 --- a/templates/review.tpl +++ b/templates/review.tpl @@ -57,24 +57,24 @@ - + - - lineStart; ?> + + getLineStart(); ?> - lineEnd; ?>', {duration: 1.5}); return false"> - lineEnd;?> + getLineEnd(); ?>', {duration: 1.5}); return false"> + getLineEnd();?> - lineEnd; ?>', {duration: 1.5}); return false"> - description;?> + getLineEnd(); ?>', {duration: 1.5}); return false"> + getDescription();?> - foundBy;?> + getFoundBy();?> - severity;?> + getSeverity();?> From c59e7044fac9a9bf916110ec20039454be38664c Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Tue, 17 Jan 2023 12:28:42 +0100 Subject: [PATCH 27/34] update phpstan --- composer.json | 2 +- phpstan.neon | 2 +- phpstan_baseline.neon | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 65c3fb8..3ca29cb 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "mayflower/mo4-coding-standard": "^9.0", "phploc/phploc": "*", "phpmd/phpmd": "1.5.*||~2.6", - "phpstan/phpstan": "^0.12.5", + "phpstan/phpstan": "^1.0", "phpunit/phpunit": "^9.5", "sebastian/phpcpd": "*" }, diff --git a/phpstan.neon b/phpstan.neon index 4a10649..6b5b9b5 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 4 + level: 5 paths: - %rootDir%/../../../src/PHPCodeBrowser diff --git a/phpstan_baseline.neon b/phpstan_baseline.neon index 4c0ee84..8f47def 100644 --- a/phpstan_baseline.neon +++ b/phpstan_baseline.neon @@ -1,7 +1,41 @@ parameters: ignoreErrors: + - + message: "#^Parameter \\#1 \\$element of method PHPCodeBrowser\\\\AbstractPlugin\\:\\:mapIssues\\(\\) expects DOMElement, DOMNode given\\.$#" + count: 1 + path: src/PHPCodeBrowser/AbstractPlugin.php + + - + message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#" + count: 1 + path: src/PHPCodeBrowser/Plugins/ErrorCPD.php + - message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#" count: 1 path: src/PHPCodeBrowser/Plugins/ErrorCoverage.php + - + message: "#^Comparison operation \"\\<\" between 1 and int\\<2, max\\> is always true\\.$#" + count: 1 + path: src/PHPCodeBrowser/View/ViewReview.php + + - + message: "#^Comparison operation \"\\<\\=\" between int\\<32, 255\\> and 55295 is always true\\.$#" + count: 1 + path: src/PHPCodeBrowser/View/ViewReview.php + + - + message: "#^Comparison operation \"\\>\\=\" between int\\<0, 8\\>\\|int\\<11, 12\\>\\|int\\<14, 31\\> and 57344 is always false\\.$#" + count: 1 + path: src/PHPCodeBrowser/View/ViewReview.php + + - + message: "#^Comparison operation \"\\>\\=\" between int\\<0, 8\\>\\|int\\<11, 12\\>\\|int\\<14, 31\\> and 65536 is always false\\.$#" + count: 1 + path: src/PHPCodeBrowser/View/ViewReview.php + + - + message: "#^Result of && is always false\\.$#" + count: 2 + path: src/PHPCodeBrowser/View/ViewReview.php From 9deced37d038506d664e9adc13f171abb99771f6 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Tue, 17 Jan 2023 12:32:04 +0100 Subject: [PATCH 28/34] utf8_encode is deprecated --- src/PHPCodeBrowser/View/ViewReview.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PHPCodeBrowser/View/ViewReview.php b/src/PHPCodeBrowser/View/ViewReview.php index aca9b20..ecf6460 100644 --- a/src/PHPCodeBrowser/View/ViewReview.php +++ b/src/PHPCodeBrowser/View/ViewReview.php @@ -365,7 +365,7 @@ private function formatSourceCode(string $filename, array $outputIssues): string ); } - $line->setAttribute('title', \utf8_encode($message)); + $line->setAttribute('title', $message); } // Add line number From 2314c3c970537b43cdc97c257ec95f1e3a19ba8f Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Tue, 17 Jan 2023 12:42:34 +0100 Subject: [PATCH 29/34] Allow newer monolog --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3ca29cb..3949719 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require": { "php": "^8.0", "ext-dom": "*", - "monolog/monolog": "~1.7||~2.0", + "monolog/monolog": "~1.7||~2.0||~3.0", "phpunit/php-file-iterator": "~2.0||^3.0", "symfony/console": "~3.4||~4.0||~5.0||~6.0" }, From f6aff8de6712f5d2d69d80ab6c01f4248284eaf2 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Wed, 18 Jan 2023 14:22:15 +0100 Subject: [PATCH 30/34] microoptimizations --- src/PHPCodeBrowser/Command/RunCommand.php | 2 +- src/PHPCodeBrowser/File.php | 4 ++-- src/PHPCodeBrowser/Helper/IOHelper.php | 2 +- src/PHPCodeBrowser/Tests/IssueTest.php | 12 ++++++------ src/PHPCodeBrowser/View/ViewAbstract.php | 5 ++--- src/PHPCodeBrowser/View/ViewReview.php | 9 ++------- 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/PHPCodeBrowser/Command/RunCommand.php b/src/PHPCodeBrowser/Command/RunCommand.php index ea52128..cbc7318 100644 --- a/src/PHPCodeBrowser/Command/RunCommand.php +++ b/src/PHPCodeBrowser/Command/RunCommand.php @@ -322,7 +322,7 @@ protected function convertIgnores(array $ignored, array $excludePCRE): array */ private function handleBackwardCompatibility(array $option): array { - if (\count($option) === 1 && \strpos($option[0], ',') !== false) { + if (\count($option) === 1 && \str_contains($option[0], ',')) { $option = \explode(',', $option[0]); \error_log('Usage of comma-separated options is deprecated, specify them one-by-one.', E_DEPRECATED); } diff --git a/src/PHPCodeBrowser/File.php b/src/PHPCodeBrowser/File.php index ce0de35..46da426 100644 --- a/src/PHPCodeBrowser/File.php +++ b/src/PHPCodeBrowser/File.php @@ -253,8 +253,8 @@ protected static function internalSort(File $first, File $second): int $firstSubName = \substr($firstName, $prefixLength); $secondSubName = \substr($secondName, $prefixLength); - $firstIsInSubDir = (\substr_count($firstSubName, DIRECTORY_SEPARATOR) !== 0); - $secondIsInSubDir = (\substr_count($secondSubName, DIRECTORY_SEPARATOR) !== 0); + $firstIsInSubDir = (\str_contains($firstSubName, DIRECTORY_SEPARATOR)); + $secondIsInSubDir = (\str_contains($secondSubName, DIRECTORY_SEPARATOR)); if ($firstIsInSubDir) { return $secondIsInSubDir ? \strcmp($firstSubName, $secondSubName) : -1; diff --git a/src/PHPCodeBrowser/Helper/IOHelper.php b/src/PHPCodeBrowser/Helper/IOHelper.php index 108c09c..e794a25 100644 --- a/src/PHPCodeBrowser/Helper/IOHelper.php +++ b/src/PHPCodeBrowser/Helper/IOHelper.php @@ -293,7 +293,7 @@ public static function getCommonPathPrefix(array $fileNames): string */ protected static function getCurrentCommonPathPrefix(string $currentPrefix, string $path): string { - if (0 === \strpos($path, $currentPrefix.DIRECTORY_SEPARATOR) + if (\str_starts_with($path, $currentPrefix.DIRECTORY_SEPARATOR) || DIRECTORY_SEPARATOR === $currentPrefix || '' === $currentPrefix || '.' === $currentPrefix diff --git a/src/PHPCodeBrowser/Tests/IssueTest.php b/src/PHPCodeBrowser/Tests/IssueTest.php index 365ec3f..e6dce6a 100644 --- a/src/PHPCodeBrowser/Tests/IssueTest.php +++ b/src/PHPCodeBrowser/Tests/IssueTest.php @@ -115,11 +115,11 @@ protected function tearDown(): void */ public function testInstantiation(): void { - $this->assertSame($this->issue->getFileName(), 'testFileName'); - $this->assertSame($this->issue->getLineStart(), 23); - $this->assertSame($this->issue->getLineEnd(), 27); - $this->assertSame($this->issue->getFoundBy(), 'testFinder'); - $this->assertSame($this->issue->getDescription(), 'testDescription'); - $this->assertSame($this->issue->getSeverity(), 'notice'); + $this->assertSame('testFileName', $this->issue->getFileName()); + $this->assertSame(23, $this->issue->getLineStart()); + $this->assertSame(27, $this->issue->getLineEnd()); + $this->assertSame('testFinder', $this->issue->getFoundBy()); + $this->assertSame('testDescription', $this->issue->getDescription()); + $this->assertSame('notice', $this->issue->getSeverity()); } } diff --git a/src/PHPCodeBrowser/View/ViewAbstract.php b/src/PHPCodeBrowser/View/ViewAbstract.php index c41f3a7..e5404e8 100644 --- a/src/PHPCodeBrowser/View/ViewAbstract.php +++ b/src/PHPCodeBrowser/View/ViewAbstract.php @@ -242,7 +242,7 @@ protected function getTreeListHtml(array $fileList, string $hrefPrefix = ''): st $dir = \dirname($name).DIRECTORY_SEPARATOR; // Go back until the file is somewhere below curDir - while (\strpos($dir, $curDir) !== 0) { + while (!\str_starts_with($dir, $curDir)) { // chop off one subDir from $curDir $curDir = \substr( $curDir, @@ -347,8 +347,7 @@ protected function render(string $templateName, array $data): string \ob_start(); include $filePath; - $contents = \ob_get_contents(); - \ob_end_clean(); + $contents = \ob_get_clean(); return $contents; } diff --git a/src/PHPCodeBrowser/View/ViewReview.php b/src/PHPCodeBrowser/View/ViewReview.php index ecf6460..2d8c862 100644 --- a/src/PHPCodeBrowser/View/ViewReview.php +++ b/src/PHPCodeBrowser/View/ViewReview.php @@ -155,7 +155,7 @@ public function generate(array $issueList, string $fileName, string $commonPathP $data['source'] = $this->formatSourceCode($fileName, $issues); $depth = \substr_count($shortFilename, DIRECTORY_SEPARATOR); - $data['csspath'] = \str_repeat('../', $depth - 1 >= 0 ? $depth - 1 : 0); + $data['csspath'] = \str_repeat('../', \max($depth - 1, 0)); //we want to exclude files without issues and there are no issues in this one if ($excludeOK && !$data['issues']) { @@ -294,12 +294,7 @@ protected function highlightCode(string $file): DOMDocument return $this->highlightPhpCode($sourceCode); } - $sourceCode = \preg_replace( - '/^.*$/m', - '
  • $0
  • ', - \htmlentities($sourceCode) - ); - $sourceCode = \preg_replace('/ /', ' ', $sourceCode); + $sourceCode = \preg_replace(['/^.*$/m', '/ /'], ['
  • $0
  • ', ' '], \htmlentities($sourceCode)); $sourceCode = '
      '.$sourceCode.'
    '; $sourceCode = $this->stripInvalidXml($sourceCode); From 27e064d3e1f9da3d516e29a0196cd254d3dd796d Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Mon, 30 Jan 2023 12:20:41 +0100 Subject: [PATCH 31/34] use ENT_COMPAT, which was default up to PHP 8.0 --- src/PHPCodeBrowser/AbstractPlugin.php | 4 ++-- src/PHPCodeBrowser/Plugins/ErrorCPD.php | 4 +--- src/PHPCodeBrowser/Plugins/ErrorPMD.php | 2 +- src/PHPCodeBrowser/View/ViewReview.php | 6 +++--- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/PHPCodeBrowser/AbstractPlugin.php b/src/PHPCodeBrowser/AbstractPlugin.php index ee1028b..ce61c83 100644 --- a/src/PHPCodeBrowser/AbstractPlugin.php +++ b/src/PHPCodeBrowser/AbstractPlugin.php @@ -309,7 +309,7 @@ protected function getSource(): string */ protected function getDescription(DOMElement $element): string { - return \htmlentities($element->getAttribute($this->descriptionAttr)); + return \htmlentities($element->getAttribute($this->descriptionAttr), ENT_COMPAT); } /** @@ -323,6 +323,6 @@ protected function getDescription(DOMElement $element): string */ protected function getSeverity(DOMElement $element): string { - return \htmlentities($element->getAttribute($this->severityAttr)); + return \htmlentities($element->getAttribute($this->severityAttr), ENT_COMPAT); } } diff --git a/src/PHPCodeBrowser/Plugins/ErrorCPD.php b/src/PHPCodeBrowser/Plugins/ErrorCPD.php index 65a28cb..3376b18 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCPD.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCPD.php @@ -114,9 +114,7 @@ public function mapIssues(DOMElement $element, string $filename): array (int) $file->getAttribute('line'), (int) $file->getAttribute('line') + $lineCount, 'Duplication', - \htmlentities( - $this->getCpdDescription($parentNode->childNodes, $file) - ), + \htmlentities($this->getCpdDescription($parentNode->childNodes, $file), ENT_COMPAT), 'notice' ); } diff --git a/src/PHPCodeBrowser/Plugins/ErrorPMD.php b/src/PHPCodeBrowser/Plugins/ErrorPMD.php index 659c984..dbb645e 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorPMD.php +++ b/src/PHPCodeBrowser/Plugins/ErrorPMD.php @@ -136,7 +136,7 @@ protected function getDescription(DOMElement $element): string return \str_replace( ' ', '', - \htmlentities($element->textContent) + \htmlentities($element->textContent, ENT_COMPAT) ); } } diff --git a/src/PHPCodeBrowser/View/ViewReview.php b/src/PHPCodeBrowser/View/ViewReview.php index 2d8c862..f168042 100644 --- a/src/PHPCodeBrowser/View/ViewReview.php +++ b/src/PHPCodeBrowser/View/ViewReview.php @@ -220,7 +220,7 @@ protected function highlightPhpCode(string $sourceCode): DOMDocument foreach ($sourceElements as $sourceElement) { if ($sourceElement instanceof DOMText) { $span = $targetDom->createElement('span'); - $span->nodeValue = \htmlspecialchars($sourceElement->wholeText); + $span->nodeValue = \htmlspecialchars($sourceElement->wholeText, ENT_COMPAT); $liElement->appendChild($span); } @@ -250,7 +250,7 @@ protected function highlightPhpCode(string $sourceCode): DOMDocument } else { // append content to current li element $span = $targetDom->createElement('span'); - $span->nodeValue = \htmlspecialchars($sourceChildElement->textContent); + $span->nodeValue = \htmlspecialchars($sourceChildElement->textContent, ENT_COMPAT); $span->setAttribute('class', $elementClass); $liElement->appendChild($span); } @@ -294,7 +294,7 @@ protected function highlightCode(string $file): DOMDocument return $this->highlightPhpCode($sourceCode); } - $sourceCode = \preg_replace(['/^.*$/m', '/ /'], ['
  • $0
  • ', ' '], \htmlentities($sourceCode)); + $sourceCode = \preg_replace(['/^.*$/m', '/ /'], ['
  • $0
  • ', ' '], \htmlentities($sourceCode, ENT_COMPAT)); $sourceCode = '
      '.$sourceCode.'
    '; $sourceCode = $this->stripInvalidXml($sourceCode); From 3824d02c4fb8a3aff18ccc451655c2a02f8229b6 Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Wed, 5 Apr 2023 12:11:46 +0200 Subject: [PATCH 32/34] add phpstan-strict-rules --- composer.json | 10 +++- phpstan_baseline.neon | 57 +++++++++++++++++-- src/PHPCodeBrowser/AbstractPlugin.php | 8 +-- src/PHPCodeBrowser/CLIController.php | 3 +- src/PHPCodeBrowser/Command/RunCommand.php | 6 +- src/PHPCodeBrowser/Helper/IOHelper.php | 8 +-- src/PHPCodeBrowser/Plugins/ErrorCPD.php | 9 +-- src/PHPCodeBrowser/Plugins/ErrorCRAP.php | 8 +-- src/PHPCodeBrowser/Plugins/ErrorCoverage.php | 9 +-- src/PHPCodeBrowser/SourceHandler.php | 2 +- src/PHPCodeBrowser/Tests/ApplicationTest.php | 4 +- .../Tests/CLIControllerTest.php | 16 +++--- src/PHPCodeBrowser/Tests/FileTest.php | 52 +++++++---------- .../Tests/Helper/IOHelperTest.php | 26 ++++----- src/PHPCodeBrowser/Tests/IssueTest.php | 12 ++-- .../Tests/Plugins/ErrorCPDTest.php | 2 +- .../Tests/Plugins/ErrorCRAPTest.php | 4 +- .../Tests/Plugins/ErrorCheckstyleTest.php | 2 +- .../Tests/Plugins/ErrorCoverageTest.php | 2 +- .../Tests/Plugins/ErrorPMDTest.php | 2 +- .../Tests/SourceHandlerTest.php | 37 +++++------- .../Tests/View/ViewReviewTest.php | 50 ++++++++-------- src/PHPCodeBrowser/View/ViewReview.php | 8 +-- 23 files changed, 186 insertions(+), 151 deletions(-) diff --git a/composer.json b/composer.json index 3949719..8369bbd 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,10 @@ "phpmd/phpmd": "1.5.*||~2.6", "phpstan/phpstan": "^1.0", "phpunit/phpunit": "^9.5", - "sebastian/phpcpd": "*" + "sebastian/phpcpd": "*", + "phpstan/phpstan-strict-rules": "^1.5", + "phpstan/extension-installer": "^1.2", + "phpstan/phpstan-phpunit": "^1.3" }, "autoload": { "psr-0": {"PHPCodeBrowser\\": "src/"} @@ -41,7 +44,7 @@ "demo": [ "@clean", "php -c php.ini vendor/bin/phpunit -c phpunit.xml.dist", - "phpcpd -q --log-pmd=build/logs/pmd-cpd.xml src || true", + "phpcpd --log-pmd=build/logs/pmd-cpd.xml src || true", "phpmd src xml cleancode,codesize,controversial,design,naming,unusedcode --reportfile build/logs/pmd.xml || true", "phpcs -q --report-checkstyle=build/logs/checkstyle.xml || true", "@browser" @@ -66,7 +69,8 @@ }, "config": { "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true } } } diff --git a/phpstan_baseline.neon b/phpstan_baseline.neon index 8f47def..38cd3fa 100644 --- a/phpstan_baseline.neon +++ b/phpstan_baseline.neon @@ -1,19 +1,49 @@ parameters: ignoreErrors: - - message: "#^Parameter \\#1 \\$element of method PHPCodeBrowser\\\\AbstractPlugin\\:\\:mapIssues\\(\\) expects DOMElement, DOMNode given\\.$#" + message: "#^Only booleans are allowed in a negated boolean, array\\ given\\.$#" count: 1 - path: src/PHPCodeBrowser/AbstractPlugin.php + path: src/PHPCodeBrowser/CLIController.php - - message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#" + message: "#^Only booleans are allowed in a negated boolean, mixed given\\.$#" + count: 4 + path: src/PHPCodeBrowser/Command/RunCommand.php + + - + message: "#^Only booleans are allowed in an if condition, mixed given\\.$#" + count: 1 + path: src/PHPCodeBrowser/Command/RunCommand.php + + - + message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" + count: 2 + path: src/PHPCodeBrowser/Helper/IOHelper.php + + - + message: "#^Only booleans are allowed in a ternary operator condition, DOMNode\\|null given\\.$#" count: 1 - path: src/PHPCodeBrowser/Plugins/ErrorCPD.php + path: src/PHPCodeBrowser/IssueXML.php - - message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#" + message: "#^Only booleans are allowed in an if condition, mixed given\\.$#" count: 1 - path: src/PHPCodeBrowser/Plugins/ErrorCoverage.php + path: src/PHPCodeBrowser/IssueXML.php + + - + message: "#^Only booleans are allowed in a negated boolean, string given\\.$#" + count: 1 + path: src/PHPCodeBrowser/Plugins/ErrorCRAP.php + + - + message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" + count: 1 + path: src/PHPCodeBrowser/View/ViewAbstract.php + + - + message: "#^Only booleans are allowed in a negated boolean, string given\\.$#" + count: 2 + path: src/PHPCodeBrowser/View/ViewAbstract.php - message: "#^Comparison operation \"\\<\" between 1 and int\\<2, max\\> is always true\\.$#" @@ -35,7 +65,22 @@ parameters: count: 1 path: src/PHPCodeBrowser/View/ViewReview.php + - + message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" + count: 1 + path: src/PHPCodeBrowser/View/ViewReview.php + + - + message: "#^Only booleans are allowed in a negated boolean, array given\\.$#" + count: 1 + path: src/PHPCodeBrowser/View/ViewReview.php + - message: "#^Result of && is always false\\.$#" count: 2 path: src/PHPCodeBrowser/View/ViewReview.php + + - + message: "#^Switch condition type \\(int\\<0, max\\>\\) does not match case condition 1 \\< \\$lineErrorCount \\(bool\\)\\.$#" + count: 1 + path: src/PHPCodeBrowser/View/ViewReview.php diff --git a/src/PHPCodeBrowser/AbstractPlugin.php b/src/PHPCodeBrowser/AbstractPlugin.php index ce61c83..89c3ad9 100644 --- a/src/PHPCodeBrowser/AbstractPlugin.php +++ b/src/PHPCodeBrowser/AbstractPlugin.php @@ -217,12 +217,12 @@ public function getFilesWithIssues(): array * This method provides a default behaviour an can be overloaded to * implement special behavior for other plugins. * - * @param DOMElement $element The XML plugin node with its errors - * @param string $filename Name of the file to return issues for. + * @param \DOMNode $element The XML plugin node with its errors + * @param string $filename Name of the file to return issues for. * - * @return array array of issue objects. + * @return array */ - public function mapIssues(DOMElement $element, string $filename): array + public function mapIssues(\DOMNode $element, string $filename): array { $errorList = []; diff --git a/src/PHPCodeBrowser/CLIController.php b/src/PHPCodeBrowser/CLIController.php index a8c1ad4..ed909b8 100644 --- a/src/PHPCodeBrowser/CLIController.php +++ b/src/PHPCodeBrowser/CLIController.php @@ -239,7 +239,7 @@ public function run(): void // init needed classes $viewReview = new ViewReview( - \getenv('PHPCB_TEMPLATE_DIR') ?: \dirname(__FILE__, 3).'/templates', + \getenv('PHPCB_TEMPLATE_DIR') ? \getenv('PHPCB_TEMPLATE_DIR') : \dirname(__FILE__, 3).'/templates', $this->htmlOutputDir, $this->ioHelper, $this->phpSuffixes @@ -255,6 +255,7 @@ public function run(): void // conversion of XML file cc to cb format foreach ($this->registeredPlugins as $className) { + /** @var AbstractPlugin $plugin */ $plugin = \array_key_exists($className, $this->pluginOptions) ? new $className( $issueXml, $this->pluginOptions[$className] diff --git a/src/PHPCodeBrowser/Command/RunCommand.php b/src/PHPCodeBrowser/Command/RunCommand.php index cbc7318..abb1008 100644 --- a/src/PHPCodeBrowser/Command/RunCommand.php +++ b/src/PHPCodeBrowser/Command/RunCommand.php @@ -156,9 +156,9 @@ static function ($class) { * * @phpcs:disable SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter * - * @return int|null null or 0 if everything went fine, or an error code + * @return int 0 if everything went fine, or an error code */ - protected function execute(InputInterface $input, OutputInterface $output): ?int + protected function execute(InputInterface $input, OutputInterface $output): int { $this->checkErrors($input); @@ -276,7 +276,7 @@ protected function disablePlugins(array $disabledPlugins, array $plugins): array foreach ($plugins as $pluginKey => $plugin) { $name = \substr($plugin, \strlen('Error')); - if (!\in_array(\strtolower($name), $disabledPlugins)) { + if (!\in_array(\strtolower($name), $disabledPlugins, true)) { continue; } diff --git a/src/PHPCodeBrowser/Helper/IOHelper.php b/src/PHPCodeBrowser/Helper/IOHelper.php index e794a25..a18c0ad 100644 --- a/src/PHPCodeBrowser/Helper/IOHelper.php +++ b/src/PHPCodeBrowser/Helper/IOHelper.php @@ -222,13 +222,12 @@ public function deleteDirectory(string $source): void /** * Copy a directory within all its items. * - * @param string $source The source directory - * @param string $target The target to create - * @param array $exclude List of files / folders that should not be copyed + * @param string $source The source directory + * @param string $target The target to create * * @return void */ - public function copyDirectory(string $source, string $target, array $exclude = []): void + public function copyDirectory(string $source, string $target): void { // first check for target itself $this->createDirectory($target); @@ -245,7 +244,6 @@ public function copyDirectory(string $source, string $target, array $exclude = [ // create folder recursive if (!$iterator->isDot() && $iterator->isDir() - && !\in_array($item, $exclude) ) { $this->copyDirectory( $source.'/'.$item, diff --git a/src/PHPCodeBrowser/Plugins/ErrorCPD.php b/src/PHPCodeBrowser/Plugins/ErrorCPD.php index 3376b18..6aa4a3a 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCPD.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCPD.php @@ -88,13 +88,14 @@ class ErrorCPD extends AbstractPlugin /** * Mapper method for this plugin. * - * @param DOMElement $element The XML plugin node with its errors - * @param string $filename + * @param \DOMNode $element The XML plugin node with its errors + * @param string $filename * - * @return array + * @return array */ - public function mapIssues(DOMElement $element, string $filename): array + public function mapIssues(\DOMNode $element, string $filename): array { + /** @var DOMElement $parentNode */ $parentNode = $element->parentNode; $files = $this->issueXml->query( 'file[@path="'.$filename.'"]', diff --git a/src/PHPCodeBrowser/Plugins/ErrorCRAP.php b/src/PHPCodeBrowser/Plugins/ErrorCRAP.php index 53b32fc..a85b3c8 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCRAP.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCRAP.php @@ -115,12 +115,12 @@ class ErrorCRAP extends AbstractPlugin * This method provides a default behaviour an can be overloaded to * implement special behavior for other plugins. * - * @param DOMElement $element The XML plugin node with its errors - * @param string $filename Name of the file to return issues for. + * @param \DOMNode $element The XML plugin node with its errors + * @param string $filename Name of the file to return issues for. * - * @return array array of issue objects. + * @return array */ - public function mapIssues(DOMElement $element, string $filename): array + public function mapIssues(\DOMNode $element, string $filename): array { $errorList = []; diff --git a/src/PHPCodeBrowser/Plugins/ErrorCoverage.php b/src/PHPCodeBrowser/Plugins/ErrorCoverage.php index f867062..f417d45 100644 --- a/src/PHPCodeBrowser/Plugins/ErrorCoverage.php +++ b/src/PHPCodeBrowser/Plugins/ErrorCoverage.php @@ -118,12 +118,12 @@ class ErrorCoverage extends AbstractPlugin * This method provides a default behaviour an can be overloaded to * implement special behavior for other plugins. * - * @param DOMElement $element The XML plugin node with its errors - * @param string $filename Name of the file to return issues for. + * @param DOMNode $element The XML plugin node with its errors + * @param string $filename Name of the file to return issues for. * - * @return array array of issue objects. + * @return array */ - public function mapIssues(DOMElement $element, string $filename): array + public function mapIssues(DOMNode $element, string $filename): array { $errorList = []; @@ -131,6 +131,7 @@ public function mapIssues(DOMElement $element, string $filename): array $childCount = $children->length; for ($next = 0; $next < $childCount; ++$next) { + /** @var DOMElement $child */ $child = $children->item($next); if (!$this->representsUncoveredLOC($child)) { diff --git a/src/PHPCodeBrowser/SourceHandler.php b/src/PHPCodeBrowser/SourceHandler.php index a9187b0..faf0187 100644 --- a/src/PHPCodeBrowser/SourceHandler.php +++ b/src/PHPCodeBrowser/SourceHandler.php @@ -153,7 +153,7 @@ public function addSourceFile($file): void $filename = $file; $file = \realpath($file); } else { - $filename = $file->getPathName(); + $filename = $file->getPathname(); $file = $file->getRealPath(); } diff --git a/src/PHPCodeBrowser/Tests/ApplicationTest.php b/src/PHPCodeBrowser/Tests/ApplicationTest.php index 8873345..591e1a2 100644 --- a/src/PHPCodeBrowser/Tests/ApplicationTest.php +++ b/src/PHPCodeBrowser/Tests/ApplicationTest.php @@ -30,7 +30,7 @@ protected function setUp(): void */ public function testCommand(): void { - $this->assertInstanceOf(RunCommand::class, $this->application->get('phpcb')); + static::assertInstanceOf(RunCommand::class, $this->application->get('phpcb')); } /** @@ -40,6 +40,6 @@ public function testGetDefinitionClearsArguments(): void { $this->application->getDefinition()->setArguments([new InputArgument('foo')]); - $this->assertEquals(0, $this->application->getDefinition()->getArgumentCount()); + static::assertEquals(0, $this->application->getDefinition()->getArgumentCount()); } } diff --git a/src/PHPCodeBrowser/Tests/CLIControllerTest.php b/src/PHPCodeBrowser/Tests/CLIControllerTest.php index dd9c0b7..32f2ea9 100644 --- a/src/PHPCodeBrowser/Tests/CLIControllerTest.php +++ b/src/PHPCodeBrowser/Tests/CLIControllerTest.php @@ -147,8 +147,8 @@ public function testRunCleansExistingOutputDir(): void $this->controller->run(); $this->assertOutputIsPresent(); - $this->assertDirectoryDoesNotExist(self::$testOutputDir.'/clear-directory'); - $this->assertFileDoesNotExist(self::$testOutputDir.'/clear-file'); + static::assertDirectoryDoesNotExist(self::$testOutputDir.'/clear-directory'); + static::assertFileDoesNotExist(self::$testOutputDir.'/clear-file'); } /** @@ -183,11 +183,11 @@ public function testRunExcludingAllSources(): void $this->controller->run(); - $this->assertFileExists(self::$testOutputDir.'/index.html'); - $this->assertFileDoesNotExist(self::$testOutputDir.'/Bad.php.html'); - $this->assertFileDoesNotExist(self::$testOutputDir.'/Good.php.html'); - $this->assertDirectoryDoesNotExist(self::$testOutputDir.'/css'); - $this->assertDirectoryDoesNotExist(self::$testOutputDir.'/img'); - $this->assertDirectoryDoesNotExist(self::$testOutputDir.'/js'); + static::assertFileExists(self::$testOutputDir.'/index.html'); + static::assertFileDoesNotExist(self::$testOutputDir.'/Bad.php.html'); + static::assertFileDoesNotExist(self::$testOutputDir.'/Good.php.html'); + static::assertDirectoryDoesNotExist(self::$testOutputDir.'/css'); + static::assertDirectoryDoesNotExist(self::$testOutputDir.'/img'); + static::assertDirectoryDoesNotExist(self::$testOutputDir.'/js'); } } diff --git a/src/PHPCodeBrowser/Tests/FileTest.php b/src/PHPCodeBrowser/Tests/FileTest.php index 7376c0c..d0768f5 100644 --- a/src/PHPCodeBrowser/Tests/FileTest.php +++ b/src/PHPCodeBrowser/Tests/FileTest.php @@ -88,19 +88,6 @@ class FileTest extends AbstractTestCase */ protected $issues; - /** - * Constructor. Initialize some values. - */ - public function __construct() - { - parent::__construct(); - $this->issues = [ - new Issue('/some/file/name.php', 39, 39, 'Checkstyle', 'm3', 'error'), - new Issue('/some/file/name.php', 50, 52, 'Checkstyle', 'm4', 'warning'), - new Issue('/some/file/name.php', 40, 40, 'Checkstyle', 'm4', 'error'), - ]; - } - /** * (non-PHPDoc) * @@ -109,7 +96,12 @@ public function __construct() protected function setUp(): void { parent::setUp(); - $this->file = new File('/some/file/name.php'); + $this->issues = [ + new Issue('/some/file/name.php', 39, 39, 'Checkstyle', 'm3', 'error'), + new Issue('/some/file/name.php', 50, 52, 'Checkstyle', 'm4', 'warning'), + new Issue('/some/file/name.php', 40, 40, 'Checkstyle', 'm4', 'error'), + ]; + $this->file = new File('/some/file/name.php'); } /** @@ -119,12 +111,12 @@ protected function setUp(): void */ public function testInstantiation(): void { - $this->assertEquals('/some/file/name.php', $this->file->name()); + static::assertEquals('/some/file/name.php', $this->file->name()); $this->file = new File('/some/file/name.php', $this->issues); - $this->assertEquals('/some/file/name.php', $this->file->name()); - $this->assertEquals($this->issues, $this->file->getIssues()); + static::assertEquals('/some/file/name.php', $this->file->name()); + static::assertEquals($this->issues, $this->file->getIssues()); } /** @@ -135,7 +127,7 @@ public function testInstantiation(): void public function testIssueAdding(): void { $this->file->addIssue($this->issues[0]); - $this->assertEquals( + static::assertEquals( [$this->issues[0]], $this->file->getIssues() ); @@ -161,7 +153,7 @@ public function testAddingIssueToWrongFile(): void */ public function testBasename(): void { - $this->assertEquals('name.php', $this->file->basename()); + static::assertEquals('name.php', $this->file->basename()); } /** @@ -171,7 +163,7 @@ public function testBasename(): void */ public function testDirName(): void { - $this->assertEquals('/some/file', $this->file->dirName()); + static::assertEquals('/some/file', $this->file->dirName()); } /** @@ -181,19 +173,19 @@ public function testDirName(): void */ public function testIssueCount(): void { - $this->assertEquals(0, $this->file->getIssueCount()); + static::assertEquals(0, $this->file->getIssueCount()); $this->file->addIssue($this->issues[0]); - $this->assertEquals(1, $this->file->getIssueCount()); + static::assertEquals(1, $this->file->getIssueCount()); $this->file = new File( '/some/file/name.php', [$this->issues[0]] ); - $this->assertEquals(1, $this->file->getIssueCount()); + static::assertEquals(1, $this->file->getIssueCount()); $this->file->addIssue($this->issues[1]); - $this->assertEquals(2, $this->file->getIssueCount()); + static::assertEquals(2, $this->file->getIssueCount()); } /** @@ -204,7 +196,7 @@ public function testIssueCount(): void public function testErrorCount(): void { $this->file = new File('/some/file/name.php', $this->issues); - $this->assertEquals(2, $this->file->getErrorCount()); + static::assertEquals(2, $this->file->getErrorCount()); } /** @@ -215,7 +207,7 @@ public function testErrorCount(): void public function testEarningCount(): void { $this->file = new File('/some/file/name.php', $this->issues); - $this->assertEquals(1, $this->file->getWarningCount()); + static::assertEquals(1, $this->file->getWarningCount()); } /** @@ -235,9 +227,9 @@ public function testMergeWith(): void ); $this->file->mergeWith($otherFile); - $this->assertEquals(2, $this->file->getErrorCount()); - $this->assertEquals(1, $this->file->getWarningCount()); - $this->assertEquals( + static::assertEquals(2, $this->file->getErrorCount()); + static::assertEquals(1, $this->file->getWarningCount()); + static::assertEquals( \array_values($this->issues), \array_values($this->file->getIssues()) ); @@ -304,6 +296,6 @@ public function testSort(): void File::sort($mixed); $mixed = \array_values($mixed); - $this->assertEquals($sorted, $mixed); + static::assertEquals($sorted, $mixed); } } diff --git a/src/PHPCodeBrowser/Tests/Helper/IOHelperTest.php b/src/PHPCodeBrowser/Tests/Helper/IOHelperTest.php index 0fbb55d..fb4b1c6 100644 --- a/src/PHPCodeBrowser/Tests/Helper/IOHelperTest.php +++ b/src/PHPCodeBrowser/Tests/Helper/IOHelperTest.php @@ -108,8 +108,8 @@ public function testFileCreation(): void } $this->ioHelper->createFile($filename, $content); - $this->assertFileExists($filename); - $this->assertEquals($content, \file_get_contents($filename)); + static::assertFileExists($filename); + static::assertEquals($content, \file_get_contents($filename)); \unlink($filename); } @@ -133,9 +133,9 @@ public function testCreationOfFileWithPath(): void } $this->ioHelper->createFile($filename, $content); - $this->assertFileExists($dirName); - $this->assertFileExists($filename); - $this->assertEquals($content, \file_get_contents($filename)); + static::assertFileExists($dirName); + static::assertFileExists($filename); + static::assertEquals($content, \file_get_contents($filename)); \unlink($filename); \rmdir($dirName); @@ -155,7 +155,7 @@ public function testFileDeletion(): void } $this->ioHelper->deleteFile($filename); - $this->assertFileDoesNotExist($filename); + static::assertFileDoesNotExist($filename); } /** @@ -174,7 +174,7 @@ public function testDirectoryDeletion(): void \touch($file); $this->ioHelper->deleteDirectory($dir); - $this->assertFileDoesNotExist($dir); + static::assertFileDoesNotExist($dir); } /** @@ -200,11 +200,11 @@ public function testCopyFile(): void \file_put_contents($srcFile, $content); $this->ioHelper->copyFile($srcFile, $dstDir); - $this->assertFileExists($srcFile); - $this->assertFileExists($dstDir); - $this->assertFileExists($dstFile); - $this->assertEquals($content, \file_get_contents($dstFile)); - $this->assertEquals($content, \file_get_contents($srcFile)); + static::assertFileExists($srcFile); + static::assertFileExists($dstDir); + static::assertFileExists($dstFile); + static::assertEquals($content, \file_get_contents($dstFile)); + static::assertEquals($content, \file_get_contents($srcFile)); \unlink($dstFile); \rmdir($dstDir); @@ -255,7 +255,7 @@ public function testCopyFileNonExisting(): void */ public function testGetCommonPathPrefixForNoFiles(): void { - $this->assertEquals( + static::assertEquals( '/', $this->ioHelper::getCommonPathPrefix([]) ); diff --git a/src/PHPCodeBrowser/Tests/IssueTest.php b/src/PHPCodeBrowser/Tests/IssueTest.php index e6dce6a..8c56fbf 100644 --- a/src/PHPCodeBrowser/Tests/IssueTest.php +++ b/src/PHPCodeBrowser/Tests/IssueTest.php @@ -115,11 +115,11 @@ protected function tearDown(): void */ public function testInstantiation(): void { - $this->assertSame('testFileName', $this->issue->getFileName()); - $this->assertSame(23, $this->issue->getLineStart()); - $this->assertSame(27, $this->issue->getLineEnd()); - $this->assertSame('testFinder', $this->issue->getFoundBy()); - $this->assertSame('testDescription', $this->issue->getDescription()); - $this->assertSame('notice', $this->issue->getSeverity()); + static::assertSame('testFileName', $this->issue->getFileName()); + static::assertSame(23, $this->issue->getLineStart()); + static::assertSame(27, $this->issue->getLineEnd()); + static::assertSame('testFinder', $this->issue->getFoundBy()); + static::assertSame('testDescription', $this->issue->getDescription()); + static::assertSame('notice', $this->issue->getSeverity()); } } diff --git a/src/PHPCodeBrowser/Tests/Plugins/ErrorCPDTest.php b/src/PHPCodeBrowser/Tests/Plugins/ErrorCPDTest.php index f8e0dfb..4b0f3f9 100644 --- a/src/PHPCodeBrowser/Tests/Plugins/ErrorCPDTest.php +++ b/src/PHPCodeBrowser/Tests/Plugins/ErrorCPDTest.php @@ -154,6 +154,6 @@ public function testGettingFileList(): void ), ]; $actual = $this->errorCPD->getFileList(); - $this->assertEquals($expected, $actual); + static::assertEquals($expected, $actual); } } diff --git a/src/PHPCodeBrowser/Tests/Plugins/ErrorCRAPTest.php b/src/PHPCodeBrowser/Tests/Plugins/ErrorCRAPTest.php index fd720d0..949912d 100644 --- a/src/PHPCodeBrowser/Tests/Plugins/ErrorCRAPTest.php +++ b/src/PHPCodeBrowser/Tests/Plugins/ErrorCRAPTest.php @@ -178,7 +178,7 @@ public function testGettingFileList(): void ), ]; $actual = $this->errorCrap->getFileList(); - $this->assertEquals($expected, $actual); + static::assertEquals($expected, $actual); } /** @@ -217,6 +217,6 @@ public function testGetFileListWithLimit(): void ), ]; $actual = $this->errorCrap->getFileList(); - $this->assertEquals($expected, $actual); + static::assertEquals($expected, $actual); } } diff --git a/src/PHPCodeBrowser/Tests/Plugins/ErrorCheckstyleTest.php b/src/PHPCodeBrowser/Tests/Plugins/ErrorCheckstyleTest.php index ed90b5b..bc6cb62 100644 --- a/src/PHPCodeBrowser/Tests/Plugins/ErrorCheckstyleTest.php +++ b/src/PHPCodeBrowser/Tests/Plugins/ErrorCheckstyleTest.php @@ -181,6 +181,6 @@ public function testGettingFileList(): void ), ]; $actual = $this->errorCheckstyle->getFileList(); - $this->assertEquals($expected, $actual); + static::assertEquals($expected, $actual); } } diff --git a/src/PHPCodeBrowser/Tests/Plugins/ErrorCoverageTest.php b/src/PHPCodeBrowser/Tests/Plugins/ErrorCoverageTest.php index a228929..1d5db97 100644 --- a/src/PHPCodeBrowser/Tests/Plugins/ErrorCoverageTest.php +++ b/src/PHPCodeBrowser/Tests/Plugins/ErrorCoverageTest.php @@ -184,6 +184,6 @@ public function testGettingFileList(): void ), ]; $actual = $this->errorCoverage->getFileList(); - $this->assertEquals($expected, $actual); + static::assertEquals($expected, $actual); } } diff --git a/src/PHPCodeBrowser/Tests/Plugins/ErrorPMDTest.php b/src/PHPCodeBrowser/Tests/Plugins/ErrorPMDTest.php index 9c7a629..104abbe 100644 --- a/src/PHPCodeBrowser/Tests/Plugins/ErrorPMDTest.php +++ b/src/PHPCodeBrowser/Tests/Plugins/ErrorPMDTest.php @@ -182,6 +182,6 @@ public function testGettingFileList(): void ), ]; $actual = $this->errorPmd->getFileList(); - $this->assertEquals($expected, $actual); + static::assertEquals($expected, $actual); } } diff --git a/src/PHPCodeBrowser/Tests/SourceHandlerTest.php b/src/PHPCodeBrowser/Tests/SourceHandlerTest.php index 0fd1dce..a1a7972 100644 --- a/src/PHPCodeBrowser/Tests/SourceHandlerTest.php +++ b/src/PHPCodeBrowser/Tests/SourceHandlerTest.php @@ -103,11 +103,14 @@ class SourceHandlerTest extends AbstractTestCase private $logger; /** - * Initializes common values. + * (non-PHPDoc) + * + * @see AbstractTests#setUp() */ - public function __construct() + protected function setUp(): void { - parent::__construct(); + parent::setUp(); + $xmlStrings = [ << @@ -119,7 +122,7 @@ public function __construct()
    HERE - , + , << @@ -135,7 +138,7 @@ public function __construct()
    HERE - , + , ]; $issueXML = new IssueXML(); @@ -150,16 +153,6 @@ public function __construct() new ErrorCheckstyle($issueXML), new ErrorPMD($issueXML), ]; - } - - /** - * (non-PHPDoc) - * - * @see AbstractTests#setUp() - */ - protected function setUp(): void - { - parent::setUp(); $this->logger = new Logger('PHPCodeBrowser'); $this->logger->pushHandler(new NullHandler()); @@ -182,7 +175,7 @@ public function testInstantiation(): void $this->logger, $this->plugins ); - $this->assertEquals($this->sourceHandler, $sourceHandler); + static::assertEquals($this->sourceHandler, $sourceHandler); } /** @@ -211,7 +204,7 @@ public function testGetFiles(): void File::sort($expected); $actual = $this->sourceHandler->getFiles(); - $this->assertEquals($expected, $actual); + static::assertEquals($expected, $actual); } /** @@ -226,7 +219,7 @@ public function testGetFilesWithIssues(): void '/a/nother/dir/src.php', ]; $actualFiles = $this->sourceHandler->getFilesWithIssues(); - $this->assertEquals($expectedFiles, $actualFiles); + static::assertEquals($expectedFiles, $actualFiles); } /** @@ -239,7 +232,7 @@ public function testAddSourceFiles(): void $this->sourceHandler->addSourceFiles( [new SplFileInfo(__FILE__), __FILE__] ); - $this->assertContains(__FILE__, \array_keys($this->sourceHandler->getFiles())); + static::assertContains(__FILE__, \array_keys($this->sourceHandler->getFiles())); } /** @@ -265,7 +258,7 @@ public function testGetCommonPathPrefix(): void { $expected = '/a/'; $actual = $this->sourceHandler->getCommonPathPrefix(); - $this->assertEquals($expected, $actual); + static::assertEquals($expected, $actual); } /** @@ -284,7 +277,7 @@ public function testExcludeMatchingPCRE(): void ), ]; $this->sourceHandler->excludeMatchingPCRE('/^\/a.*src\.php$/'); - $this->assertEquals($expected, $this->sourceHandler->getFiles()); + static::assertEquals($expected, $this->sourceHandler->getFiles()); } /** @@ -303,6 +296,6 @@ public function testExcludeMatchingPattern(): void ), ]; $this->sourceHandler->excludeMatchingPattern('*src.php'); - $this->assertEquals($expected, $this->sourceHandler->getFiles()); + static::assertEquals($expected, $this->sourceHandler->getFiles()); } } diff --git a/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php b/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php index c9eb738..119f042 100644 --- a/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php +++ b/src/PHPCodeBrowser/Tests/View/ViewReviewTest.php @@ -104,7 +104,7 @@ protected function setUp(): void $this->ioMock = $this->createMock(IOHelper::class); $this->viewReview = new ViewReview( - \getenv('PHPCB_TEMPLATE_DIR') ?: \dirname(__FILE__, 5).'/templates', + \getenv('PHPCB_TEMPLATE_DIR') ? \getenv('PHPCB_TEMPLATE_DIR') : \dirname(__FILE__, 5).'/templates', self::$testOutputDir, $this->ioMock ); @@ -119,13 +119,13 @@ public function testGenerateNoIssues(): void { $expectedFile = self::$testOutputDir.DIRECTORY_SEPARATOR.\basename(__FILE__).'.html'; - $this->ioMock->expects($this->once()) + $this->ioMock->expects(static::once()) ->method('loadFile') - ->with($this->equalTo(__FILE__)) + ->with(static::equalTo(__FILE__)) ->willReturn(\file_get_contents(__FILE__)); - $this->ioMock->expects($this->once()) + $this->ioMock->expects(static::once()) ->method('createFile') - ->with($this->equalTo($expectedFile)); + ->with(static::equalTo($expectedFile)); $this->viewReview->generate( [], @@ -153,13 +153,13 @@ public function testGenerate(): void ]; $expectedFile = self::$testOutputDir.DIRECTORY_SEPARATOR.\basename(__FILE__).'.html'; - $this->ioMock->expects($this->once()) + $this->ioMock->expects(static::once()) ->method('loadFile') - ->with($this->equalTo(__FILE__)) + ->with(static::equalTo(__FILE__)) ->willReturn(\file_get_contents(__FILE__)); - $this->ioMock->expects($this->once()) + $this->ioMock->expects(static::once()) ->method('createFile') - ->with($this->equalTo($expectedFile)); + ->with(static::equalTo($expectedFile)); $this->viewReview->generate( $issueList, @@ -181,13 +181,13 @@ public function testGenerateMultiple(): void ]; $expectedFile = self::$testOutputDir.DIRECTORY_SEPARATOR.\basename(__FILE__).'.html'; - $this->ioMock->expects($this->once()) + $this->ioMock->expects(static::once()) ->method('loadFile') - ->with($this->equalTo(__FILE__)) + ->with(static::equalTo(__FILE__)) ->willReturn(\file_get_contents(__FILE__)); - $this->ioMock->expects($this->once()) + $this->ioMock->expects(static::once()) ->method('createFile') - ->with($this->equalTo($expectedFile)); + ->with(static::equalTo($expectedFile)); $this->viewReview->generate( $issueList, @@ -204,7 +204,7 @@ public function testGenerateMultiple(): void public function testGenerateWithTextHighlighter(): void { if (!\class_exists('Text_Highlighter')) { - $this->markTestIncomplete(); + static::markTestIncomplete(); } $html = <<< EOT @@ -221,13 +221,13 @@ public function testGenerateWithTextHighlighter(): void $fileName = $prefix.'file.html'; $expectedFile = self::$testOutputDir.'/file.html.html'; - $this->ioMock->expects($this->once()) + $this->ioMock->expects(static::once()) ->method('loadFile') - ->with($this->equalTo($fileName)) + ->with(static::equalTo($fileName)) ->willReturn($html); - $this->ioMock->expects($this->once()) + $this->ioMock->expects(static::once()) ->method('createFile') - ->with($this->equalTo($expectedFile)); + ->with(static::equalTo($expectedFile)); $issues = [ new Issue($fileName, 5, 5, 'finder', 'description', 'severity'), @@ -245,9 +245,9 @@ public function testGenerateUnknownType(): void { $expectedFile = self::$testOutputDir.DIRECTORY_SEPARATOR.\basename(self::$xmlBasic).'.html'; - $this->ioMock->expects($this->once()) + $this->ioMock->expects(static::once()) ->method('createFile') - ->with($this->equalTo($expectedFile)); + ->with(static::equalTo($expectedFile)); $issueList = [ new Issue(self::$xmlBasic, 5, 5, 'finder', 'description', 'severity'), @@ -267,10 +267,10 @@ public function testGenerateUnknownType(): void */ public function testCopyResourceFolders(): void { - $this->ioMock->expects($this->exactly(3)) + $this->ioMock->expects(static::exactly(3)) ->method('copyDirectory') ->with( - $this->matchesRegularExpression( + static::matchesRegularExpression( '|^'.\realpath(__DIR__.'/../../../templates/').'|' ) ); @@ -290,11 +290,11 @@ public function testGenerateIndex(): void 's/B/anotherfile.php' => new File('s/B/anotherfile.php'), ]; - $this->ioMock->expects($this->once()) + $this->ioMock->expects(static::once()) ->method('createFile') ->with( - $this->logicalAnd( - $this->stringEndsWith('index.html') + static::logicalAnd( + static::stringEndsWith('index.html') ) ); $this->viewReview->generateIndex($files); diff --git a/src/PHPCodeBrowser/View/ViewReview.php b/src/PHPCodeBrowser/View/ViewReview.php index f168042..05f36fc 100644 --- a/src/PHPCodeBrowser/View/ViewReview.php +++ b/src/PHPCodeBrowser/View/ViewReview.php @@ -184,7 +184,7 @@ protected function highlightPhpCode(string $sourceCode): DOMDocument $code = \highlight_string($sourceCode, true); if (\extension_loaded('mbstring') && !\mb_check_encoding($code, 'UTF-8')) { - $detectOrder = \mb_detect_order(); + $detectOrder = (array) \mb_detect_order(); $detectOrder[] = 'iso-8859-1'; $encoding = \mb_detect_encoding($code, $detectOrder, true); @@ -204,7 +204,7 @@ protected function highlightPhpCode(string $sourceCode): DOMDocument $sourceDom->loadHTML(''.$code); //fetch ->->children from php generated html - $sourceElements = $sourceDom->getElementsByTagname('code')->item(0) + $sourceElements = $sourceDom->getElementsByTagName('code')->item(0) ->childNodes->item(0)->childNodes; //create target dom @@ -290,7 +290,7 @@ protected function highlightCode(string $file): DOMDocument $sourceCode = $this->ioHelper->loadFile($file); $extension = \pathinfo($file, PATHINFO_EXTENSION); - if (\in_array($extension, $this->phpSuffixes)) { + if (\in_array($extension, $this->phpSuffixes, true)) { return $this->highlightPhpCode($sourceCode); } @@ -339,7 +339,7 @@ private function formatSourceCode(string $filename, array $outputIssues): string $line->setAttribute('id', 'line_'.$lineNumber); $lineClasses = [ - ($lineNumber % 2) ? 'odd' : 'even', + ($lineNumber % 2 === 0) ? 'odd' : 'even', ]; if (isset($outputIssues[$lineNumber])) { From 8803324d22c7f4834bc0a358da8141802f3907ac Mon Sep 17 00:00:00 2001 From: croensch Date: Thu, 7 Mar 2024 17:33:29 +0100 Subject: [PATCH 33/34] IssueXML.php: skip DOCTYPE (fixes cobertura) skips 'childNodes as $node) { + if ($node instanceof DOMDocumentType) { + continue; + } + $this->documentElement->appendChild($this->importNode($node, true)); } } From 0835029efed6de613a4d3e6ad0e568089ff8f35e Mon Sep 17 00:00:00 2001 From: Michael Moll Date: Tue, 19 Mar 2024 23:19:52 +0100 Subject: [PATCH 34/34] Bump version to 4.0.1 --- bin/phpcb | 2 +- box.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/phpcb b/bin/phpcb index 72ddbe8..8ae4b8d 100755 --- a/bin/phpcb +++ b/bin/phpcb @@ -53,5 +53,5 @@ if (file_exists(__DIR__ . '/../../../autoload.php')) { include_once __DIR__ . '/../vendor/autoload.php'; } -$app = new PHPCodeBrowser\Application('PHP_CodeBrowser', '4.0.0'); +$app = new PHPCodeBrowser\Application('PHP_CodeBrowser', '4.0.1'); $app->run(); diff --git a/box.json b/box.json index 11a976c..7a7d53a 100644 --- a/box.json +++ b/box.json @@ -30,5 +30,5 @@ ], "git-commit": "git-commit", "git-version": "git-version", - "output": "phpcb-4.0.0.phar" + "output": "phpcb-4.0.1.phar" }