PHP Classes

PHP Function Arguments Detector: Detect complex functions with too many arguments

Recommend this page to a friend!
  Info   View files Example   View files View files (13)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2022-08-04 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 33 This week: 1All time: 10,566 This week: 153Up
Version License PHP version Categories
php-arguments-detect 1.0The PHP License5PHP 5, Utilities and Tools
Description Author

This package can detect complex functions with too many arguments.

It can check the application classes automatically loaded using the vendor/autoload.php script.

The package can find application classes that take many arguments and report them in the command line console.

Innovation Award
PHP Programming Innovation award nominee
August 2022
Nominee
Vote
Complex PHP code is hard to maintain. In practice, this means that if you use a complex coding style, you spend a lot of time analyzing and improving your code every time you need to make changes.

There are several types of signs that you use a complex coding style. One of them is the way you declare your classes and functions.

For instance, if you create classes with functions with many parameters, that is a sign that you are trying to do many operations in those functions.

This package can help you to find which can be the complex class functions, so you can fix them, probably splitting them into several functions that do fewer operations.

Manuel Lemos
Picture of DeGraciaMathieu
  Performance   Level  
Name: DeGraciaMathieu <contact>
Classes: 11 packages by
Country: France France
Age: ???
All time rank: 324786 in France France
Week rank: 93 Up4 in France France Up
Innovation award
Innovation award
Nominee: 7x

Details

build packagist) packagist)

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

| options | description | |-----------------------|-------------| | --min= | Ignore methods with less than --min arguments. | | --max= | Ignore methods with more than --max arguments. | | --limit= | Number of methods displayed. | | --without-constructor | Ignore method constructors from detection. | | --sort-by-weight | Sort the results by the weight of methods. |

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=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.

  Files folder image Files  
File Role Description
Files folder image.github (1 directory)
Files folder imagedocker (1 directory)
Files folder imagesrc (3 files, 3 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file docker-compose.yml Data Auxiliary data
Accessible without login Plain text file phpargsdetector Example Example script
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file build.yml Data Auxiliary data

  Files folder image Files  /  docker  
File Role Description
Files folder imageapp (1 file)

  Files folder image Files  /  docker  /  app  
File Role Description
  Accessible without login Plain text file Dockerfile Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageCommands (1 file)
Files folder imagePrinters (1 file)
Files folder imageVisitors (1 file)
  Plain text file Detector.php Class Class source
  Plain text file Method.php Class Class source
  Plain text file NodeMethodExplorer.php Class Class source

  Files folder image Files  /  src  /  Commands  
File Role Description
  Plain text file InspectCommand.php Class Class source

  Files folder image Files  /  src  /  Printers  
File Role Description
  Plain text file Console.php Class Class source

  Files folder image Files  /  src  /  Visitors  
File Role Description
  Plain text file FileVisitor.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:33
This week:1
All time:10,566
This week:153Up
For more information send a message to info at phpclasses dot org.