Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #43, Adds check for deprecated @subpackage tag #52

Merged
merged 1 commit into from
Feb 13, 2019
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
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
);
}
}