Skip to content

Commit

Permalink
Merge pull request #1 from andrey-tech/ignore-metrics-on-exit
Browse files Browse the repository at this point in the history
Ignore metrics on exit
  • Loading branch information
andrey-tech authored Jul 28, 2024
2 parents 6584331 + 3b17af7 commit 1f06685
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[![Latest Stable Version](https://poser.pugx.org/andrey-tech/pdepend-summary-formatter-php/v)](https://packagist.org/packages/andrey-tech/pdepend-summary-formatter-php)
[![Total Downloads](https://poser.pugx.org/andrey-tech/pdepend-summary-formatter-php/downloads)](//packagist.org/packages/andrey-tech/pdepend-summary-formatter-php)
[![PHP Version Require](http://poser.pugx.org/andrey-tech/pdepend-summary-formatter-php/require/php)](https://packagist.org/packages/andrey-tech/pdepend-summary-formatter-php)
[![PHP Version Require](https://poser.pugx.org/andrey-tech/pdepend-summary-formatter-php/require/php)](https://packagist.org/packages/andrey-tech/pdepend-summary-formatter-php)
[![License](https://poser.pugx.org/andrey-tech/pdepend-summary-formatter-php/license)](https://packagist.org/packages/andrey-tech/pdepend-summary-formatter-php)

Pdepend Summary Formatter is a tool to show software code quality metrics, measured by
Expand Down Expand Up @@ -64,10 +64,12 @@ measured by PHP Depend, in console and to write results to specified text file `

The Pdepend Summary Formatter tool command line interface also accepts the following optional arguments:

- `--init` - Will generate a default config file `pdepend-summary-formatter.yml.dist` in current working directory.
- `--output-file=` - Write results also to the specified text file.
- `--config-file=` - The filepath to a custom config YAML file.
- `--no-colors` - Disable colors in console.
- `--init` — Will generate a default config file `pdepend-summary-formatter.yml.dist` in current working directory.
- `--output-file=` — Write results also to the specified text file.
- `--config-file=` — The filepath to a custom config YAML file.
- `--ignore-red-metrics-on-exit` — Will exit with a zero code, even "red" metrics exist.
- `--ignore-yellow-metrics-on-exit` — Will exit with a zero code, even "yellow" metrics exist.
- `--no-colors` — Disable colors in console.

An example command line of Pdepend Summary Formatter tool and PHP Depend tool:

Expand Down Expand Up @@ -157,7 +159,7 @@ based on [PHP Mess Detector](https://phpmd.org/) (PHPMD) tool.
| vars | [Number of Properties](https://phpmd.org/rules/codesize.html#toomanyfields) | | 15 | 15 | |
| wmc | [Weighted Method Count](https://phpmd.org/rules/codesize.html#excessiveclasscomplexity) | | 50 | 50 | |

Note: ✓ - means there are no defined "red" color boundaries for this metric.
Note: ✓ means there are no defined "red" color boundaries for this metric.

<a id="configuration-yaml-file"></a>
## Configuration YAML file
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"symfony/yaml": "^4.4 || ^5.4 || ^6.3 || ^7.1"
},
"require-dev": {
"overtrue/phplint": "^3.4",
"overtrue/phplint": "^3.4 || ^9.0",
"pdepend/pdepend": "^2.15",
"phpmd/phpmd": "^2.14",
"slevomat/coding-standard": "^8.13",
Expand Down
21 changes: 21 additions & 0 deletions src/AndreyTech/Pdepend/Summary/Formatter/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,27 @@ public function doRun(): int
$exitCode = $this->renderToConsole($metrics);
$this->renderToOutputFile($metrics, $outputFile);

return $this->prepareExitCode($exitCode);
}

private function prepareExitCode(int $exitCode): int
{
if (
$exitCode === self::EXIT_CODE_RED_METRICS
&&
$this->config->handleOptionIgnoreRedMetricsOnExit()
) {
return 0;
}

if (
$exitCode === self::EXIT_CODE_YELLOW_METRICS
&&
$this->config->handleOptionIgnoreYellowMetricsOnExit()
) {
return 0;
}

return $exitCode;
}

Expand Down
16 changes: 16 additions & 0 deletions src/AndreyTech/Pdepend/Summary/Formatter/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,25 @@ public function buildArgvInput(): void
$option = new InputOption('init', null, InputOption::VALUE_NONE);
$definition->addOption($option);

$option = new InputOption('ignore-red-metrics-on-exit', null, InputOption::VALUE_NONE);
$definition->addOption($option);

$option = new InputOption('ignore-yellow-metrics-on-exit', null, InputOption::VALUE_NONE);
$definition->addOption($option);

$this->argvInput = new ArgvInput(null, $definition);
}

public function handleOptionIgnoreRedMetricsOnExit(): bool
{
return (bool) $this->argvInput->getOption('ignore-red-metrics-on-exit');
}

public function handleOptionIgnoreYellowMetricsOnExit(): bool
{
return (bool) $this->argvInput->getOption('ignore-yellow-metrics-on-exit');
}

public function handleOptionNoColor(): void
{
$noColor = (bool) $this->argvInput->getOption('no-color');
Expand Down

0 comments on commit 1f06685

Please sign in to comment.