degraciamathieu / php-arguments-detector
通过检查方法是否具有过多的参数,来控制方法的复杂度。
v0.5.0
2022-09-01 07:09 UTC
Requires
- php: ^7.3 || ^7.4 || ^8.0
- nikic/php-parser: ^4.13
- symfony/console: ^4.4 || ^5.0 || ^6.0
- symfony/finder: ^4.4 || ^5.0 || ^6.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- symfony/var-dumper: ^5.1|^6.1
README
php 参数检测器
函数的理想参数数量为零。~ Robert C. Martin
使用此软件包检查方法是否具有过多的参数,以控制方法的复杂度。
安装
需要 >= PHP 7.3
composer require degraciamathieu/php-arguments-detector --dev
用法
vendor/bin/phpargsdetector inspect {folder}
选项
示例
vendor/bin/phpargsdetector inspect app/Services/Saml/
+------------------------------------------+------------------+-----------+--------+
| Files | Methods | Arguments | Weight |
+------------------------------------------+------------------+-----------+--------+
| app/Services/Saml/SamlMessageFactory.php | __construct | 2 | 2 |
| app/Services/Saml/SamlMessageFactory.php | makeSamlResponse | 2 | 68 |
| app/Services/Saml/SamlSecurity.php | checkSignature | 2 | 18 |
| app/Services/Saml/SamlIssuer.php | find | 1 | 3 |
| app/Services/Saml/SamlKeeper.php | keep | 1 | 1 |
| app/Services/Saml/SamlMessageFactory.php | addAttributes | 1 | 26 |
| app/Services/Saml/SamlMessageFactory.php | sign | 1 | 12 |
| app/Services/Saml/SamlResponder.php | launch | 1 | 10 |
| app/Services/Saml/SamlKeeper.php | has | 0 | 0 |
| app/Services/Saml/SamlKeeper.php | retrieve | 0 | 0 |
+------------------------------------------+------------------+-----------+--------+
Total of methods : 10
vendor/bin/phpargsdetector inspect app/ --limit=3 --min-args=2 --without-constructor
+-------------------------------------------------+---------+-----------+--------+
| Files | Methods | Arguments | Weight |
+-------------------------------------------------+---------+-----------+--------+
| app/Http/Middleware/RedirectIfAuthenticated.php | handle | 3 | 27 |
| app/Http/Controllers/IssuerController.php | update | 2 | 24 |
| app/Http/Controllers/RestrictionController.php | update | 2 | 28 |
+-------------------------------------------------+---------+-----------+--------+
Total of methods : 3
vendor/bin/phpargsdetector inspect app/ --limit=3 --sort-by-weight
+-------------------------------------------------+------------------+-----------+--------+
| Files | Methods | Arguments | Weight |
+-------------------------------------------------+------------------+-----------+--------+
| app/Services/Saml/SamlMessageFactory.php | makeSamlResponse | 2 | 68 |
| app/Http/Controllers/RestrictionController.php | update | 2 | 28 |
| app/Http/Middleware/RedirectIfAuthenticated.php | handle | 3 | 27 |
+-------------------------------------------------+------------------+-----------+--------+
Total of methods : 3
权重
权重是参数数量与方法行数的乘积。
foo
方法的权重是 10:2 个参数 * 5 行。
class Bar { public function foo($a, $b) { if ($a) { // } return $b; } }
可以用作复杂度指标。