-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fixes #32, Adds function length metric * Adds documentation
- Loading branch information
1 parent
eda475d
commit b60fcbf
Showing
5 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace NdB\PhpDocCheck\Metrics; | ||
|
||
final class FunctionLength implements Metric | ||
{ | ||
public $value = 0; | ||
|
||
const LINES_PER_POINT = 5; | ||
|
||
public function getMessage():string | ||
{ | ||
return '%1$s has a length score of %2$d. It is recommended to document long functions.'; | ||
} | ||
|
||
public function getName():string | ||
{ | ||
return 'metrics.complexity.length'; | ||
} | ||
|
||
public function getValue(\PhpParser\Node $node):int | ||
{ | ||
if (!empty($node->getDocComment())) { | ||
return 0; | ||
} | ||
return ( $node->getEndLine() - $node->getStartLine() ) / self::LINES_PER_POINT; | ||
} | ||
|
||
public function jsonSerialize() : array | ||
{ | ||
return array( | ||
'name'=>$this->getName(), | ||
'value'=>$this->value | ||
); | ||
} | ||
} |