From 14aa35507e93516ec82b92418e1fc7315cf4ef7b Mon Sep 17 00:00:00 2001 From: Niels de Blaauw Date: Wed, 13 Feb 2019 10:27:34 +0100 Subject: [PATCH] Fixes #43, Adds check for deprecated @subpackage tag --- README.md | 4 ++- src/AnalysableFile.php | 1 + src/ApplicationArgumentsProvider.php | 4 ++- src/Metrics/SubpackageDeprecated.php | 37 ++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/Metrics/SubpackageDeprecated.php diff --git a/README.md b/README.md index 1d686cc..a5e8fcb 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,9 @@ Options: [default: text] -o, --reportFile Send report output to a file -m, --metric Metric to use for determining - complexity [cognitive, cyclomatic] + complexity [cognitive, cyclomatic, + metrics.deprecated.category, + metrics.deprecated.subpackage] [default: cognitive] -w, --complexity-warning-threshold Cyclomatic complexity score which is the lower bound for a warning diff --git a/src/AnalysableFile.php b/src/AnalysableFile.php index 6f6fc5b..a577038 100644 --- a/src/AnalysableFile.php +++ b/src/AnalysableFile.php @@ -13,6 +13,7 @@ class AnalysableFile implements \JsonSerializable protected $metrics = array( 'cognitive' => '\NdB\PhpDocCheck\Metrics\CognitiveComplexity', 'metrics.deprecated.category' => '\NdB\PhpDocCheck\Metrics\CategoryDeprecated', + 'metrics.deprecated.subpackage' => '\NdB\PhpDocCheck\Metrics\SubpackageDeprecated', 'cyclomatic' => '\NdB\PhpDocCheck\Metrics\CyclomaticComplexity' ); diff --git a/src/ApplicationArgumentsProvider.php b/src/ApplicationArgumentsProvider.php index e2c5c7e..e325c12 100644 --- a/src/ApplicationArgumentsProvider.php +++ b/src/ApplicationArgumentsProvider.php @@ -18,7 +18,9 @@ public function __construct() ->setDefaultValue(''), \GetOpt\Option::create('m', 'metric', \GetOpt\GetOpt::REQUIRED_ARGUMENT) ->setDescription( - 'Metric to use for determining complexity [cognitive, cyclomatic] [default: cognitive]' + 'Metric to use for determining complexity [cognitive, cyclomatic, '. + 'metrics.deprecated.category, metrics.deprecated.subpackage] '. + '[default: cognitive]' ) ->setDefaultValue('cognitive'), \GetOpt\Option::create('w', 'complexity-warning-threshold', \GetOpt\GetOpt::REQUIRED_ARGUMENT) diff --git a/src/Metrics/SubpackageDeprecated.php b/src/Metrics/SubpackageDeprecated.php new file mode 100644 index 0000000..1d36b0c --- /dev/null +++ b/src/Metrics/SubpackageDeprecated.php @@ -0,0 +1,37 @@ +getAttribute('DocBlock'); + if (!empty($docBlock) && $docBlock->hasTag('subpackage')) { + return 4; + } + return 0; + } + + public function jsonSerialize() : array + { + return array( + 'name'=>$this->getName(), + 'value'=>$this->value + ); + } +}