PHP Classes

How to Use a PHP Quality Assurance Tool to Improve Your PHP Code Using the PHP Smelly Code Detector: Analyze PHP code to evaluate quality factors

Recommend this page to a friend!

  Author Author  
Picture of DeGraciaMathieu
Name: DeGraciaMathieu <contact>
Classes: 13 packages by
Country: France France
Innovation award
Innovation award
Nominee: 8x


  Detailed description   Download Download .zip .tar.gz  
This package can analyze PHP code to evaluate quality factors.

It provides a script that calls the package classes, analyzes the quality factors, and displays the results in a console terminal.

Currently, this package can analyze the following:

- The complexity of the code of functions

- The number of arguments of functions

- The number of lines of code

Details

<p align="center"> <img src="https://github.com/DeGraciaMathieu/php-smelly-code-detector/blob/master/arts/robot.png" width="250"> </p>

testing phpstan Packagist Version Packagist PHP Version

php-smelly-code-detector

> "A code smell is a surface indication that usually corresponds to a deeper problem in the system." > ~ Martin Fowler

Code smell is a potentially problematic code indicator with the following formula : ($ccn + $arg) * $loc

  • ccn : cyclomatic complexity of the method
  • arg : number of method arguments
  • loc : number of lines in the method

A high smell value will often reveal that the method is too complex.

This complexity could be detrimental to the maintainability of the method, favoring the appearance of bugs in the future.

This indicator does not replace the expertise of a developer and must above all be considered as an alarm detecting "smelly" code.

Installation

Requires >= PHP 8.1

composer require degraciamathieu/php-smelly-code-detector --dev

Usage

vendor/bin/smellyphpcodedetector inspect {folder}

Options

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

Examples

$ php smellyphpcodedetector inspect app --sort-by-smell --limit=10
? PHP Smelly Code Detector ?
   81 [============================] < 1 sec
+-----------------------------------------------------------+---------------------------------+-------+
| Files                                                     | Methods                         | smell |
+-----------------------------------------------------------+---------------------------------+-------+
| app/Http/Controllers/Blog/AdminPostController.php         | update                          | 174   |
| app/Http/Controllers/Auth/NewPasswordController.php       | store                           | 87    |
| app/Console/Commands/FetchGoogleFonts.php                 | store                           | 78    |
| app/Http/Middleware/RedirectIfAuthenticated.php           | handle                          | 77    |
| app/Http/Controllers/User/ProfileController.php           | updateAvatar                    | 75    |
| app/Services/Community/CreatorRepository.php              | instantiateCreatorsFromResponse | 72    |
| app/Http/Controllers/Auth/PasswordResetLinkController.php | store                           | 51    |
| app/Http/Controllers/User/ProfileController.php           | updateInformations              | 51    |
| app/Http/Controllers/Auth/RegisteredUserController.php    | store                           | 50    |
| app/Http/Controllers/Blog/ShowPostController.php          | __invoke                        | 48    |
+-----------------------------------------------------------+---------------------------------+-------+
193 methods found.

  Classes of DeGraciaMathieu  >  How to Use a PHP Quality Assurance Tool to Improve Your PHP Code Using the PHP Smelly Code Detector  >  Download Download .zip .tar.gz  >  Support forum Support forum  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: How to Use a PHP Quality Assurance Tool to Improve Your PHP Code Using the PHP Smelly Code Detector
Base name: php-smelly-code-dete
Description: Analyze PHP code to evaluate quality factors
Version: -
PHP version: 5
License: The PHP License
 
  Groups   Applications   Files Files  

  Groups  
Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes
Group folder image Utilities and Tools General purpose tools to simplify software development View top rated classes
Group folder image Parsers Programming language interpreters and format parsers View top rated classes


  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
File Role Description
Files folder image.github (1 directory)
Files folder imagearts (1 file)
Files folder imagesrc (2 files, 5 directories)
Files folder imagetests (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file Makefile Data Auxiliary data
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file smellyphpcodedetector Example Example script

  Files folder image Files  /  .github  
File Role Description
Files folder imageworkflows (2 files)

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

  Files folder image Files  /  arts  
File Role Description
  Accessible without login Image file robot.png Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageCommands (1 file)
Files folder imageEnums (1 file)
Files folder imageMetrics (1 file)
Files folder imagePrinters (1 file)
Files folder imageVisitors (3 files, 1 directory)
  Plain text file FileParser.php Class Class source
  Plain text file VisitorBag.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  /  Enums  
File Role Description
  Accessible without login Plain text file Metric.php Aux. Auxiliary script

  Files folder image Files  /  src  /  Metrics  
File Role Description
  Plain text file MethodMetric.php Class Class source

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

  Files folder image Files  /  src  /  Visitors  
File Role Description
Files folder imageAbstracts (1 file)
  Plain text file ArgumentVisitor.php Class Class source
  Plain text file CyclomaticComplexityVisitor.php Class Class source
  Plain text file WeightVisitor.php Class Class source

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

  Files folder image Files  /  tests  
File Role Description
Files folder imageUnit (2 files, 3 directories)

  Files folder image Files  /  tests  /  Unit  
File Role Description
Files folder imageCommands (1 file)
Files folder imageMetrics (1 file)
Files folder imageStubs (1 file)
  Plain text file FileParserTest.php Class Class source
  Plain text file VisitorBagTest.php Class Class source

  Files folder image Files  /  tests  /  Unit  /  Commands  
File Role Description
  Plain text file InspectCommandTest.php Class Class source

  Files folder image Files  /  tests  /  Unit  /  Metrics  
File Role Description
  Plain text file MethodMetricTest.php Class Class source

  Files folder image Files  /  tests  /  Unit  /  Stubs  
File Role Description
  Plain text file Foo.php Class Class source

Download Download all files: php-smelly-code-dete.tar.gz php-smelly-code-dete.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
  Files folder image Files  
File Role Description
Files folder image.github (1 directory)
Files folder imagearts (1 file)
Files folder imagesrc (2 files, 5 directories)
Files folder imagetests (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file Makefile Data Auxiliary data
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file smellyphpcodedetector Example Example script

  Files folder image Files  /  .github  
File Role Description
Files folder imageworkflows (2 files)

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

  Files folder image Files  /  arts  
File Role Description
  Accessible without login Image file robot.png Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageCommands (1 file)
Files folder imageEnums (1 file)
Files folder imageMetrics (1 file)
Files folder imagePrinters (1 file)
Files folder imageVisitors (3 files, 1 directory)
  Plain text file FileParser.php Class Class source
  Plain text file VisitorBag.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  /  Enums  
File Role Description
  Accessible without login Plain text file Metric.php Aux. Auxiliary script

  Files folder image Files  /  src  /  Metrics  
File Role Description
  Plain text file MethodMetric.php Class Class source

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

  Files folder image Files  /  src  /  Visitors  
File Role Description
Files folder imageAbstracts (1 file)
  Plain text file ArgumentVisitor.php Class Class source
  Plain text file CyclomaticComplexityVisitor.php Class Class source
  Plain text file WeightVisitor.php Class Class source

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

  Files folder image Files  /  tests  
File Role Description
Files folder imageUnit (2 files, 3 directories)

  Files folder image Files  /  tests  /  Unit  
File Role Description
Files folder imageCommands (1 file)
Files folder imageMetrics (1 file)
Files folder imageStubs (1 file)
  Plain text file FileParserTest.php Class Class source
  Plain text file VisitorBagTest.php Class Class source

  Files folder image Files  /  tests  /  Unit  /  Commands  
File Role Description
  Plain text file InspectCommandTest.php Class Class source

  Files folder image Files  /  tests  /  Unit  /  Metrics  
File Role Description
  Plain text file MethodMetricTest.php Class Class source

  Files folder image Files  /  tests  /  Unit  /  Stubs  
File Role Description
  Plain text file Foo.php Class Class source

Download Download all files: php-smelly-code-dete.tar.gz php-smelly-code-dete.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.