From 3abe22ecc683e5d2fd7190991fa78e8132672ea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Fri, 4 Oct 2024 13:10:48 +0200 Subject: [PATCH] Shortening the command --- .gitignore | 4 +-- Makefile | 6 +---- bin/{cognitive-analysis => phpcca} | 0 bin/{cognitive-analysis.bat => phpcca.bat} | 2 +- box.json.dist | 2 +- composer.json | 2 +- config.yml | 2 +- docs/Configuration.md | 30 +++++++++++----------- readme.md | 6 ++--- src/Command/CognitiveMetricsCommand.php | 2 +- 10 files changed, 26 insertions(+), 30 deletions(-) rename bin/{cognitive-analysis => phpcca} (100%) rename bin/{cognitive-analysis.bat => phpcca.bat} (87%) diff --git a/.gitignore b/.gitignore index 1a5f647..89e29e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /vendor/ /bin/ -!/bin/cognitive-analysis -!/bin/cognitive-analysis.bat +!/bin/phpcca +!/bin/phpcca.bat /.phive/ /.phpunit.cache/ /tmp/ diff --git a/Makefile b/Makefile index 64907eb..4c65828 100644 --- a/Makefile +++ b/Makefile @@ -38,11 +38,7 @@ shell: self-test: @echo "Running cognitive analyses self-test" - docker compose run php php analyse.php metrics:cognitive src - -self-test-halstead: - @echo "Running cognitive analyses self-test" - docker compose run php php analyse.php metrics:halstead src + docker compose run php bin/phpcca analyse src build-phar: @echo "Building phar" diff --git a/bin/cognitive-analysis b/bin/phpcca similarity index 100% rename from bin/cognitive-analysis rename to bin/phpcca diff --git a/bin/cognitive-analysis.bat b/bin/phpcca.bat similarity index 87% rename from bin/cognitive-analysis.bat rename to bin/phpcca.bat index 6e1b1dc..e645059 100755 --- a/bin/cognitive-analysis.bat +++ b/bin/phpcca.bat @@ -9,4 +9,4 @@ if "%PHP_PEAR_PHP_BIN%" neq "" ( set PHPBIN=%PHP_PEAR_PHP_BIN% ) else set PHPBIN=php -"%PHPBIN%" "%~dp0\cognitive-analysis" %* +"%PHPBIN%" "%~dp0\phpcca" %* diff --git a/box.json.dist b/box.json.dist index 9f5c0cb..d3c3463 100644 --- a/box.json.dist +++ b/box.json.dist @@ -1,5 +1,5 @@ { "main": "./analyse.php", "compression": "GZ", - "output": "cognitive-analysis.phar" + "output": "phpcca.phar" } diff --git a/composer.json b/composer.json index b097c41..5a6e7d3 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ } }, "bin": [ - "bin/cognitive-analysis" + "bin/phpcca" ], "scripts": { "test": [ diff --git a/config.yml b/config.yml index dd874fd..2ad4b9e 100644 --- a/config.yml +++ b/config.yml @@ -2,7 +2,7 @@ cognitive: excludeFilePatterns: excludePatterns: scoreThreshold: 0.5 - showOnlyMethodsExceedingThreshold: true + showOnlyMethodsExceedingThreshold: false metrics: lineCount: threshold: 60 diff --git a/docs/Configuration.md b/docs/Configuration.md index f1fc5b5..5aafbc1 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -5,27 +5,39 @@ You can specify another configuration file by passing it to the config options: ```bash -php analyse.php metrics:cognitive --config= +bin/phpcca analyse --config= ``` ## Excluding Classes and Methods You can exclude classes and methods via a regex in the configuration. -The following configuration will exclude all constructors and all methods of classes that end with `Transformer`. +The following configuration will exclude all constructors, `toArray` methods and all methods of classes that end with `Transformer`. ```yaml cognitive: excludePatterns: - '(.*)::__construct' + - '(.*)::toArray' - '(.*)Transformer::(.*)' ``` +## Exclude Files + +You can exclude files via a regex in the configuration. + +```yaml +cognitive: + excludeFilePatterns: + - '.*Cognitive.*' + - '(.*)Test.php' +``` + ## Tuning the calculation The configuration file can contain the following settings for the calculation of cognitive complexity. -Feel free to adjust the values to your match your opinion on what makes code complex. +Feel free to adjust the values to your match **your opinion** on what makes code complex. It is recommended to play with the values until you get weights that you are comfortable with. The default values are a good starting point. ```yaml cognitive: @@ -55,15 +67,3 @@ cognitive: threshold: 1 scale: 1.0 ``` - -It is recommended to play with the values until you get weights that you are comfortable with. The default values are a good starting point. - -## Excluding Files - -Regular expression patterns can be defined to exclude files from the analysis. - -```yaml -cognitive: - excludeFilePatterns: - - '(.*)Test.php' -``` diff --git a/readme.md b/readme.md index 8d86cd4..a9fa409 100644 --- a/readme.md +++ b/readme.md @@ -11,19 +11,19 @@ Cognitive Code Analysis is an approach to understanding and improving code by fo Cognitive Complexity Analysis ```bash -bin/cognitive-analysis metrics:cognitive +bin/phpcca analyse ``` Generate a report, supported types are `json`, `csv`, `html`. ```bash -bin/cognitive-analysis metrics:cognitive --report-type json --report-file cognitive.json +bin/phpcca analyse --report-type json --report-file cognitive.json ``` You can also pass a baseline file to compare the results to. The JSON report is used as baseline. The output will now show a delta if a value was changed. ```bash -bin/cognitive-analysis metrics:cognitive --baseline cognitive.json +bin/phpcca analyse --baseline cognitive.json ``` ## Documentation diff --git a/src/Command/CognitiveMetricsCommand.php b/src/Command/CognitiveMetricsCommand.php index 3c34356..50d871d 100644 --- a/src/Command/CognitiveMetricsCommand.php +++ b/src/Command/CognitiveMetricsCommand.php @@ -19,7 +19,7 @@ * Command to parse PHP files or directories and output method metrics. */ #[AsCommand( - name: 'metrics:cognitive', + name: 'analyse', description: 'Parse PHP files or directories and output method metrics.' )] class CognitiveMetricsCommand extends Command