Skip to content

Commit

Permalink
Shortening the command
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankraemer committed Oct 4, 2024
1 parent f9960bf commit 3abe22e
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/vendor/
/bin/
!/bin/cognitive-analysis
!/bin/cognitive-analysis.bat
!/bin/phpcca
!/bin/phpcca.bat
/.phive/
/.phpunit.cache/
/tmp/
Expand Down
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion bin/cognitive-analysis.bat → bin/phpcca.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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" %*
2 changes: 1 addition & 1 deletion box.json.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"main": "./analyse.php",
"compression": "GZ",
"output": "cognitive-analysis.phar"
"output": "phpcca.phar"
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}
},
"bin": [
"bin/cognitive-analysis"
"bin/phpcca"
],
"scripts": {
"test": [
Expand Down
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cognitive:
excludeFilePatterns:
excludePatterns:
scoreThreshold: 0.5
showOnlyMethodsExceedingThreshold: true
showOnlyMethodsExceedingThreshold: false
metrics:
lineCount:
threshold: 60
Expand Down
30 changes: 15 additions & 15 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,39 @@
You can specify another configuration file by passing it to the config options:

```bash
php analyse.php metrics:cognitive <path-to-folder> --config=<path-to-config-file>
bin/phpcca analyse <path-to-folder> --config=<path-to-config-file>
```

## 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:
Expand Down Expand Up @@ -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'
```
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path-to-folder>
bin/phpcca analyse <path-to-folder>
```

Generate a report, supported types are `json`, `csv`, `html`.

```bash
bin/cognitive-analysis metrics:cognitive <path-to-folder> --report-type json --report-file cognitive.json
bin/phpcca analyse <path-to-folder> --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 <path-to-folder> --baseline cognitive.json
bin/phpcca analyse <path-to-folder> --baseline cognitive.json
```

## Documentation
Expand Down
2 changes: 1 addition & 1 deletion src/Command/CognitiveMetricsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3abe22e

Please sign in to comment.