Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/Churn-Finding-Hotspots.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ bin/phpcca churn <path-to-folder> [--config=<file>] [--git=<vcs>] [--debug]

- `<path-to-folder>`: **Required.** Path to the PHP file or directory to analyze.
- `--config, -c`: Path to a configuration file (optional).
- `--git, -s`: Version control system to use for change detection (default: `git`).
- `--vcs, -s`: Version control system to use for change detection (default: `git`).
- `--debug`: Enables debug output.

## What it does

1. **Collects cognitive metrics** for each class in the given path.
2. **Counts how many times each file/class has changed** using your VCS (default: Git).
3. **Calculates a churn score**:
3. **Calculates a churn score**:
`churn = timesChanged * score`
4. **Ranks classes by churn score** so you can focus on the most critical hotspots.

⚠️ **For the time being only Git is supported as the VCS backend!** ⚠️

## Example Output

```
Expand All @@ -43,4 +45,3 @@ bin/phpcca churn <path-to-folder> [--config=<file>] [--git=<vcs>] [--debug]
- Only classes with a valid class name are included in the results.
- The command supports extensible VCS backends (default is Git).
- For now only Git is supported.

10 changes: 9 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Cognitive Code Analysis is an approach to understanding and improving code by fo

[Source: Human Cognitive Limitations. Broad, Consistent, Clinical Application of Physiological Principles Will Require Decision Support](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5822395/)

## Installation

```bash
composer require --dev phauthentic/cognitive-code-analysis
```

## Running it

Cognitive Complexity Analysis
Expand All @@ -28,7 +34,9 @@ bin/phpcca analyse <path-to-folder> --baseline cognitive.json

### Finding Hotspots

Churn is a measure of how much code has changed over time. It helps to find the most changed and complex areas in your codebase, which are often the most error-prone and difficult to maintain.
Churn is a measure of how much code has changed over time. It helps to find the most changed and complex areas in your codebase, which are often the most error-prone and difficult to maintain. Read the [Churn - Finding Hotspots](./docs/Churn-Finding-Hotspots.md) documentation for more details.

Note that this requires a version control system (VCS) to be set up, such as Git.

```bash
bin/phpcca churn <path-to-folder>
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ChurnCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ChurnCommand extends Command

public const OPTION_CONFIG_FILE = 'config';

public const OPTION_VCS = 'git';
public const OPTION_VCS = 'vcs';

public const OPTION_DEBUG = 'debug';

Expand Down