diff --git a/README.md b/README.md index a5e8fcb..90af83e 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,8 @@ Options: -m, --metric Metric to use for determining complexity [cognitive, cyclomatic, metrics.deprecated.category, - metrics.deprecated.subpackage] + metrics.deprecated.subpackage, + metrics.complexity.length] [default: cognitive] -w, --complexity-warning-threshold Cyclomatic complexity score which is the lower bound for a warning diff --git a/bin/php-doc-check b/bin/php-doc-check index 73df944..18ce68f 100755 --- a/bin/php-doc-check +++ b/bin/php-doc-check @@ -42,6 +42,7 @@ $lexer = new \PhpParser\Lexer\Emulative( array( 'usedAttributes' => array( 'startLine', + 'endLine', 'comments', ), ) diff --git a/src/AnalysableFile.php b/src/AnalysableFile.php index a577038..b81ad08 100644 --- a/src/AnalysableFile.php +++ b/src/AnalysableFile.php @@ -14,6 +14,7 @@ class AnalysableFile implements \JsonSerializable 'cognitive' => '\NdB\PhpDocCheck\Metrics\CognitiveComplexity', 'metrics.deprecated.category' => '\NdB\PhpDocCheck\Metrics\CategoryDeprecated', 'metrics.deprecated.subpackage' => '\NdB\PhpDocCheck\Metrics\SubpackageDeprecated', + 'metrics.complexity.length' => '\NdB\PhpDocCheck\Metrics\FunctionLength', 'cyclomatic' => '\NdB\PhpDocCheck\Metrics\CyclomaticComplexity' ); diff --git a/src/ApplicationArgumentsProvider.php b/src/ApplicationArgumentsProvider.php index e325c12..267c2e9 100644 --- a/src/ApplicationArgumentsProvider.php +++ b/src/ApplicationArgumentsProvider.php @@ -19,7 +19,7 @@ public function __construct() \GetOpt\Option::create('m', 'metric', \GetOpt\GetOpt::REQUIRED_ARGUMENT) ->setDescription( 'Metric to use for determining complexity [cognitive, cyclomatic, '. - 'metrics.deprecated.category, metrics.deprecated.subpackage] '. + 'metrics.deprecated.category, metrics.deprecated.subpackage, metrics.complexity.length] '. '[default: cognitive]' ) ->setDefaultValue('cognitive'), diff --git a/src/Metrics/FunctionLength.php b/src/Metrics/FunctionLength.php new file mode 100644 index 0000000..f9369bb --- /dev/null +++ b/src/Metrics/FunctionLength.php @@ -0,0 +1,36 @@ +getDocComment())) { + return 0; + } + return ( $node->getEndLine() - $node->getStartLine() ) / self::LINES_PER_POINT; + } + + public function jsonSerialize() : array + { + return array( + 'name'=>$this->getName(), + 'value'=>$this->value + ); + } +}