degraciamathieu / php-arguments-detector
Keep control over the complexity of your methods by checking that they do not have too many arguments.
Installs: 856
Dependents: 7
Suggesters: 0
Security: 0
Stars: 13
Watchers: 2
Forks: 1
Open Issues: 0
Type:package
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 arguments detector
The ideal number of arguments for a function is zero. ~ Robert C. Martin
Keep control over the complexity of your methods by checking that they do not have too many arguments with this package.
Installation
Requires >= PHP 7.3
composer require degraciamathieu/php-arguments-detector --dev
Usage
vendor/bin/phpargsdetector inspect {folder}
Options
Examples
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
Weight
The weight is the number of arguments multiplied by the number of lines of the method.
The weight of the foo
method is 10 : 2 arguments * 5 lines.
class Bar { public function foo($a, $b) { if ($a) { // } return $b; } }
You can use it as a complexity indicator.