Skip to content

Commit

Permalink
Update dependencies & ability to ignore anonymous functions (#58)
Browse files Browse the repository at this point in the history
* Ignore anonymous functions

* Update dependencies

Co-authored-by: Nikita Zarubin <[email protected]>
  • Loading branch information
nikserg and Nikita Zarubin authored Sep 19, 2022
1 parent 4bc3fee commit 39615ba
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Options:
value] [default: natural]
-i, --ignore-violations-on-exit Will exit with a zero code, even if
any violations are found
-a, --ignore-anonymous-functions Skip checks on anonymous functions
-?, --help Show this help and quit
-q, --quiet Don't show any output
```
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"nikic/php-parser": "^4.2",
"wp-cli/php-cli-tools": "^0.11.11",
"ulrichsg/getopt-php": "^3.2",
"phpdocumentor/reflection-docblock": "^4.3"
"phpdocumentor/reflection-docblock": "^4.3|^5.0"
},
"bin": [
"bin/php-doc-check"
Expand Down
2 changes: 2 additions & 0 deletions src/ApplicationArgumentsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public function __construct()
'[natural, value] [default: natural]'
)
->setDefaultValue('file'),
\GetOpt\Option::create('a', 'ignore-anonymous-functions', \GetOpt\GetOpt::NO_ARGUMENT)
->setDescription('Will ignore anonymous functions on checks'),
\GetOpt\Option::create('i', 'ignore-violations-on-exit', \GetOpt\GetOpt::NO_ARGUMENT)
->setDescription('Will exit with a zero code, even if any violations are found'),
\GetOpt\Option::create('?', 'help', \GetOpt\GetOpt::NO_ARGUMENT)
Expand Down
3 changes: 3 additions & 0 deletions src/NodeVisitors/MetricChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function leaveNode(\PhpParser\Node $node)
$name = $node->namespacedName . '()';
}
}
if ($name == 'Anonymous function' && $this->arguments['ignore-anonymous-functions']) {
return;
}
$node->setAttribute('FQSEN', $name);

if ($metricValue >= $this->arguments->getOption('complexity-error-threshold')) {
Expand Down

0 comments on commit 39615ba

Please sign in to comment.