Skip to content

Commit

Permalink
Fixes #43, Adds check for deprecated @subpackage tag
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsdeBlaauw committed Feb 13, 2019
1 parent 65c19f6 commit 14aa355
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ Options:
[default: text]
-o, --reportFile <arg> Send report output to a file
-m, --metric <arg> Metric to use for determining
complexity [cognitive, cyclomatic]
complexity [cognitive, cyclomatic,
metrics.deprecated.category,
metrics.deprecated.subpackage]
[default: cognitive]
-w, --complexity-warning-threshold <arg> Cyclomatic complexity score which
is the lower bound for a warning
Expand Down
1 change: 1 addition & 0 deletions src/AnalysableFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);

Expand Down
4 changes: 3 additions & 1 deletion src/ApplicationArgumentsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 37 additions & 0 deletions src/Metrics/SubpackageDeprecated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace NdB\PhpDocCheck\Metrics;

final class SubpackageDeprecated implements Metric
{
public $value = 0;

public function getMessage():string
{
return '%1$s has a @subpackage tag, which is deprecated. '.
'It is recommended to use the @package tag\'s ability '.
'to provide multiple levels.';
}

public function getName():string
{
return 'metrics.deprecated.subpackage';
}

public function getValue(\PhpParser\Node $node):int
{
$docBlock = $node->getAttribute('DocBlock');
if (!empty($docBlock) && $docBlock->hasTag('subpackage')) {
return 4;
}
return 0;
}

public function jsonSerialize() : array
{
return array(
'name'=>$this->getName(),
'value'=>$this->value
);
}
}

0 comments on commit 14aa355

Please sign in to comment.