diff --git a/composer.json b/composer.json index 4e50031..e2f863b 100644 --- a/composer.json +++ b/composer.json @@ -38,12 +38,14 @@ "phpstan/phpstan": "^2.1", "squizlabs/php_codesniffer": "^3.10", "symfony/var-dumper": "^7.3", - "phpbench/phpbench": "^1.4" + "phpbench/phpbench": "^1.4", + "slevomat/coding-standard": "^8.15" }, "config": { "bin-dir": "bin", "allow-plugins": { - "infection/extension-installer": true + "infection/extension-installer": true, + "dealerdirect/phpcodesniffer-composer-installer": true }, "process-timeout": 0 }, @@ -82,7 +84,6 @@ "bin/phpbench run benchmarks --report=aggregate" ], "all": [ - "@csfix", "@cscheck", "@analyze", "@phpmd", diff --git a/composer.lock b/composer.lock index 5de4bb4..54a57c3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "822640c462f0d98b33c92e0f7b9231ad", + "content-hash": "60d45f0f109155e1ca2504ecf9b6c62c", "packages": [ { "name": "nikic/php-parser", @@ -1469,6 +1469,102 @@ ], "time": "2021-04-09T19:40:06+00:00" }, + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v1.1.2", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/composer-installer.git", + "reference": "e9cf5e4bbf7eeaf9ef5db34938942602838fc2b1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/e9cf5e4bbf7eeaf9ef5db34938942602838fc2b1", + "reference": "e9cf5e4bbf7eeaf9ef5db34938942602838fc2b1", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.2", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "^2.2", + "ext-json": "*", + "ext-zip": "*", + "php-parallel-lint/php-parallel-lint": "^1.4.0", + "phpcompatibility/php-compatibility": "^9.0", + "yoast/phpunit-polyfills": "^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "opensource@frenck.dev", + "homepage": "https://frenck.dev", + "role": "Open source developer" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "security": "https://github.com/PHPCSStandards/composer-installer/security/policy", + "source": "https://github.com/PHPCSStandards/composer-installer" + }, + "funding": [ + { + "url": "https://github.com/PHPCSStandards", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" + } + ], + "time": "2025-07-17T20:45:56+00:00" + }, { "name": "doctrine/annotations", "version": "2.0.2", @@ -2655,6 +2751,53 @@ ], "time": "2023-12-11T08:22:20+00:00" }, + { + "name": "phpstan/phpdoc-parser", + "version": "1.33.0", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/82a311fd3690fb2bf7b64d5c98f912b3dd746140", + "reference": "82a311fd3690fb2bf7b64d5c98f912b3dd746140", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "doctrine/annotations": "^2.0", + "nikic/php-parser": "^4.15", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.5", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.33.0" + }, + "time": "2024-10-13T11:25:22+00:00" + }, { "name": "phpstan/phpstan", "version": "2.1.0", @@ -5252,6 +5395,71 @@ ], "time": "2024-07-11T14:55:45+00:00" }, + { + "name": "slevomat/coding-standard", + "version": "8.15.0", + "source": { + "type": "git", + "url": "https://github.com/slevomat/coding-standard.git", + "reference": "7d1d957421618a3803b593ec31ace470177d7817" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/7d1d957421618a3803b593ec31ace470177d7817", + "reference": "7d1d957421618a3803b593ec31ace470177d7817", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0", + "php": "^7.2 || ^8.0", + "phpstan/phpdoc-parser": "^1.23.1", + "squizlabs/php_codesniffer": "^3.9.0" + }, + "require-dev": { + "phing/phing": "2.17.4", + "php-parallel-lint/php-parallel-lint": "1.3.2", + "phpstan/phpstan": "1.10.60", + "phpstan/phpstan-deprecation-rules": "1.1.4", + "phpstan/phpstan-phpunit": "1.3.16", + "phpstan/phpstan-strict-rules": "1.5.2", + "phpunit/phpunit": "8.5.21|9.6.8|10.5.11" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-master": "8.x-dev" + } + }, + "autoload": { + "psr-4": { + "SlevomatCodingStandard\\": "SlevomatCodingStandard/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "keywords": [ + "dev", + "phpcs" + ], + "support": { + "issues": "https://github.com/slevomat/coding-standard/issues", + "source": "https://github.com/slevomat/coding-standard/tree/8.15.0" + }, + "funding": [ + { + "url": "https://github.com/kukulich", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard", + "type": "tidelift" + } + ], + "time": "2024-03-09T15:20:58+00:00" + }, { "name": "squizlabs/php_codesniffer", "version": "3.10.0", @@ -5926,6 +6134,8 @@ "platform": { "php": "^8.1" }, - "platform-dev": {}, + "platform-dev": { + "ext-dom": "*" + }, "plugin-api-version": "2.6.0" } diff --git a/phpcs.xml b/phpcs.xml index 024a178..9a6f9b9 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,10 +1,24 @@ + + + + + + + + + + + + + + ./src ./tests/Unit *.TestCode diff --git a/src/Application.php b/src/Application.php index ee1d0d4..1979830 100644 --- a/src/Application.php +++ b/src/Application.php @@ -46,9 +46,6 @@ use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Messenger\Middleware\HandleMessageMiddleware; -/** - * - */ class Application { public const VERSION = '1.3.1'; @@ -271,13 +268,10 @@ public function getContainer(): ContainerBuilder return $this->containerBuilder; } - /** - * @param ProgressBarHandler $progressbar - * @param VerboseHandler $verbose - * @return HandlersLocator - */ - private function setUpEventHandlersLocator(ProgressBarHandler $progressbar, VerboseHandler $verbose): HandlersLocator - { + private function setUpEventHandlersLocator( + ProgressBarHandler $progressbar, + VerboseHandler $verbose + ): HandlersLocator { return new HandlersLocator([ SourceFilesFound::class => [ $progressbar, diff --git a/src/Business/Churn/ChangeCounter/ChangeCounterFactory.php b/src/Business/Churn/ChangeCounter/ChangeCounterFactory.php index 87e881b..759b890 100644 --- a/src/Business/Churn/ChangeCounter/ChangeCounterFactory.php +++ b/src/Business/Churn/ChangeCounter/ChangeCounterFactory.php @@ -6,15 +6,8 @@ use InvalidArgumentException; -/** - * - */ class ChangeCounterFactory { - /** - * @param string $type - * @return ChangeCounterInterface - */ public function create(string $type): ChangeCounterInterface { return match ($type) { diff --git a/src/Business/Churn/ChangeCounter/GitChangeCounter.php b/src/Business/Churn/ChangeCounter/GitChangeCounter.php index 6e83f59..19e4ab8 100644 --- a/src/Business/Churn/ChangeCounter/GitChangeCounter.php +++ b/src/Business/Churn/ChangeCounter/GitChangeCounter.php @@ -6,9 +6,6 @@ use Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException; -/** - * - */ class GitChangeCounter implements ChangeCounterInterface { /** diff --git a/src/Business/Churn/ChurnCalculator.php b/src/Business/Churn/ChurnCalculator.php index a59a9a7..52aa38b 100644 --- a/src/Business/Churn/ChurnCalculator.php +++ b/src/Business/Churn/ChurnCalculator.php @@ -7,9 +7,6 @@ use Phauthentic\CognitiveCodeAnalysis\Business\CodeCoverage\CoverageReportReaderInterface; use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\CognitiveMetricsCollection; -/** - * - */ class ChurnCalculator { /** diff --git a/src/Business/Churn/Exporter/CsvExporter.php b/src/Business/Churn/Exporter/CsvExporter.php index 0a52774..d1b3b1c 100644 --- a/src/Business/Churn/Exporter/CsvExporter.php +++ b/src/Business/Churn/Exporter/CsvExporter.php @@ -4,8 +4,6 @@ namespace Phauthentic\CognitiveCodeAnalysis\Business\Churn\Exporter; -use Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException; - /** * CsvExporter for Churn metrics. */ @@ -25,7 +23,7 @@ class CsvExporter extends AbstractExporter /** * @param array> $classes * @param string $filename - * @throws CognitiveAnalysisException + * @throws \Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException */ public function export(array $classes, string $filename): void { diff --git a/src/Business/Churn/Exporter/DataExporterInterface.php b/src/Business/Churn/Exporter/DataExporterInterface.php index 9008996..162ff0c 100644 --- a/src/Business/Churn/Exporter/DataExporterInterface.php +++ b/src/Business/Churn/Exporter/DataExporterInterface.php @@ -4,9 +4,6 @@ namespace Phauthentic\CognitiveCodeAnalysis\Business\Churn\Exporter; -/** - * - */ interface DataExporterInterface { /** diff --git a/src/Business/Churn/Exporter/JsonExporter.php b/src/Business/Churn/Exporter/JsonExporter.php index b4667f3..0615b25 100644 --- a/src/Business/Churn/Exporter/JsonExporter.php +++ b/src/Business/Churn/Exporter/JsonExporter.php @@ -4,15 +4,13 @@ namespace Phauthentic\CognitiveCodeAnalysis\Business\Churn\Exporter; -use JsonException; use Phauthentic\CognitiveCodeAnalysis\Business\Utility\Datetime; -use Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException; class JsonExporter extends AbstractExporter { /** * @param array> $classes - * @throws JsonException|CognitiveAnalysisException + * @throws \JsonException|\Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException */ public function export(array $classes, string $filename): void { diff --git a/src/Business/Churn/Exporter/MarkdownExporter.php b/src/Business/Churn/Exporter/MarkdownExporter.php index 27e1a4c..f982784 100644 --- a/src/Business/Churn/Exporter/MarkdownExporter.php +++ b/src/Business/Churn/Exporter/MarkdownExporter.php @@ -7,7 +7,6 @@ use Phauthentic\CognitiveCodeAnalysis\Business\Exporter\MarkdownFormatterTrait; use Phauthentic\CognitiveCodeAnalysis\Business\Traits\CoverageDataDetector; use Phauthentic\CognitiveCodeAnalysis\Business\Utility\Datetime; -use Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException; /** * MarkdownExporter for Churn metrics. @@ -43,7 +42,7 @@ class MarkdownExporter extends AbstractExporter /** * @param array> $classes * @param string $filename - * @throws CognitiveAnalysisException + * @throws \Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException */ public function export(array $classes, string $filename): void { diff --git a/src/Business/Churn/Exporter/TreemapMath.php b/src/Business/Churn/Exporter/TreemapMath.php index 23e61bb..7bc5a53 100644 --- a/src/Business/Churn/Exporter/TreemapMath.php +++ b/src/Business/Churn/Exporter/TreemapMath.php @@ -31,13 +31,15 @@ public function prepareItems(array $classes): array foreach ($classes as $class => $data) { $churn = (float)($data['churn'] ?? 0); $score = (float)($data['score'] ?? 0); - if ($churn > 0) { - $items[] = [ - 'class' => $class, - 'churn' => $churn, - 'score' => $score, - ]; + if ($churn <= 0) { + continue; } + + $items[] = [ + 'class' => $class, + 'churn' => $churn, + 'score' => $score, + ]; } usort($items, fn($a, $b) => $b['churn'] <=> $a['churn']); diff --git a/src/Business/CodeCoverage/AbstractXmlCoverageReader.php b/src/Business/CodeCoverage/AbstractXmlCoverageReader.php index 5b81b00..d875bf8 100644 --- a/src/Business/CodeCoverage/AbstractXmlCoverageReader.php +++ b/src/Business/CodeCoverage/AbstractXmlCoverageReader.php @@ -54,9 +54,11 @@ public function getAllClasses(): array } foreach ($classes as $class) { - if ($class instanceof DOMElement) { - $fqcns[] = $class->getAttribute('name'); + if (!($class instanceof DOMElement)) { + continue; } + + $fqcns[] = $class->getAttribute('name'); } return $fqcns; diff --git a/src/Business/CodeCoverage/CloverReader.php b/src/Business/CodeCoverage/CloverReader.php index 0a00c65..18e4dc9 100644 --- a/src/Business/CodeCoverage/CloverReader.php +++ b/src/Business/CodeCoverage/CloverReader.php @@ -169,20 +169,22 @@ private function extractMethodsCoverage(DOMElement $classNode): array } foreach ($methodLines as $methodLine) { - if ($methodLine instanceof DOMElement) { - $methodName = $methodLine->getAttribute('name'); - $complexity = (int)$methodLine->getAttribute('complexity'); - - // Calculate coverage for this method by looking at subsequent statement lines - $methodCoverage = $this->calculateMethodCoverage($fileNode, $methodLine); - - $methods[$methodName] = new MethodCoverage( - name: $methodName, - lineRate: $methodCoverage, - branchRate: 0.0, // Clover doesn't provide per-method branch coverage - complexity: $complexity, - ); + if (!($methodLine instanceof DOMElement)) { + continue; } + + $methodName = $methodLine->getAttribute('name'); + $complexity = (int)$methodLine->getAttribute('complexity'); + + // Calculate coverage for this method by looking at subsequent statement lines + $methodCoverage = $this->calculateMethodCoverage($fileNode, $methodLine); + + $methods[$methodName] = new MethodCoverage( + name: $methodName, + lineRate: $methodCoverage, + branchRate: 0.0, // Clover doesn't provide per-method branch coverage + complexity: $complexity, + ); } return $methods; @@ -235,12 +237,16 @@ private function extractMethodCoverageFromLines(mixed $allLines, int $methodLine break; } - if ($this->isMethodStatement($inMethod, $type)) { - $statements++; - if ($this->isStatementCovered($line)) { - $coveredStatements++; - } + if (!$this->isMethodStatement($inMethod, $type)) { + continue; } + + $statements++; + if (!$this->isStatementCovered($line)) { + continue; + } + + $coveredStatements++; } return [ diff --git a/src/Business/CodeCoverage/CoberturaReader.php b/src/Business/CodeCoverage/CoberturaReader.php index 304a03d..0ca3850 100644 --- a/src/Business/CodeCoverage/CoberturaReader.php +++ b/src/Business/CodeCoverage/CoberturaReader.php @@ -88,15 +88,17 @@ private function extractMethodsCoverage(DOMElement $classNode): array } foreach ($methodNodes as $methodNode) { - if ($methodNode instanceof DOMElement) { - $methodName = $methodNode->getAttribute('name'); - $methods[$methodName] = new MethodCoverage( - name: $methodName, - lineRate: (float)$methodNode->getAttribute('line-rate'), - branchRate: (float)$methodNode->getAttribute('branch-rate'), - complexity: (int)$methodNode->getAttribute('complexity'), - ); + if (!($methodNode instanceof DOMElement)) { + continue; } + + $methodName = $methodNode->getAttribute('name'); + $methods[$methodName] = new MethodCoverage( + name: $methodName, + lineRate: (float)$methodNode->getAttribute('line-rate'), + branchRate: (float)$methodNode->getAttribute('branch-rate'), + complexity: (int)$methodNode->getAttribute('complexity'), + ); } return $methods; diff --git a/src/Business/Cognitive/Baseline.php b/src/Business/Cognitive/Baseline.php index 19499bc..c1f2065 100644 --- a/src/Business/Cognitive/Baseline.php +++ b/src/Business/Cognitive/Baseline.php @@ -4,12 +4,8 @@ namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive; -use JsonException; use Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException; -/** - * - */ class Baseline { /** @@ -36,7 +32,7 @@ public function calculateDeltas(CognitiveMetricsCollection $metricsCollection, a * * @param string $baselineFile * @return array> $baseline - * @throws JsonException|CognitiveAnalysisException + * @throws \JsonException|\Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException */ public function loadBaseline(string $baselineFile): array { diff --git a/src/Business/Cognitive/CognitiveMetrics.php b/src/Business/Cognitive/CognitiveMetrics.php index d3c904f..cbef0d8 100644 --- a/src/Business/Cognitive/CognitiveMetrics.php +++ b/src/Business/Cognitive/CognitiveMetrics.php @@ -86,9 +86,11 @@ public function __construct(array $metrics) $this->halstead = new HalsteadMetrics($metrics['halstead']); } - if (isset($metrics['cyclomatic_complexity'])) { - $this->cyclomatic = new CyclomaticMetrics($metrics['cyclomatic_complexity']); + if (!isset($metrics['cyclomatic_complexity'])) { + return; } + + $this->cyclomatic = new CyclomaticMetrics($metrics['cyclomatic_complexity']); } /** @@ -458,17 +460,11 @@ public function jsonSerialize(): array return $this->toArray(); } - /** - * @return HalsteadMetrics|null - */ public function getHalstead(): ?HalsteadMetrics { return $this->halstead; } - /** - * @return CyclomaticMetrics|null - */ public function getCyclomatic(): ?CyclomaticMetrics { return $this->cyclomatic; diff --git a/src/Business/Cognitive/CognitiveMetricsCollector.php b/src/Business/Cognitive/CognitiveMetricsCollector.php index eda366c..acbd42b 100644 --- a/src/Business/Cognitive/CognitiveMetricsCollector.php +++ b/src/Business/Cognitive/CognitiveMetricsCollector.php @@ -58,7 +58,7 @@ public function collectFromPaths(array $paths, CognitiveConfig $config): Cogniti $allFiles = array_merge($allFiles, iterator_to_array($files)); } - $this->messageBus->dispatch(new SourceFilesFound($allFiles)); + $this->messageBus->dispatch(new SourceFilesFound(array_values($allFiles))); return $this->findMetrics($allFiles); } @@ -160,9 +160,11 @@ private function processMethodMetrics( $metric = new CognitiveMetrics($metricsArray); - if (!$metricsCollection->contains($metric)) { - $metricsCollection->add($metric); + if ($metricsCollection->contains($metric)) { + continue; } + + $metricsCollection->add($metric); } return $metricsCollection; diff --git a/src/Business/Cognitive/Delta.php b/src/Business/Cognitive/Delta.php index 54203de..454a031 100644 --- a/src/Business/Cognitive/Delta.php +++ b/src/Business/Cognitive/Delta.php @@ -4,9 +4,6 @@ namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive; -/** - * - */ final class Delta { private bool $hasIncreased; diff --git a/src/Business/Cognitive/Events/FileProcessed.php b/src/Business/Cognitive/Events/FileProcessed.php index 022ca8d..49de136 100644 --- a/src/Business/Cognitive/Events/FileProcessed.php +++ b/src/Business/Cognitive/Events/FileProcessed.php @@ -6,9 +6,6 @@ use SplFileInfo; -/** - * - */ class FileProcessed { public function __construct( diff --git a/src/Business/Cognitive/Events/ParserFailed.php b/src/Business/Cognitive/Events/ParserFailed.php index 67bd596..8e336d2 100644 --- a/src/Business/Cognitive/Events/ParserFailed.php +++ b/src/Business/Cognitive/Events/ParserFailed.php @@ -7,9 +7,6 @@ use SplFileInfo; use Throwable; -/** - * - */ class ParserFailed { public function __construct( diff --git a/src/Business/Cognitive/Events/SourceFilesFound.php b/src/Business/Cognitive/Events/SourceFilesFound.php index ef1e61a..355cc64 100644 --- a/src/Business/Cognitive/Events/SourceFilesFound.php +++ b/src/Business/Cognitive/Events/SourceFilesFound.php @@ -4,15 +4,10 @@ namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Events; -use SplFileInfo; - -/** - * - */ class SourceFilesFound { /** - * @param array $files + * @param array<\SplFileInfo> $files */ public function __construct( public readonly array $files diff --git a/src/Business/Cognitive/Exporter/CsvExporter.php b/src/Business/Cognitive/Exporter/CsvExporter.php index 1548969..2e84963 100644 --- a/src/Business/Cognitive/Exporter/CsvExporter.php +++ b/src/Business/Cognitive/Exporter/CsvExporter.php @@ -7,9 +7,6 @@ use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\CognitiveMetricsCollection; use Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException; -/** - * - */ class CsvExporter implements DataExporterInterface { /** diff --git a/src/Business/Cognitive/Exporter/DataExporterInterface.php b/src/Business/Cognitive/Exporter/DataExporterInterface.php index 727f000..42d24a4 100644 --- a/src/Business/Cognitive/Exporter/DataExporterInterface.php +++ b/src/Business/Cognitive/Exporter/DataExporterInterface.php @@ -6,9 +6,6 @@ use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\CognitiveMetricsCollection; -/** - * - */ interface DataExporterInterface { public function export(CognitiveMetricsCollection $metrics, string $filename): void; diff --git a/src/Business/Cognitive/Exporter/JsonExporter.php b/src/Business/Cognitive/Exporter/JsonExporter.php index 9173851..997e5cc 100644 --- a/src/Business/Cognitive/Exporter/JsonExporter.php +++ b/src/Business/Cognitive/Exporter/JsonExporter.php @@ -4,17 +4,13 @@ namespace Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Exporter; -use JsonException; use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\CognitiveMetricsCollection; use Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException; -/** - * - */ class JsonExporter implements DataExporterInterface { /** - * @throws JsonException|CognitiveAnalysisException + * @throws \JsonException|\Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException */ public function export(CognitiveMetricsCollection $metricsCollection, string $filename): void { diff --git a/src/Business/Cognitive/Exporter/MarkdownExporter.php b/src/Business/Cognitive/Exporter/MarkdownExporter.php index 9917e85..f4e61a2 100644 --- a/src/Business/Cognitive/Exporter/MarkdownExporter.php +++ b/src/Business/Cognitive/Exporter/MarkdownExporter.php @@ -80,9 +80,11 @@ private function filterMetrics(CognitiveMetricsCollection $methods): CognitiveMe $filtered = new CognitiveMetricsCollection(); foreach ($methods as $metric) { - if ($metric->getScore() > $this->config->scoreThreshold) { - $filtered->add($metric); + if ($metric->getScore() <= $this->config->scoreThreshold) { + continue; } + + $filtered->add($metric); } return $filtered; diff --git a/src/Business/Cognitive/Parser.php b/src/Business/Cognitive/Parser.php index c2b8540..9016504 100644 --- a/src/Business/Cognitive/Parser.php +++ b/src/Business/Cognitive/Parser.php @@ -17,9 +17,6 @@ use PhpParser\ParserFactory; use ReflectionClass; -/** - * - */ class Parser { protected PhpParser $parser; @@ -78,21 +75,25 @@ public function parse(string $code): array // Add cyclomatic complexity to method metrics foreach ($cyclomaticMetrics as $method => $complexityData) { - if (isset($methodMetrics[$method])) { - $complexity = $complexityData['complexity'] ?? $complexityData; - $riskLevel = $complexityData['risk_level'] ?? $this->getRiskLevel($complexity); - $methodMetrics[$method]['cyclomatic_complexity'] = [ - 'complexity' => $complexity, - 'risk_level' => $riskLevel - ]; + if (!isset($methodMetrics[$method])) { + continue; } + + $complexity = $complexityData['complexity'] ?? $complexityData; + $riskLevel = $complexityData['risk_level'] ?? $this->getRiskLevel($complexity); + $methodMetrics[$method]['cyclomatic_complexity'] = [ + 'complexity' => $complexity, + 'risk_level' => $riskLevel + ]; } // Add Halstead metrics to method metrics foreach ($halsteadMetrics as $method => $metrics) { - if (isset($methodMetrics[$method])) { - $methodMetrics[$method]['halstead'] = $metrics; + if (!isset($methodMetrics[$method])) { + continue; } + + $methodMetrics[$method]['halstead'] = $metrics; } return $methodMetrics; diff --git a/src/Business/Cognitive/ScoreCalculator.php b/src/Business/Cognitive/ScoreCalculator.php index 07263f0..4379c81 100644 --- a/src/Business/Cognitive/ScoreCalculator.php +++ b/src/Business/Cognitive/ScoreCalculator.php @@ -6,9 +6,6 @@ use Phauthentic\CognitiveCodeAnalysis\Config\CognitiveConfig; -/** - * - */ class ScoreCalculator { /** @@ -39,11 +36,6 @@ class ScoreCalculator 'ElseCount' => 'elseCount', ]; - /** - * @param CognitiveMetrics $metrics - * @param CognitiveConfig $config - * @return void - */ public function calculate(CognitiveMetrics $metrics, CognitiveConfig $config): void { $this->calculateMetricWeights($this->metricTypes, $metrics, $config); @@ -67,8 +59,11 @@ private function calculateScore(CognitiveMetrics $metrics): void * @param CognitiveConfig $config * @return void */ - private function calculateMetricWeights(array $metricTypes, CognitiveMetrics $metrics, CognitiveConfig $config): void - { + private function calculateMetricWeights( + array $metricTypes, + CognitiveMetrics $metrics, + CognitiveConfig $config + ): void { $metricConfigs = $config->metrics; foreach ($metricTypes as $methodSuffix => $configKey) { diff --git a/src/Business/DirectoryScanner.php b/src/Business/DirectoryScanner.php index 207d304..f55058b 100644 --- a/src/Business/DirectoryScanner.php +++ b/src/Business/DirectoryScanner.php @@ -35,9 +35,11 @@ public function scan(array $paths, array $exclude = []): Generator yield from $this->yieldFileIfNotExcluded($path, $exclude); } - if (is_dir($path)) { - yield from $this->traverseDirectory($path, $exclude); + if (!is_dir($path)) { + continue; } + + yield from $this->traverseDirectory($path, $exclude); } } @@ -60,9 +62,11 @@ private function yieldFileIfNotExcluded(string $path, array $exclude): Generator { $fileInfo = new SplFileInfo($path); - if (!$this->isExcluded($fileInfo, $exclude)) { - yield $fileInfo; + if ($this->isExcluded($fileInfo, $exclude)) { + return; } + + yield $fileInfo; } /** @@ -112,9 +116,11 @@ private function getFilesFromIterator(\Iterator $iterator, array $exclude): arra { $files = []; foreach ($iterator as $fileInfo) { - if ($fileInfo->isFile() && !$this->isExcluded($fileInfo, $exclude)) { - $files[] = $fileInfo; + if (!$fileInfo->isFile() || $this->isExcluded($fileInfo, $exclude)) { + continue; } + + $files[] = $fileInfo; } return $files; diff --git a/src/Business/MetricsFacade.php b/src/Business/MetricsFacade.php index ac1ca14..1bbb764 100644 --- a/src/Business/MetricsFacade.php +++ b/src/Business/MetricsFacade.php @@ -83,17 +83,21 @@ public function getCognitiveMetrics(string $path): CognitiveMetricsCollection * @param CoverageReportReaderInterface|null $coverageReader Optional coverage reader for coverage data. * @return CognitiveMetricsCollection The collected cognitive metrics from all paths. */ - public function getCognitiveMetricsFromPaths(array $paths, ?CoverageReportReaderInterface $coverageReader = null): CognitiveMetricsCollection - { + public function getCognitiveMetricsFromPaths( + array $paths, + ?CoverageReportReaderInterface $coverageReader = null + ): CognitiveMetricsCollection { $metricsCollection = $this->cognitiveMetricsCollector->collectFromPaths($paths, $this->configService->getConfig()); foreach ($metricsCollection as $metric) { $this->scoreCalculator->calculate($metric, $this->configService->getConfig()); // Add coverage data if reader is provided - if ($coverageReader !== null) { - $this->addCoverageToMetric($metric, $coverageReader); + if ($coverageReader === null) { + continue; } + + $this->addCoverageToMetric($metric, $coverageReader); } return $metricsCollection; @@ -153,8 +157,6 @@ public function exportChurnReport( $exporter->export($classes, $filename); } - /** - */ public function exportMetricsReport( CognitiveMetricsCollection $metricsCollection, string $reportType, @@ -183,9 +185,11 @@ private function addCoverageToMetric( // Fall back to class-level coverage if details not available $coverage = $coverageReader->getLineCoverage($className); - if ($coverage !== null) { - $metric->setCoverage($coverage); + if ($coverage === null) { + return; } + + $metric->setCoverage($coverage); } /** diff --git a/src/Business/Utility/Datetime.php b/src/Business/Utility/Datetime.php index 453a52a..d0ef6cd 100644 --- a/src/Business/Utility/Datetime.php +++ b/src/Business/Utility/Datetime.php @@ -6,9 +6,6 @@ use DateTime as PHPDateTime; -/** - * - */ class Datetime extends PHPDateTime { /** diff --git a/src/CognitiveAnalysisException.php b/src/CognitiveAnalysisException.php index 93f2be3..c49778e 100644 --- a/src/CognitiveAnalysisException.php +++ b/src/CognitiveAnalysisException.php @@ -6,9 +6,6 @@ use Exception; -/** - * - */ class CognitiveAnalysisException extends Exception { } diff --git a/src/Command/ChurnCommand.php b/src/Command/ChurnCommand.php index bf57e4e..115df40 100644 --- a/src/Command/ChurnCommand.php +++ b/src/Command/ChurnCommand.php @@ -17,9 +17,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -/** - * - */ #[AsCommand( name: 'churn', description: 'Calculates the churn based on version control history.', diff --git a/src/Command/CognitiveMetricsCommand.php b/src/Command/CognitiveMetricsCommand.php index 8ac124b..87e69f0 100644 --- a/src/Command/CognitiveMetricsCommand.php +++ b/src/Command/CognitiveMetricsCommand.php @@ -185,10 +185,12 @@ private function parsePaths(string $pathInput): array private function handleBaseLine(InputInterface $input, CognitiveMetricsCollection $metricsCollection): void { $baselineFile = $input->getOption(self::OPTION_BASELINE); - if ($baselineFile) { - $baseline = $this->baselineService->loadBaseline($baselineFile); - $this->baselineService->calculateDeltas($metricsCollection, $baseline); + if (!$baselineFile) { + return; } + + $baseline = $this->baselineService->loadBaseline($baselineFile); + $this->baselineService->calculateDeltas($metricsCollection, $baseline); } /** @@ -196,8 +198,10 @@ private function handleBaseLine(InputInterface $input, CognitiveMetricsCollectio * * @return CoverageReportReaderInterface|null|false Returns reader, null if no coverage, or false on error */ - private function handleCoverageOptions(InputInterface $input, OutputInterface $output): CoverageReportReaderInterface|null|false - { + private function handleCoverageOptions( + InputInterface $input, + OutputInterface $output + ): CoverageReportReaderInterface|null|false { $coberturaFile = $input->getOption(self::OPTION_COVERAGE_COBERTURA); $cloverFile = $input->getOption(self::OPTION_COVERAGE_CLOVER); diff --git a/src/Command/EventHandler/ProgressBarHandler.php b/src/Command/EventHandler/ProgressBarHandler.php index f91e49f..1ede31c 100644 --- a/src/Command/EventHandler/ProgressBarHandler.php +++ b/src/Command/EventHandler/ProgressBarHandler.php @@ -9,9 +9,6 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Helper\ProgressBar; -/** - * - */ class ProgressBarHandler { private ProgressBar $progressBar; @@ -30,9 +27,11 @@ public function __invoke(SourceFilesFound|FileProcessed $event): void $event instanceof FileProcessed => $this->handleFileProcessed(), }; - if ($this->processedFiles === $this->totalFiles) { - $this->handleAllFilesProcessed(); + if ($this->processedFiles !== $this->totalFiles) { + return; } + + $this->handleAllFilesProcessed(); } private function handleSourceFilesFound(SourceFilesFound $event): void diff --git a/src/Command/EventHandler/VerboseHandler.php b/src/Command/EventHandler/VerboseHandler.php index dd09088..15b5b59 100644 --- a/src/Command/EventHandler/VerboseHandler.php +++ b/src/Command/EventHandler/VerboseHandler.php @@ -10,9 +10,6 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -/** - * - */ class VerboseHandler { private float $startTime = 0.0; @@ -33,12 +30,14 @@ public function __invoke(SourceFilesFound|FileProcessed $event): void $this->startTime = microtime(true); } - if ($event instanceof FileProcessed) { - $runtime = (microtime(true) - $this->startTime); - - $this->output->writeln('Processed ' . $event->file->getRealPath()); - $this->output->writeln(' Memory: ' . $this->formatBytes(memory_get_usage(true)) . ' || Total Time: ' . round($runtime, 4) . 's'); + if (!($event instanceof FileProcessed)) { + return; } + + $runtime = (microtime(true) - $this->startTime); + + $this->output->writeln('Processed ' . $event->file->getRealPath()); + $this->output->writeln(' Memory: ' . $this->formatBytes(memory_get_usage(true)) . ' || Total Time: ' . round($runtime, 4) . 's'); } /** @@ -60,9 +59,6 @@ private function formatBytes(int $size): string return round($size, 2) . ' ' . $units[$index]; } - /** - * @return bool - */ public function isDebugEnabled(): bool { return $this->input->hasOption(CognitiveMetricsCommand::OPTION_DEBUG) diff --git a/src/Command/Handler/ChurnReportHandler.php b/src/Command/Handler/ChurnReportHandler.php index 7feda7d..78a639b 100644 --- a/src/Command/Handler/ChurnReportHandler.php +++ b/src/Command/Handler/ChurnReportHandler.php @@ -10,9 +10,6 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Output\OutputInterface; -/** - * - */ class ChurnReportHandler { private ChurnExporterFactory $exporterFactory; @@ -70,10 +67,6 @@ private function isValidReportType(?string $reportType): bool return $this->exporterFactory->isSupported($reportType); } - /** - * @param Exception $exception - * @return int - */ private function handleExceptions(Exception $exception): int { $this->output->writeln(sprintf( @@ -84,10 +77,6 @@ private function handleExceptions(Exception $exception): int return Command::FAILURE; } - /** - * @param string|null $reportType - * @return int - */ private function handleInvalidReportType(?string $reportType): int { $supportedTypes = implode('`, `', $this->exporterFactory->getSupportedTypes()); diff --git a/src/Command/Handler/CognitiveMetricsReportHandler.php b/src/Command/Handler/CognitiveMetricsReportHandler.php index e78f56f..a1720f9 100644 --- a/src/Command/Handler/CognitiveMetricsReportHandler.php +++ b/src/Command/Handler/CognitiveMetricsReportHandler.php @@ -59,10 +59,6 @@ private function isValidReportType(?string $reportType): bool return in_array($reportType, ['json', 'csv', 'html', 'markdown']); } - /** - * @param Exception $exception - * @return int - */ private function handleExceptions(Exception $exception): int { $this->output->writeln(sprintf( @@ -73,10 +69,6 @@ private function handleExceptions(Exception $exception): int return Command::FAILURE; } - /** - * @param string|null $reportType - * @return int - */ public function handleInvalidReporType(?string $reportType): int { $this->output->writeln(sprintf( diff --git a/src/Command/Presentation/ChurnTextRenderer.php b/src/Command/Presentation/ChurnTextRenderer.php index c93588d..bfdc0d8 100644 --- a/src/Command/Presentation/ChurnTextRenderer.php +++ b/src/Command/Presentation/ChurnTextRenderer.php @@ -4,14 +4,10 @@ namespace Phauthentic\CognitiveCodeAnalysis\Command\Presentation; -use Phauthentic\CognitiveCodeAnalysis\Business\CodeCoverage\CoberturaReader; use Phauthentic\CognitiveCodeAnalysis\Business\Traits\CoverageDataDetector; use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Output\OutputInterface; -/** - * - */ class ChurnTextRenderer { use CoverageDataDetector; diff --git a/src/Command/Presentation/CognitiveMetricSummaryTextRenderer.php b/src/Command/Presentation/CognitiveMetricSummaryTextRenderer.php index f8f20be..8d233c6 100644 --- a/src/Command/Presentation/CognitiveMetricSummaryTextRenderer.php +++ b/src/Command/Presentation/CognitiveMetricSummaryTextRenderer.php @@ -10,9 +10,6 @@ use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Output\OutputInterface; -/** - * - */ class CognitiveMetricSummaryTextRenderer implements CognitiveMetricTextRendererInterface { public function __construct( @@ -24,9 +21,11 @@ public function render(CognitiveMetricsCollection $metricsCollection, OutputInte { $highlighted = []; foreach ($metricsCollection as $metric) { - if ($metric->getScore() > $this->configService->getConfig()->scoreThreshold) { - $highlighted[] = $metric; + if ($metric->getScore() <= $this->configService->getConfig()->scoreThreshold) { + continue; } + + $highlighted[] = $metric; } usort( diff --git a/src/Command/Presentation/CognitiveMetricTextRenderer.php b/src/Command/Presentation/CognitiveMetricTextRenderer.php index 8aee736..cb81d27 100644 --- a/src/Command/Presentation/CognitiveMetricTextRenderer.php +++ b/src/Command/Presentation/CognitiveMetricTextRenderer.php @@ -12,9 +12,6 @@ use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Output\OutputInterface; -/** - * - */ class CognitiveMetricTextRenderer implements CognitiveMetricTextRendererInterface { use CoverageDataDetector; @@ -51,10 +48,6 @@ private function hasCoverageInCollection(CognitiveMetricsCollection $metricsColl return false; } - /** - * @param CognitiveMetricsCollection $metricsCollection - * @param OutputInterface $output - */ public function render(CognitiveMetricsCollection $metricsCollection, OutputInterface $output): void { $config = $this->configService->getConfig(); @@ -73,11 +66,6 @@ public function render(CognitiveMetricsCollection $metricsCollection, OutputInte $this->renderAllMethodsInSingleTable($metricsCollection, $config, $output); } - /** - * @param CognitiveMetricsCollection $metricsCollection - * @param CognitiveConfig $config - * @param OutputInterface $output - */ private function renderGroupedByClass( CognitiveMetricsCollection $metricsCollection, CognitiveConfig $config, @@ -91,10 +79,12 @@ private function renderGroupedByClass( } $rows = $this->buildRowsForClass($metrics, $config); - if (count($rows) > 0) { - $filename = $this->getFilenameFromMetrics($metrics); - $this->renderTable((string)$className, $rows, $filename, $output); + if (count($rows) <= 0) { + continue; } + + $filename = $this->getFilenameFromMetrics($metrics); + $this->renderTable((string)$className, $rows, $filename, $output); } } @@ -128,11 +118,6 @@ private function getFilenameFromMetrics(CognitiveMetricsCollection $metrics): st return ''; } - /** - * @param CognitiveMetricsCollection $metricsCollection - * @param CognitiveConfig $config - * @param OutputInterface $output - */ private function renderAllMethodsInSingleTable( CognitiveMetricsCollection $metricsCollection, CognitiveConfig $config, @@ -141,9 +126,11 @@ private function renderAllMethodsInSingleTable( $rows = $this->buildRowsForSingleTable($metricsCollection, $config); $totalMethods = count($rows); - if ($totalMethods > 0) { - $this->renderSingleTable($rows, $totalMethods, $output); + if ($totalMethods <= 0) { + return; } + + $this->renderSingleTable($rows, $totalMethods, $output); } /** diff --git a/src/Command/Presentation/CognitiveMetricTextRendererInterface.php b/src/Command/Presentation/CognitiveMetricTextRendererInterface.php index ce8c0f1..fd1f5ad 100644 --- a/src/Command/Presentation/CognitiveMetricTextRendererInterface.php +++ b/src/Command/Presentation/CognitiveMetricTextRendererInterface.php @@ -5,18 +5,14 @@ namespace Phauthentic\CognitiveCodeAnalysis\Command\Presentation; use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\CognitiveMetricsCollection; -use Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException; use Symfony\Component\Console\Output\OutputInterface; -/** - * - */ interface CognitiveMetricTextRendererInterface { /** * @param CognitiveMetricsCollection $metricsCollection * @param OutputInterface $output - * @throws CognitiveAnalysisException + * @throws \Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException */ public function render(CognitiveMetricsCollection $metricsCollection, OutputInterface $output): void; } diff --git a/src/Config/CognitiveConfig.php b/src/Config/CognitiveConfig.php index 80402f0..0279f49 100644 --- a/src/Config/CognitiveConfig.php +++ b/src/Config/CognitiveConfig.php @@ -4,8 +4,6 @@ namespace Phauthentic\CognitiveCodeAnalysis\Config; -use InvalidArgumentException; - /** * @SuppressWarnings(BooleanArgumentFlag) */ diff --git a/src/Config/ConfigFactory.php b/src/Config/ConfigFactory.php index e98823b..17641aa 100644 --- a/src/Config/ConfigFactory.php +++ b/src/Config/ConfigFactory.php @@ -4,9 +4,6 @@ namespace Phauthentic\CognitiveCodeAnalysis\Config; -/** - * - */ class ConfigFactory { /** diff --git a/src/Config/ConfigService.php b/src/Config/ConfigService.php index 5181e7d..725d601 100644 --- a/src/Config/ConfigService.php +++ b/src/Config/ConfigService.php @@ -7,9 +7,6 @@ use Symfony\Component\Yaml\Yaml; use Symfony\Component\Config\Definition\Processor; -/** - * - */ class ConfigService { private CognitiveConfig $config; diff --git a/src/Config/MetricsConfig.php b/src/Config/MetricsConfig.php index 92621d6..98ea5e8 100644 --- a/src/Config/MetricsConfig.php +++ b/src/Config/MetricsConfig.php @@ -4,9 +4,6 @@ namespace Phauthentic\CognitiveCodeAnalysis\Config; -/** - * - */ class MetricsConfig { public function __construct( diff --git a/src/PhpParser/AnnotationVisitor.php b/src/PhpParser/AnnotationVisitor.php index 3ac2bb3..1f84577 100644 --- a/src/PhpParser/AnnotationVisitor.php +++ b/src/PhpParser/AnnotationVisitor.php @@ -57,9 +57,11 @@ private function hasIgnoreAnnotation(Node $node): bool */ private function setCurrentNamespace(Node $node): void { - if ($node instanceof Node\Stmt\Namespace_) { - $this->currentNamespace = $node->name instanceof Node\Name ? $node->name->toString() : ''; + if (!($node instanceof Node\Stmt\Namespace_)) { + return; } + + $this->currentNamespace = $node->name instanceof Node\Name ? $node->name->toString() : ''; } /** @@ -67,12 +69,16 @@ private function setCurrentNamespace(Node $node): void */ private function setCurrentClass(Node $node): void { - if ($node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Trait_) { - if ($node->name !== null) { - $fqcn = $this->currentNamespace . '\\' . $node->name->toString(); - $this->currentClassName = $this->normalizeFqcn($fqcn); - } + if (!($node instanceof Node\Stmt\Class_) && !($node instanceof Node\Stmt\Trait_)) { + return; + } + + if ($node->name === null) { + return; } + + $fqcn = $this->currentNamespace . '\\' . $node->name->toString(); + $this->currentClassName = $this->normalizeFqcn($fqcn); } /** @@ -92,9 +98,11 @@ private function processClassNode(Node $node): void return; } - if ($this->hasIgnoreAnnotation($node)) { - $this->ignoredClasses[$this->currentClassName] = $this->currentClassName; + if (!$this->hasIgnoreAnnotation($node)) { + return; } + + $this->ignoredClasses[$this->currentClassName] = $this->currentClassName; } /** @@ -111,10 +119,12 @@ private function processMethodNode(Node $node): void return; } - if ($this->hasIgnoreAnnotation($node)) { - $methodKey = $this->currentClassName . '::' . $node->name->toString(); - $this->ignoredMethods[$methodKey] = $methodKey; + if (!$this->hasIgnoreAnnotation($node)) { + return; } + + $methodKey = $this->currentClassName . '::' . $node->name->toString(); + $this->ignoredMethods[$methodKey] = $methodKey; } public function enterNode(Node $node): void @@ -131,9 +141,11 @@ public function leaveNode(Node $node): void $this->currentNamespace = ''; } - if ($node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Trait_) { - $this->currentClassName = ''; + if (!($node instanceof Node\Stmt\Class_) && !($node instanceof Node\Stmt\Trait_)) { + return; } + + $this->currentClassName = ''; } /** diff --git a/src/PhpParser/CognitiveMetricsVisitor.php b/src/PhpParser/CognitiveMetricsVisitor.php index 5745332..4a7eebc 100644 --- a/src/PhpParser/CognitiveMetricsVisitor.php +++ b/src/PhpParser/CognitiveMetricsVisitor.php @@ -5,7 +5,6 @@ namespace Phauthentic\CognitiveCodeAnalysis\PhpParser; use PhpParser\Node; -use PhpParser\NodeTraverser; use PhpParser\NodeVisitor; use PhpParser\NodeVisitorAbstract; @@ -177,9 +176,11 @@ private function initializeMethodContext(Node\Stmt\ClassMethod $node): void private function trackMethodArguments(Node\Stmt\ClassMethod $node): void { foreach ($node->params as $param) { - if ($this->isVariable($param->var)) { - $this->methodArguments[$param->var->name] = true; + if (!$this->isVariable($param->var)) { + continue; } + + $this->methodArguments[$param->var->name] = true; } } @@ -218,9 +219,11 @@ private function countMethodArguments(Node\Stmt\ClassMethod $node): int private function setCurrentNamespaceOnEnterNode(Node $node): void { - if ($node instanceof Node\Stmt\Namespace_) { - $this->currentNamespace = $node->name instanceof Node\Name ? $node->name->toString() : ''; + if (!($node instanceof Node\Stmt\Namespace_)) { + return; } + + $this->currentNamespace = $node->name instanceof Node\Name ? $node->name->toString() : ''; } /** @@ -325,9 +328,11 @@ private function incrementReturnCount(): void */ private function countVariablesNotAlreadyTrackedAsArguments(Node\Expr\Variable $node): void { - if (is_string($node->name) && !isset($this->methodArguments[$node->name])) { - $this->currentVariables[$node->name] = true; + if (!is_string($node->name) || isset($this->methodArguments[$node->name])) { + return; } + + $this->currentVariables[$node->name] = true; } private function trackPropertyFetch(Node\Expr\PropertyFetch $node): void @@ -340,10 +345,12 @@ private function trackPropertyFetch(Node\Expr\PropertyFetch $node): void $property = $node->name->toString(); // Only track new properties to avoid duplicates - if (!isset($this->accessedProperties[$property])) { - $this->accessedProperties[$property] = true; - $this->propertyCalls++; + if (isset($this->accessedProperties[$property])) { + return; } + + $this->accessedProperties[$property] = true; + $this->propertyCalls++; } private function trackIfStatement(): void @@ -351,9 +358,11 @@ private function trackIfStatement(): void $this->ifCount++; $this->currentIfNestingLevel++; - if ($this->currentIfNestingLevel > $this->maxIfNestingLevel) { - $this->maxIfNestingLevel = $this->currentIfNestingLevel; + if ($this->currentIfNestingLevel <= $this->maxIfNestingLevel) { + return; } + + $this->maxIfNestingLevel = $this->currentIfNestingLevel; } private function incrementElseCount(): void @@ -363,9 +372,11 @@ private function incrementElseCount(): void private function checkNestingLevelOnLeaveNode(Node $node): void { - if ($node instanceof Node\Stmt\If_) { - $this->currentIfNestingLevel--; + if (!($node instanceof Node\Stmt\If_)) { + return; } + + $this->currentIfNestingLevel--; } @@ -411,21 +422,25 @@ private function writeMetricsOnLeaveNode(Node $node): void private function checkNameSpaceOnLeaveNode(Node $node): void { - if ($node instanceof Node\Stmt\Namespace_) { - $this->currentNamespace = ''; + if (!($node instanceof Node\Stmt\Namespace_)) { + return; } + + $this->currentNamespace = ''; } private function checkClassOnLeaveNode(Node $node): void { - if ($this->isClassOrTraitNode($node)) { - if (!empty($this->currentMethod)) { - // Don't clear the class context if we're still processing a method - return; - } + if (!$this->isClassOrTraitNode($node)) { + return; + } - $this->currentClassName = ''; + if (!empty($this->currentMethod)) { + // Don't clear the class context if we're still processing a method + return; } + + $this->currentClassName = ''; } public function leaveNode(Node $node): void @@ -442,9 +457,11 @@ public function getMethodMetrics(): array $completeMetrics = []; foreach ($this->methodMetrics as $methodKey => $metrics) { // Ensure the method key contains a class name and method name (not just ::method or ClassName::) - if (strpos($methodKey, '::') > 0 && !str_starts_with($methodKey, '::') && !str_ends_with($methodKey, '::')) { - $completeMetrics[$methodKey] = $metrics; + if (strpos($methodKey, '::') <= 0 || str_starts_with($methodKey, '::') || str_ends_with($methodKey, '::')) { + continue; } + + $completeMetrics[$methodKey] = $metrics; } return $completeMetrics; diff --git a/src/PhpParser/CyclomaticComplexityVisitor.php b/src/PhpParser/CyclomaticComplexityVisitor.php index e9c95fa..b6a6a3b 100644 --- a/src/PhpParser/CyclomaticComplexityVisitor.php +++ b/src/PhpParser/CyclomaticComplexityVisitor.php @@ -116,9 +116,11 @@ public function enterNode(Node $node): void $this->setCurrentClassOnEnterNode($node); $this->handleClassMethodEnter($node); - if ($this->currentMethod) { - $this->countDecisionPoints($node); + if (!$this->currentMethod) { + return; } + + $this->countDecisionPoints($node); } public function leaveNode(Node $node): void @@ -130,27 +132,33 @@ public function leaveNode(Node $node): void private function setCurrentNamespaceOnEnterNode(Node $node): void { - if ($node instanceof Node\Stmt\Namespace_) { - $this->currentNamespace = $node->name instanceof Node\Name ? $node->name->toString() : ''; + if (!($node instanceof Node\Stmt\Namespace_)) { + return; } + + $this->currentNamespace = $node->name instanceof Node\Name ? $node->name->toString() : ''; } private function setCurrentClassOnEnterNode(Node $node): void { - if ($node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Trait_) { - if ($node->name !== null) { - $fqcn = $this->currentNamespace . '\\' . $node->name->toString(); - $this->currentClassName = $this->normalizeFqcn($fqcn); + if (!($node instanceof Node\Stmt\Class_) && !($node instanceof Node\Stmt\Trait_)) { + return; + } - // Check if this class should be ignored - if ($this->annotationVisitor !== null && $this->annotationVisitor->isClassIgnored($this->currentClassName)) { - $this->currentClassName = ''; // Clear the class name if ignored - return; - } + if ($node->name === null) { + return; + } - $this->classComplexity[$this->currentClassName] = 1; // Base complexity for class or trait - } + $fqcn = $this->currentNamespace . '\\' . $node->name->toString(); + $this->currentClassName = $this->normalizeFqcn($fqcn); + + // Check if this class should be ignored + if ($this->annotationVisitor !== null && $this->annotationVisitor->isClassIgnored($this->currentClassName)) { + $this->currentClassName = ''; // Clear the class name if ignored + return; } + + $this->classComplexity[$this->currentClassName] = 1; // Base complexity for class or trait } private function normalizeFqcn(string $fqcn): string @@ -164,22 +172,24 @@ private function normalizeFqcn(string $fqcn): string private function handleClassMethodEnter(Node $node): void { - if ($node instanceof Node\Stmt\ClassMethod) { - // Skip methods that don't have a class or trait context (interfaces, global functions) - if (empty($this->currentClassName)) { - return; - } + if (!($node instanceof Node\Stmt\ClassMethod)) { + return; + } - $methodKey = $this->currentClassName . '::' . $node->name->toString(); + // Skip methods that don't have a class or trait context (interfaces, global functions) + if (empty($this->currentClassName)) { + return; + } - // Check if this method should be ignored - if ($this->annotationVisitor !== null && $this->annotationVisitor->isMethodIgnored($methodKey)) { - return; - } + $methodKey = $this->currentClassName . '::' . $node->name->toString(); - $this->currentMethod = $node->name->toString(); - $this->resetMethodCounters(); + // Check if this method should be ignored + if ($this->annotationVisitor !== null && $this->annotationVisitor->isMethodIgnored($methodKey)) { + return; } + + $this->currentMethod = $node->name->toString(); + $this->resetMethodCounters(); } private function countDecisionPoints(Node $node): void @@ -289,60 +299,66 @@ private function countTernary(): void private function handleClassMethodLeave(Node $node): void { - if ($node instanceof Node\Stmt\ClassMethod) { - // Skip methods that don't have a class context (interfaces, traits, global functions) - if (empty($this->currentClassName)) { - $this->currentMethod = ''; - return; - } + if (!($node instanceof Node\Stmt\ClassMethod)) { + return; + } - $methodKey = "{$this->currentClassName}::{$this->currentMethod}"; - - // Store method complexity - $this->methodComplexity[$methodKey] = $this->currentMethodComplexity; - - // Store detailed breakdown - $this->methodComplexityBreakdown[$methodKey] = [ - 'total' => $this->currentMethodComplexity, - 'base' => 1, - 'if' => $this->ifCount, - 'elseif' => $this->elseIfCount, - 'else' => $this->elseCount, - 'switch' => $this->switchCount, - 'case' => $this->caseCount, - 'default' => $this->defaultCount, - 'while' => $this->whileCount, - 'do_while' => $this->doWhileCount, - 'for' => $this->forCount, - 'foreach' => $this->foreachCount, - 'catch' => $this->catchCount, - 'logical_and' => $this->logicalAndCount, - 'logical_or' => $this->logicalOrCount, - 'logical_xor' => $this->logicalXorCount, - 'ternary' => $this->ternaryCount, - ]; + // Skip methods that don't have a class context (interfaces, traits, global functions) + if (empty($this->currentClassName)) { + $this->currentMethod = ''; + return; + } - // Add method complexity to class complexity - if (isset($this->classComplexity[$this->currentClassName])) { - $this->classComplexity[$this->currentClassName] += $this->currentMethodComplexity; - } + $methodKey = "{$this->currentClassName}::{$this->currentMethod}"; + + // Store method complexity + $this->methodComplexity[$methodKey] = $this->currentMethodComplexity; + + // Store detailed breakdown + $this->methodComplexityBreakdown[$methodKey] = [ + 'total' => $this->currentMethodComplexity, + 'base' => 1, + 'if' => $this->ifCount, + 'elseif' => $this->elseIfCount, + 'else' => $this->elseCount, + 'switch' => $this->switchCount, + 'case' => $this->caseCount, + 'default' => $this->defaultCount, + 'while' => $this->whileCount, + 'do_while' => $this->doWhileCount, + 'for' => $this->forCount, + 'foreach' => $this->foreachCount, + 'catch' => $this->catchCount, + 'logical_and' => $this->logicalAndCount, + 'logical_or' => $this->logicalOrCount, + 'logical_xor' => $this->logicalXorCount, + 'ternary' => $this->ternaryCount, + ]; - $this->currentMethod = ''; + // Add method complexity to class complexity + if (isset($this->classComplexity[$this->currentClassName])) { + $this->classComplexity[$this->currentClassName] += $this->currentMethodComplexity; } + + $this->currentMethod = ''; } private function checkNamespaceLeave(Node $node): void { - if ($node instanceof Node\Stmt\Namespace_) { - $this->currentNamespace = ''; + if (!($node instanceof Node\Stmt\Namespace_)) { + return; } + + $this->currentNamespace = ''; } private function checkClassLeave(Node $node): void { - if ($node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Trait_) { - $this->currentClassName = ''; + if (!($node instanceof Node\Stmt\Class_) && !($node instanceof Node\Stmt\Trait_)) { + return; } + + $this->currentClassName = ''; } /** @@ -409,9 +425,11 @@ public function getComplexitySummary(): array if ($complexity >= 10) { $summary['high_risk_methods'][$methodKey] = $complexity; } - if ($complexity >= 15) { - $summary['very_high_risk_methods'][$methodKey] = $complexity; + if ($complexity < 15) { + continue; } + + $summary['very_high_risk_methods'][$methodKey] = $complexity; } return $summary; diff --git a/src/PhpParser/HalsteadMetricsVisitor.php b/src/PhpParser/HalsteadMetricsVisitor.php index 8186ea1..c838f5c 100644 --- a/src/PhpParser/HalsteadMetricsVisitor.php +++ b/src/PhpParser/HalsteadMetricsVisitor.php @@ -71,12 +71,14 @@ public function enterNode(Node $node) // Check if this class should be ignored if ( - $this->currentClassName !== null - && $this->annotationVisitor !== null - && $this->annotationVisitor->isClassIgnored($this->currentClassName) + $this->currentClassName === null + || $this->annotationVisitor === null + || !$this->annotationVisitor->isClassIgnored($this->currentClassName) ) { - $this->currentClassName = null; // Clear the class name if ignored + return; } + + $this->currentClassName = null; // Clear the class name if ignored }, $node instanceof Node\Stmt\ClassMethod => function () use ($node) { // Skip methods that don't have a class or trait context (interfaces, global functions) @@ -97,22 +99,28 @@ public function enterNode(Node $node) }, $this->isOperator($node) => function () use ($node) { $this->addOperator($node); - if ($this->currentMethodName !== null) { - $this->methodOperators[] = $node->getType(); + if ($this->currentMethodName === null) { + return; } + + $this->methodOperators[] = $node->getType(); }, $this->isOperand($node) => function () use ($node) { $this->addOperand($node); - if ($this->currentMethodName !== null) { - $this->methodOperands[] = $this->getOperandValue($node); + if ($this->currentMethodName === null) { + return; } + + $this->methodOperands[] = $this->getOperandValue($node); }, default => null, }; - if ($result !== null) { - $result(); + if ($result === null) { + return; } + + $result(); } private function setCurrentNamespace(Namespace_ $node): void @@ -175,9 +183,11 @@ public function leaveNode(Node $node) $this->resetMetrics(); } - if ($node instanceof Namespace_) { - $this->currentNamespace = ''; + if (!($node instanceof Namespace_)) { + return; } + + $this->currentNamespace = ''; } private function isOperator(Node $node): bool @@ -215,9 +225,11 @@ private function getOperandValue(Node $node): string private function storeClassMetrics(): void { - if ($this->currentClassName !== null) { - $this->classMetrics[$this->currentClassName] = $this->calculateMetrics(); + if ($this->currentClassName === null) { + return; } + + $this->classMetrics[$this->currentClassName] = $this->calculateMetrics(); } public function resetMetrics(): void diff --git a/tests/Unit/Business/Churn/ChurnCalculatorTest.php b/tests/Unit/Business/Churn/ChurnCalculatorTest.php index b754b6b..7a69d74 100644 --- a/tests/Unit/Business/Churn/ChurnCalculatorTest.php +++ b/tests/Unit/Business/Churn/ChurnCalculatorTest.php @@ -10,9 +10,6 @@ use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\CognitiveMetricsCollection; use PHPUnit\Framework\TestCase; -/** - * - */ class ChurnCalculatorTest extends TestCase { public function testCalculate(): void diff --git a/tests/Unit/Business/Churn/Exporter/AbstractExporterTestCase.php b/tests/Unit/Business/Churn/Exporter/AbstractExporterTestCase.php index 09932d9..38b3f91 100644 --- a/tests/Unit/Business/Churn/Exporter/AbstractExporterTestCase.php +++ b/tests/Unit/Business/Churn/Exporter/AbstractExporterTestCase.php @@ -7,9 +7,6 @@ use Phauthentic\CognitiveCodeAnalysis\Business\Utility\Datetime; use PHPUnit\Framework\TestCase; -/** - * - */ class AbstractExporterTestCase extends TestCase { protected string $filename; diff --git a/tests/Unit/Business/Churn/Exporter/CsvExportTest.php b/tests/Unit/Business/Churn/Exporter/CsvExportTest.php index 68b002e..7021f3e 100644 --- a/tests/Unit/Business/Churn/Exporter/CsvExportTest.php +++ b/tests/Unit/Business/Churn/Exporter/CsvExportTest.php @@ -8,9 +8,6 @@ use Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException; use PHPUnit\Framework\Attributes\Test; -/** - * - */ class CsvExportTest extends AbstractExporterTestCase { protected function setUp(): void diff --git a/tests/Unit/Business/Churn/Exporter/HtmlExporterTest.php b/tests/Unit/Business/Churn/Exporter/HtmlExporterTest.php index b0c8798..f0eb245 100644 --- a/tests/Unit/Business/Churn/Exporter/HtmlExporterTest.php +++ b/tests/Unit/Business/Churn/Exporter/HtmlExporterTest.php @@ -7,9 +7,6 @@ use Phauthentic\CognitiveCodeAnalysis\Business\Churn\Exporter\CsvExporter; use PHPUnit\Framework\Attributes\Test; -/** - * - */ class HtmlExporterTest extends AbstractExporterTestCase { protected function setUp(): void diff --git a/tests/Unit/Business/Churn/Exporter/JsonExporterTest.php b/tests/Unit/Business/Churn/Exporter/JsonExporterTest.php index e996bed..81dd872 100644 --- a/tests/Unit/Business/Churn/Exporter/JsonExporterTest.php +++ b/tests/Unit/Business/Churn/Exporter/JsonExporterTest.php @@ -7,9 +7,6 @@ use Phauthentic\CognitiveCodeAnalysis\Business\Churn\Exporter\JsonExporter; use PHPUnit\Framework\Attributes\Test; -/** - * - */ class JsonExporterTest extends AbstractExporterTestCase { protected function setUp(): void diff --git a/tests/Unit/Business/Churn/Exporter/MarkdownExporterTest.php b/tests/Unit/Business/Churn/Exporter/MarkdownExporterTest.php index 23568f1..9726886 100644 --- a/tests/Unit/Business/Churn/Exporter/MarkdownExporterTest.php +++ b/tests/Unit/Business/Churn/Exporter/MarkdownExporterTest.php @@ -7,9 +7,6 @@ use Phauthentic\CognitiveCodeAnalysis\Business\Churn\Exporter\MarkdownExporter; use PHPUnit\Framework\Attributes\Test; -/** - * - */ class MarkdownExporterTest extends AbstractExporterTestCase { protected function setUp(): void diff --git a/tests/Unit/Business/Churn/Exporter/SvgTreemapExporterTest.php b/tests/Unit/Business/Churn/Exporter/SvgTreemapExporterTest.php index 0d532cd..8fba35e 100644 --- a/tests/Unit/Business/Churn/Exporter/SvgTreemapExporterTest.php +++ b/tests/Unit/Business/Churn/Exporter/SvgTreemapExporterTest.php @@ -7,9 +7,6 @@ use Phauthentic\CognitiveCodeAnalysis\Business\Churn\Exporter\SvgTreemapExporter; use PHPUnit\Framework\Attributes\Test; -/** - * - */ class SvgTreemapExporterTest extends AbstractExporterTestCase { protected function setUp(): void diff --git a/tests/Unit/Business/Cognitive/BaselineServiceTest.php b/tests/Unit/Business/Cognitive/BaselineServiceTest.php index 6d0d32c..67c76ff 100644 --- a/tests/Unit/Business/Cognitive/BaselineServiceTest.php +++ b/tests/Unit/Business/Cognitive/BaselineServiceTest.php @@ -5,17 +5,11 @@ namespace Phauthentic\CognitiveCodeAnalysis\Tests\Unit\Business\Cognitive; use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Baseline; -use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\CognitiveMetrics; -use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\CognitiveMetricsCollection; use Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use RuntimeException; use JsonException; -/** - * - */ class BaselineServiceTest extends TestCase { protected Baseline $baselineService; diff --git a/tests/Unit/Business/Cognitive/CognitiveMetricsCollectionTest.php b/tests/Unit/Business/Cognitive/CognitiveMetricsCollectionTest.php index 99278ed..4817f19 100644 --- a/tests/Unit/Business/Cognitive/CognitiveMetricsCollectionTest.php +++ b/tests/Unit/Business/Cognitive/CognitiveMetricsCollectionTest.php @@ -5,7 +5,6 @@ namespace Phauthentic\CognitiveCodeAnalysis\Tests\Unit\Business\Cognitive; use ArrayIterator; -use InvalidArgumentException; use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\CognitiveMetrics; use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\CognitiveMetricsCollection; use PHPUnit\Framework\Attributes\Test; diff --git a/tests/Unit/Business/Cognitive/CognitiveMetricsCollectorTest.php b/tests/Unit/Business/Cognitive/CognitiveMetricsCollectorTest.php index 2637e8d..a2f62af 100644 --- a/tests/Unit/Business/Cognitive/CognitiveMetricsCollectorTest.php +++ b/tests/Unit/Business/Cognitive/CognitiveMetricsCollectorTest.php @@ -20,9 +20,6 @@ use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\MessageBusInterface; -/** - * - */ class CognitiveMetricsCollectorTest extends TestCase { private CognitiveMetricsCollector $metricsCollector; diff --git a/tests/Unit/Business/Cognitive/CognitiveMetricsTest.php b/tests/Unit/Business/Cognitive/CognitiveMetricsTest.php index 819cfa7..21dd784 100644 --- a/tests/Unit/Business/Cognitive/CognitiveMetricsTest.php +++ b/tests/Unit/Business/Cognitive/CognitiveMetricsTest.php @@ -9,9 +9,6 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -/** - * - */ class CognitiveMetricsTest extends TestCase { private array $testMetricsData; diff --git a/tests/Unit/Business/Cognitive/Exporter/CsvExporterTest.php b/tests/Unit/Business/Cognitive/Exporter/CsvExporterTest.php index 246ab55..bbcfeca 100644 --- a/tests/Unit/Business/Cognitive/Exporter/CsvExporterTest.php +++ b/tests/Unit/Business/Cognitive/Exporter/CsvExporterTest.php @@ -11,9 +11,6 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -/** - * - */ class CsvExporterTest extends TestCase { private CsvExporter $csvExporter; @@ -29,9 +26,11 @@ protected function setUp(): void protected function tearDown(): void { parent::tearDown(); - if (file_exists($this->filename)) { - unlink($this->filename); + if (!file_exists($this->filename)) { + return; } + + unlink($this->filename); } #[Test] diff --git a/tests/Unit/Business/Cognitive/Exporter/HtmlExporterTest.php b/tests/Unit/Business/Cognitive/Exporter/HtmlExporterTest.php index b2efaac..2093c7f 100644 --- a/tests/Unit/Business/Cognitive/Exporter/HtmlExporterTest.php +++ b/tests/Unit/Business/Cognitive/Exporter/HtmlExporterTest.php @@ -11,9 +11,6 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -/** - * - */ class HtmlExporterTest extends TestCase { private HtmlExporter $csvExporter; diff --git a/tests/Unit/Business/Cognitive/ScoreCalculatorTest.php b/tests/Unit/Business/Cognitive/ScoreCalculatorTest.php index 4d185f6..90463a3 100644 --- a/tests/Unit/Business/Cognitive/ScoreCalculatorTest.php +++ b/tests/Unit/Business/Cognitive/ScoreCalculatorTest.php @@ -12,9 +12,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Config\Definition\Processor; -/** - * - */ class ScoreCalculatorTest extends TestCase { private ScoreCalculator $scoreCalculator; diff --git a/tests/Unit/Business/DirectoryScannerTest.php b/tests/Unit/Business/DirectoryScannerTest.php index 6c4c350..e3e5ae1 100644 --- a/tests/Unit/Business/DirectoryScannerTest.php +++ b/tests/Unit/Business/DirectoryScannerTest.php @@ -11,9 +11,6 @@ use RecursiveDirectoryIterator; use RecursiveIteratorIterator; -/** - * - */ class DirectoryScannerTest extends TestCase { private string $testDir = ''; diff --git a/tests/Unit/Command/ChurnCommandTest.php b/tests/Unit/Command/ChurnCommandTest.php index 78f215c..bffa308 100644 --- a/tests/Unit/Command/ChurnCommandTest.php +++ b/tests/Unit/Command/ChurnCommandTest.php @@ -13,9 +13,6 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Tester\CommandTester; -/** - * - */ class ChurnCommandTest extends TestCase { #[Test] diff --git a/tests/Unit/Command/CognitiveMetricsCommandCoverageTest.php b/tests/Unit/Command/CognitiveMetricsCommandCoverageTest.php index a7f9448..8de9326 100644 --- a/tests/Unit/Command/CognitiveMetricsCommandCoverageTest.php +++ b/tests/Unit/Command/CognitiveMetricsCommandCoverageTest.php @@ -109,8 +109,12 @@ public function testAnalyseWithoutCoverageDoesNotShowCoverageColumn(): void #[Test] #[DataProvider('methodLevelCoverageProvider')] - public function testAnalyseShowsMethodLevelCoverage(string $format, string $file, string $zeroMethod, string $fullMethod): void - { + public function testAnalyseShowsMethodLevelCoverage( + string $format, + string $file, + string $zeroMethod, + string $fullMethod + ): void { $application = new Application(); $command = $application->getContainer()->get(CognitiveMetricsCommand::class); $tester = new CommandTester($command); diff --git a/tests/Unit/Command/CognitiveMetricsCommandTest.php b/tests/Unit/Command/CognitiveMetricsCommandTest.php index 832cb9a..c8d6f17 100644 --- a/tests/Unit/Command/CognitiveMetricsCommandTest.php +++ b/tests/Unit/Command/CognitiveMetricsCommandTest.php @@ -11,12 +11,8 @@ use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tester\CommandTester; -/** - * - */ class CognitiveMetricsCommandTest extends TestCase { #[Test] diff --git a/tests/Unit/PhpParser/CognitiveMetricsVisitorTest.php b/tests/Unit/PhpParser/CognitiveMetricsVisitorTest.php index fa89266..e789888 100644 --- a/tests/Unit/PhpParser/CognitiveMetricsVisitorTest.php +++ b/tests/Unit/PhpParser/CognitiveMetricsVisitorTest.php @@ -9,9 +9,6 @@ use Phauthentic\CognitiveCodeAnalysis\PhpParser\CognitiveMetricsVisitor; use PHPUnit\Framework\TestCase; -/** - * - */ class CognitiveMetricsVisitorTest extends TestCase { protected function getTestCode(): string diff --git a/tests/Unit/PhpParser/CyclomaticComplexityVisitorTest.php b/tests/Unit/PhpParser/CyclomaticComplexityVisitorTest.php index 370151c..49b1547 100644 --- a/tests/Unit/PhpParser/CyclomaticComplexityVisitorTest.php +++ b/tests/Unit/PhpParser/CyclomaticComplexityVisitorTest.php @@ -8,9 +8,6 @@ use PhpParser\NodeTraverser; use PHPUnit\Framework\TestCase; -/** - * - */ class CyclomaticComplexityVisitorTest extends TestCase { public function testCyclomaticComplexityCalculation(): void diff --git a/tests/Unit/PhpParser/HalsteadMetricsVisitorTest.php b/tests/Unit/PhpParser/HalsteadMetricsVisitorTest.php index f395c01..d3ab759 100644 --- a/tests/Unit/PhpParser/HalsteadMetricsVisitorTest.php +++ b/tests/Unit/PhpParser/HalsteadMetricsVisitorTest.php @@ -8,9 +8,6 @@ use PhpParser\NodeTraverser; use PHPUnit\Framework\TestCase; -/** - * - */ class HalsteadMetricsVisitorTest extends TestCase { public function testHalsteadMetricsCalculation(): void