Skip to content

Commit 36a2acd

Browse files
Adding Analysis Action and Fixes to the Configuration (#72)
* Enhance report generation with new CI formats and refactor Markdown handling - Added support for new CI report formats: Checkstyle, JUnit, SARIF, GitLab Code Quality, and GitHub Actions. - Improved HTML and Markdown report generation with a single table configuration option. - Refactored MarkdownReport for better file handling and class section management, enhancing code readability and maintainability. - Updated tests to validate new report formats and configurations. * Update output files to include configuration and cache status - Added configuration file paths and cache status to various output files for improved clarity and debugging. - Updated output formats for all relevant test cases to reflect the new configuration and cache information. * Refactor configuration management and update file references - Replaced instances of `config.yml` with `phpcca.yaml` across the codebase to standardize configuration file usage. - Introduced a new `phpcca.yaml` file containing cognitive metrics configuration settings. - Updated README.md to reflect the new copyright format. - Adjusted GitHub Actions workflow to utilize the new configuration file. * Update configuration file references to phpcca.yaml - Changed all instances of cca.yaml to phpcca.yaml across documentation and codebase for consistency. - Updated README.md, CI-Integration.md, and Configuration.md to reflect the new configuration file name. - Modified InitCommand and related tests to create and reference phpcca.yaml instead of cca.yaml. * Update cognitive metrics configuration in phpcca.yaml - Changed the setting for showOnlyMethodsExceedingThreshold from false to true to enhance cognitive metrics reporting. * Refactor CognitiveMetricsCommandCoverageTest to use a centralized test configuration method - Introduced a private method `withTestConfig` to streamline the execution of tests with a specified configuration file. - Updated all test cases in `CognitiveMetricsCommandCoverageTest` to utilize the new method for improved readability and maintainability.
1 parent 9979ef5 commit 36a2acd

22 files changed

Lines changed: 102 additions & 38 deletions
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Cognitive Code Analysis
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**/*.php'
7+
8+
permissions:
9+
pull-requests: write
10+
contents: read
11+
12+
jobs:
13+
analyse:
14+
name: Cognitive Code Analysis
15+
runs-on: ubuntu-24.04
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- uses: Phauthentic/cognitive-code-analysis-github-action@v1
22+
with:
23+
install-mode: phar
24+
config: phpcca.yaml
25+
post-comment: true
26+
upload-artifact: true
27+
emit-annotations: true
28+
upload-sarif: false
29+
fail-on-threshold: false

box.json.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"KevinGH\\Box\\Compactor\\PhpScoper"
1010
],
1111
"files": [
12-
"config.yml",
12+
"phpcca.yaml",
1313
"composer.json",
1414
"readme.md",
1515
"LICENSE"

docs/CI-Integration.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A typical CI integration follows these steps:
1313
3. Run `bin/phpcca analyse` on those files only
1414
4. Publish the report (Markdown comment, SARIF upload, or quality gate)
1515

16-
When `cca.yaml` exists in the project root, `analyse` loads it automatically. Use `--config=path/to/config.yaml` to override.
16+
When `phpcca.yaml` exists in the project root, `analyse` loads it automatically. Use `--config=path/to/config.yaml` to override.
1717

1818
## Report formats for CI
1919

@@ -38,7 +38,7 @@ See [Baseline Analysis](./Baseline-Analysis.md) to compare metrics against a pre
3838

3939
The workflow below runs on pull requests, analyses changed PHP files, posts a Markdown report as a PR comment, and uploads the report as an artifact.
4040

41-
Add `--config=cca.yaml` if your config file is not named `cca.yaml` or not in the working directory.
41+
Add `--config=phpcca.yaml` if your config file is not named `phpcca.yaml` or not in the working directory.
4242

4343
```yaml
4444
name: Code Metrics
@@ -142,7 +142,7 @@ Then upload `results.sarif` using the [GitHub Code Scanning upload action](https
142142

143143
The job below runs on merge requests, analyses changed PHP files, posts a Markdown report as an MR note, and stores the report as an artifact.
144144

145-
Use `--config=cca.yaml` when your config file is not auto-discovered from the project root.
145+
Use `--config=phpcca.yaml` when your config file is not auto-discovered from the project root.
146146

147147
```yaml
148148
Code-Metrics:
@@ -166,7 +166,7 @@ Code-Metrics:
166166
CHANGED_FILES=$(find src/ -name "*.php" | tr '\n' ' ')
167167
fi
168168
if [ -n "$CHANGED_FILES" ]; then
169-
bin/phpcca analyse $CHANGED_FILES --report-type=markdown --report-file=cca-report.md --config=cca.yaml
169+
bin/phpcca analyse $CHANGED_FILES --report-type=markdown --report-file=cca-report.md --config=phpcca.yaml
170170
if [ -f "cca-report.md" ] && [ -s "cca-report.md" ]; then
171171
# Try with CI_JOB_TOKEN first, fallback to CI/CD variables
172172
if [ -n "$VALIDATOR" ]; then
@@ -237,7 +237,7 @@ GitLab picks up the Code Quality report automatically when configured in your pi
237237

238238
## Related
239239

240-
- [Configuration](./Configuration.md) — project setup with `bin/phpcca init` and `cca.yaml`
240+
- [Configuration](./Configuration.md) — project setup with `bin/phpcca init` and `phpcca.yaml`
241241
- [Baseline Analysis](./Baseline-Analysis.md) — track complexity changes over time
242242
- [Creating Custom Reporters](./Creating-Custom-Reporters.md) — extend report output for custom CI integrations
243243
- [Issue #29](https://github.com/Phauthentic/cognitive-code-analysis/issues/29) — original feature discussion for GitHub Actions and branch comparison

docs/Configuration.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
## Creating a configuration file
44

5-
Run `init` to create a `cca.yaml` in your project:
5+
Run `init` to create a `phpcca.yaml` in your project:
66

77
```bash
88
bin/phpcca init
99
bin/phpcca init --silent
10-
bin/phpcca init --path=/path/to/cca.yaml
10+
bin/phpcca init --path=/path/to/phpcca.yaml
1111
```
1212

13-
When `cca.yaml` exists in the working directory, `analyse` and `churn` pick it up automatically. You only need `--config` for a custom path or filename.
13+
When `phpcca.yaml` exists in the working directory, `analyse` and `churn` pick it up automatically. You only need `--config` for a custom path or filename.
1414

1515
## Passing a configuration file
1616

@@ -20,7 +20,7 @@ You can specify another configuration file by passing it to the config options:
2020
bin/phpcca analyse <path-to-folder> --config=<path-to-config-file>
2121
```
2222

23-
When both `cca.yaml` and `--config` are available, the explicit `--config` path takes precedence.
23+
When both `phpcca.yaml` and `--config` are available, the explicit `--config` path takes precedence.
2424

2525
## Excluding Classes and Methods
2626

config.yml renamed to phpcca.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cognitive:
22
excludeFilePatterns:
33
excludePatterns:
44
scoreThreshold: 0.5
5-
showOnlyMethodsExceedingThreshold: false
5+
showOnlyMethodsExceedingThreshold: true
66
showHalsteadComplexity: false
77
showCyclomaticComplexity: false
88
showDetailedCognitiveMetrics: true

readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ composer require --dev phauthentic/cognitive-code-analysis
3737
Create a project configuration file:
3838

3939
```bash
40-
bin/phpcca init # interactive setup → creates cca.yaml in current directory
40+
bin/phpcca init # interactive setup → creates phpcca.yaml in current directory
4141
bin/phpcca init --silent # non-interactive, all defaults
42-
bin/phpcca init --path=/path/to/cca.yaml
42+
bin/phpcca init --path=/path/to/phpcca.yaml
4343
```
4444

45-
When `cca.yaml` exists in the current working directory, `analyse` and `churn` load it automatically. Use `--config` to specify a different file.
45+
When `phpcca.yaml` exists in the current working directory, `analyse` and `churn` load it automatically. Use `--config` to specify a different file.
4646

4747
Cognitive Complexity Analysis
4848

@@ -163,6 +163,6 @@ Especially the AST-parser used under the hood to analyse the code might have iss
163163

164164
## License ⚖️
165165

166-
Copyright Florian Krämer
166+
Copyright [Florian Krämer](https://florian-kraemer.net/)
167167

168168
Licensed under the [GPL3 license](LICENSE).

src/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ private function registerUtilityServices(): void
192192
->setArguments([
193193
new Reference(Processor::class),
194194
new Reference(ConfigLoader::class),
195-
__DIR__ . '/../config.yml',
195+
__DIR__ . '/../phpcca.yaml',
196196
])
197197
->setPublic(true);
198198

src/Command/InitCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#[AsCommand(
1818
name: 'init',
19-
description: 'Create a default cca.yaml for cognitive code analysis.'
19+
description: 'Create a default phpcca.yaml for cognitive code analysis.'
2020
)]
2121
class InitCommand extends Command
2222
{

src/Config/ConfigFileResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class ConfigFileResolver
88
{
9-
public const DEFAULT_FILENAME = 'cca.yaml';
9+
public const DEFAULT_FILENAME = 'phpcca.yaml';
1010

1111
public function resolve(?string $explicitConfigPath): ?string
1212
{

src/Config/ConfigService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(
2727
private function loadDefaultConfig(): void
2828
{
2929
$config = $this->processor->processConfiguration($this->configuration, [
30-
Yaml::parseFile(__DIR__ . '/../../config.yml'),
30+
Yaml::parseFile(__DIR__ . '/../../phpcca.yaml'),
3131
]);
3232

3333
$this->config = (new ConfigFactory())->fromArray($config);
@@ -38,7 +38,7 @@ private function loadDefaultConfig(): void
3838
*/
3939
public function loadConfig(string $configFilePath): void
4040
{
41-
$defaultConfig = Yaml::parseFile(__DIR__ . '/../../config.yml');
41+
$defaultConfig = Yaml::parseFile(__DIR__ . '/../../phpcca.yaml');
4242
$providedConfig = Yaml::parseFile($configFilePath);
4343

4444
$config = $this->processor->processConfiguration($this->configuration, [

0 commit comments

Comments
 (0)