Keep control over the complexity of your methods by checking that they do not have too many arguments.

Overview

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-args= Ignore methods with less than --min-args arguments.
--max-args= Ignore methods with more than --max-args arguments.
--min-weight= Ignore methods with less than --min-weight weight.
--max-weight= Ignore methods with more than --max-weight weight.
--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-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.

You might also like...
SPAM Registration Stopper is a Q2A plugin that prevents highly probable SPAM user registrations based on well-known SPAM checking services and other techniques

SPAM Registration Stopper [by Gabriel Zanetti] Description SPAM Registration Stopper is a Question2Answer plugin that prevents highly probable SPAM us

A tidy conditional Blade directive for checking if something is in an array

A tidy conditional Blade directive for checking if something is in an array. This package provides a small @in directive that allows you to simplify i

Nagios/Icinga plugin for checking SATEON field network device status

check_sateon Nagios/Icinga plugin for checking SATEON field network device status Max.Fischer [email protected] Tested on CentOS GNU/Linux 6.5 with Ici

Allow players to see how well they are doing while pvping with the help of a combo counter

Combo-Counter Allow players to see how well they are doing while pvping with the help of a combo counter Settngs / Config #set to false if you dont wa

QuestionApp - a platform where users can ask questions and discuss about the subject they are curious about
QuestionApp - a platform where users can ask questions and discuss about the subject they are curious about

QuestionApp About The Project It can be a trend according to the number of likes and comments that members can ask questions. ![Alt Text] Ask your any

The simplest way to create a dynamic sitemap for your self-coded website which you have made by using PHP/HTML/CSS/Js etc... Scripts.

Sitemap_index.xml The simplest way to create a dynamic sitemap for your self-coded website which you have made by using PHP/HTML/CSS/Js etc... Scripts

Download this Plugin and you will have Hive MC server in your own!

Your-Own-Hive Version: v1.9.0 Murder Mystery Update Next Update: Survival Games This Plugin has all the essentials with HiveMC! Updates Every Day! Pla

Keep your website up to date.
Keep your website up to date.

Deutsch English Svenska Update 0.8.88 Keep your website up to date. How to add extensions You can download extensions as ZIP files and copy them into

Chat over your local network: 127.0.0.1

#Howto: install packages: apache2 (or nginx but I wouldn't prefer it if you're using your local computer) php for ubuntu/debian instance: $ apt instal

Comments
  • Avoid return negative weight

    Avoid return negative weight

    When showing results, if there's an interface in the scanned folder that has methods with arguments, it returns a negative weight (-2 * args), because of getLine() method it substracts always 2 (I guess its for the curly braces of the method).

    opened by hmorv 1
Releases(v0.5.0)
  • v0.5.0(Sep 1, 2022)

    What's Changed

    • Avoid return negative weight by @hmorv in https://github.com/DeGraciaMathieu/php-arguments-detector/pull/1

    New Contributors

    • @hmorv made their first contribution in https://github.com/DeGraciaMathieu/php-arguments-detector/pull/1

    Full Changelog: https://github.com/DeGraciaMathieu/php-arguments-detector/compare/v0.4.1...v0.5.0

    Source code(tar.gz)
    Source code(zip)
Owner
DeGraciaMathieu
Lead Developer #Laravel
DeGraciaMathieu
Silverstripe-tinytidy - Control which styles are available in TinyMCE's style dropdown menu and what elements they can be applied to

TinyTidy for SilverStripe This module mainly serves as an example of how to customise the 'styles' dropdown menu in the TinyMCE editor to control whic

Jono Menz 30 Jul 30, 2020
Core - ownCloud gives you freedom and control over your own data.

ownCloud Core ownCloud gives you freedom and control over your own data. A personal cloud which runs on your own server. Why is this so awesome? ?? Ac

ownCloud 7.9k Jan 4, 2023
This plugin allows you to create many-to-many relationships between pages in Kirby and synchronizes them on both sides.

Kirby 3 Many To Many Field This plugin allows you to create many-to-many relationships between pages in Kirby.

Jonas Holfeld 41 Nov 19, 2022
This Statamic addon allows you to modify the tags rendered by the Bard fieldtype, giving you full control over the final HTML.

Bard Mutator This Statamic addon allows you to modify the tags rendered by the Bard fieldtype, giving you full control over the final HTML. You can ad

Jack Sleight 10 Sep 26, 2022
salah eddine bendyab 18 Aug 17, 2021
Secure the data of your sites by encrypting them. They will be decrypted only in your applications

PHP Crypter Secure the data of your sites by encrypting them. They will be decrypted only in your applications How to use ? You just have to include t

Claude Fassinou 7 Nov 26, 2022
Better error reporting for PHP, and prettier too!

PHP Error | Improve Error Reporting for PHP THIS IS NO LOBGER MAINTAINED, Please leave me alone. PHP errors are not good enough for development, it's

Joseph Lenton 1.4k Dec 27, 2022
Just the stats I want, maybe you want them too

SKCDEV Easy Digital Downloads Stats This plugin adds a new "SKCDEV EDD Stats" report tab to the EDD Reports tabs. Just the stats I want, maybe you wan

Scott Kingsley Clark 3 Sep 8, 2022
Detect flaws in your architecture, before they drag you down into the depths of dependency hell ...

Detect flaws in your architecture before they drag you down into the depths of dependency hell ... What it does System Requirements Installation Phive

Michael Haeuslmann 507 Dec 27, 2022
Test and enforce architectural rules in your Laravel applications. Keep your app's architecture clean and consistent!

Laravel Arkitect Laravel Arkitect lets you test and enforce your architectural rules in your Laravel applications, and it's a PHPArkitect wrapper for

SMorteza Ebadi 55 Dec 17, 2022