PHPackages                             degraciamathieu/php-smelly-code-detector - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [DevOps &amp; Deployment](/categories/devops)
4. /
5. degraciamathieu/php-smelly-code-detector

ActivePackage[DevOps &amp; Deployment](/categories/devops)

degraciamathieu/php-smelly-code-detector
========================================

PHP code smell detector

v2.1.0(2y ago)2873811MITPHPPHP ^8.1CI passing

Since Dec 30Pushed 1y ago1 watchersCompare

[ Source](https://github.com/DeGraciaMathieu/php-smelly-code-detector)[ Packagist](https://packagist.org/packages/degraciamathieu/php-smelly-code-detector)[ RSS](/packages/degraciamathieu-php-smelly-code-detector/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (15)Used By (1)

[![](https://github.com/DeGraciaMathieu/php-smelly-code-detector/raw/master/arts/robot.png)](https://github.com/DeGraciaMathieu/php-smelly-code-detector/blob/master/arts/robot.png)

[![testing](https://github.com/DeGraciaMathieu/php-smelly-code-detector/actions/workflows/testing.yml/badge.svg)](https://github.com/DeGraciaMathieu/php-smelly-code-detector/actions/workflows/testing.yml)[![phpstan](https://github.com/DeGraciaMathieu/php-smelly-code-detector/actions/workflows/phpstan.yml/badge.svg)](https://github.com/DeGraciaMathieu/php-smelly-code-detector/actions/workflows/phpstan.yml)[![Packagist Version](https://camo.githubusercontent.com/328bb12f8bdeece5af88c01fde9474b013b80d2994ca22022d62105d88267ada/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64656772616369616d6174686965752f7068702d736d656c6c792d636f64652d6465746563746f72)](https://camo.githubusercontent.com/328bb12f8bdeece5af88c01fde9474b013b80d2994ca22022d62105d88267ada/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64656772616369616d6174686965752f7068702d736d656c6c792d636f64652d6465746563746f72)[![Packagist PHP Version](https://camo.githubusercontent.com/a2d2f8cbd49c87b02fb801740e68e578ecca30df4a3acf02c2e933875c53deed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f64656772616369616d6174686965752f7068702d736d656c6c792d636f64652d6465746563746f722f706870)](https://camo.githubusercontent.com/a2d2f8cbd49c87b02fb801740e68e578ecca30df4a3acf02c2e933875c53deed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f64656772616369616d6174686965752f7068702d736d656c6c792d636f64652d6465746563746f722f706870)

php-smelly-code-detector
========================

[](#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](https://en.wikipedia.org/wiki/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
============

[](#installation)

```
Requires >= PHP 8.1

```

Phar
----

[](#phar)

This tool is distributed as a [PHP Archive (PHAR)](https://www.php.net/phar):

```
wget https://github.com/DeGraciaMathieu/php-smelly-code-detector/raw/master/builds/smelly-code-detector

```

```
php smelly-code-detector --version

```

Composer
--------

[](#composer)

Alternately, you can directly use composer :

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

```

Analyze methods
===============

[](#analyze-methods)

```
php smelly-code-detector inspect-method {path}

```

Options
-------

[](#options)

optionsdescription--min-smell=The minimum smell threshold to show.--max-smell=The maximum smell threshold to show.--only=Comma-separated list of smells to show.--ignore=Comma-separated list of smells to ignore.--limit=The maximum number of results to show, default 20.--publicShow only public methods.--privateShow only private methods.--protectedShow only protected methods.--without-constructorHide constructors.--sort-by=smellSort order (smell, loc, arg, ccl), default smell.--jsonRender metrics in JSONExamples
--------

[](#examples)

20 lines are displayed by default, you can configure this with the `--limit=` option.

```
$ php smelly-code-detector inspect-method app --limit=5
❀ PHP Smelly Code Detector ❀
   84 [============================]
+-----------------------------------------------------+--------+------------+-----+-----+-----+-------+
| file                                                | method | visibility | loc | arg | ccn | Smell |
+-----------------------------------------------------+--------+------------+-----+-----+-----+-------+
| app/Http/Controllers/Blog/AdminPostController.php   | update | Public     | 25  | 2   | 3   | 125   |
| app/Http/Controllers/Auth/NewPasswordController.php | store  | Public     | 29  | 1   | 2   | 87    |
| app/Http/Controllers/Blog/AdminPostController.php   | store  | Public     | 26  | 1   | 2   | 78    |
| app/Console/Commands/FetchGoogleFonts.php           | store  | Private    | 26  | 1   | 2   | 78    |
| app/Http/Middleware/RedirectIfAuthenticated.php     | handle | Public     | 11  | 3   | 4   | 77    |
+-----------------------------------------------------+--------+------------+-----+-----+-----+-------+
5/183 methods displayed

```

You can select scanned files with `--only=` and `--ignore=` options.

```
$ php smelly-code-detector inspect-method app --only=Controller.php --limit=10
❀ PHP Smelly Code Detector ❀
   24 [============================]
+-----------------------------------------------------------+--------------------+------------+-----+-----+-----+-------+
| file                                                      | method             | visibility | loc | arg | ccn | Smell |
+-----------------------------------------------------------+--------------------+------------+-----+-----+-----+-------+
| app/Http/Controllers/Blog/AdminPostController.php         | update             | Public     | 25  | 2   | 3   | 125   |
| app/Http/Controllers/Auth/NewPasswordController.php       | store              | Public     | 29  | 1   | 2   | 87    |
| app/Http/Controllers/Blog/AdminPostController.php         | store              | Public     | 26  | 1   | 2   | 78    |
| app/Http/Controllers/User/ProfileController.php           | updateAvatar       | Public     | 21  | 1   | 2   | 63    |
| app/Http/Controllers/Blog/GalleryController.php           | uploadPicture      | Public     | 21  | 1   | 2   | 63    |
| app/Http/Controllers/Auth/PasswordResetLinkController.php | store              | Public     | 17  | 1   | 2   | 51    |
| app/Http/Controllers/User/ProfileController.php           | updateInformations | Public     | 17  | 1   | 2   | 51    |
| app/Http/Controllers/Auth/RegisteredUserController.php    | store              | Public     | 25  | 1   | 1   | 50    |
| app/Http/Controllers/Blog/ShowPostController.php          | __invoke           | Public     | 12  | 2   | 2   | 48    |
| app/Http/Controllers/Forum/CommentController.php          | store              | Public     | 16  | 2   | 1   | 48    |
+-----------------------------------------------------------+--------------------+------------+-----+-----+-----+-------+
10/50 methods displayed

```

You can select the visibilities to keep with the `--public`, `--protected` and `--private` options.

```
$ php smelly-code-detector inspect-method app --private
❀ PHP Smelly Code Detector ❀
   84 [============================]
+--------------------------------------------------+---------------------------------+------------+-----+-----+-----+-------+
| file                                             | method                          | visibility | loc | arg | ccn | Smell |
+--------------------------------------------------+---------------------------------+------------+-----+-----+-----+-------+
| app/Console/Commands/FetchGoogleFonts.php        | store                           | Private    | 26  | 1   | 2   | 78    |
| app/Services/Community/CreatorRepository.php     | instantiateCreatorsFromResponse | Private    | 24  | 1   | 2   | 72    |
| app/Notifications/VerifyEmail.php                | verificationUrl                 | Private    | 10  | 1   | 1   | 20    |
| app/Http/Controllers/Blog/ShowPostController.php | postAreNotDisplayable           | Private    | 3   | 2   | 2   | 12    |
+--------------------------------------------------+---------------------------------+------------+-----+-----+-----+-------+
4/4 methods displayed

```

By default, rows will be sorted by the smell value, you can change the sort order with `--sort-by=` option, the following values are available : loc, arg, ccl, smell.

```
$ php smelly-code-detector inspect-method app --sort-by=ccl --limit=3
❀ PHP Smelly Code Detector ❀
   84 [============================]
+---------------------------------------------------+-----------------------+------------+-----+-----+-----+-------+
| file                                              | method                | visibility | loc | arg | ccn | Smell |
+---------------------------------------------------+-----------------------+------------+-----+-----+-----+-------+
| app/Http/Middleware/RedirectIfAuthenticated.php   | handle                | Public     | 11  | 3   | 4   | 77    |
| app/Http/Controllers/Blog/AdminPostController.php | update                | Public     | 25  | 2   | 3   | 125   |
| app/Providers/RouteServiceProvider.php            | configureRateLimiting | Protected  | 5   | 0   | 2   | 10    |
+---------------------------------------------------+-----------------------+------------+-----+-----+-----+-------+
3/183 methods displayed

```

Analyze class
=============

[](#analyze-class)

This command gives the total smell of a class, as well as an average by method and a breakdown by visibility.

```
php smelly-code-detector inspect-class {path}

```

Options
-------

[](#options-1)

optionsdescription--only=Comma-separated list of smells to show.--ignore=Comma-separated list of smells to ignore.--limit=The maximum number of results to show, default 20.--publicShow only public methods.--privateShow only private methods.--protectedShow only protected methods.--without-constructorHide constructors.--sort-by=smellSort order (count, smell, avg), default smell.--jsonRender metrics in JSONExamples
--------

[](#examples-1)

```
$ php smelly-code-detector inspect-class app
❀ PHP Smelly Code Detector ❀
+-----------------------------------------------------+-------+-------+-----+--------+-------+-------+
| class                                               | count | smell | avg | public | prot. | priv. |
+-----------------------------------------------------+-------+-------+-----+--------+-------+-------+
| app/Http/Controllers/Blog/AdminPostController.php   | 8     | 244   | 30  | 100 %  | 0 %   | 0 %   |
| app/Http/Controllers/User/ProfileController.php     | 5     | 150   | 30  | 100 %  | 0 %   | 0 %   |
| app/Services/Community/CreatorRepository.php        | 3     | 118   | 39  | 38 %   | 61 %  | 0 %   |
| app/Console/Commands/FetchGoogleFonts.php           | 4     | 117   | 29  | 9 %    | 66 %  | 23 %  |
| app/Http/Controllers/Forum/CommentController.php    | 4     | 116   | 29  | 100 %  | 0 %   | 0 %   |
| app/Http/Controllers/Auth/NewPasswordController.php | 2     | 93    | 46  | 100 %  | 0 %   | 0 %   |
| app/Http/Controllers/Forum/TopicController.php      | 7     | 81    | 11  | 100 %  | 0 %   | 0 %   |
| app/Policies/UserPolicy.php                         | 8     | 77    | 9   | 100 %  | 0 %   | 0 %   |
| app/Policies/TopicPolicy.php                        | 8     | 77    | 9   | 100 %  | 0 %   | 0 %   |
| app/Policies/CommentPolicy.php                      | 8     | 77    | 9   | 100 %  | 0 %   | 0 %   |
| app/Policies/SubscriberPolicy.php                   | 8     | 77    | 9   | 100 %  | 0 %   | 0 %   |
| app/Policies/PostPolicy.php                         | 8     | 77    | 9   | 100 %  | 0 %   | 0 %   |
| app/Http/Middleware/RedirectIfAuthenticated.php     | 1     | 77    | 77  | 100 %  | 0 %   | 0 %   |
| app/Http/Controllers/Blog/GalleryController.php     | 3     | 76    | 25  | 100 %  | 0 %   | 0 %   |
| app/Services/Markdown/MarkdownProvider.php          | 1     | 75    | 75  | 100 %  | 0 %   | 0 %   |
| app/Http/Controllers/Blog/ShowPostController.php    | 3     | 74    | 24  | 64 %   | 16 %  | 18 %  |
| app/Http/Requests/LoginRequest.php                  | 5     | 70    | 14  | 100 %  | 0 %   | 0 %   |
| app/Models/Post.php                                 | 6     | 68    | 11  | 58 %   | 0 %   | 41 %  |
| app/Notifications/VerifyEmail.php                   | 5     | 61    | 12  | 67 %   | 32 %  | 0 %   |
| app/Channels/DiscordWebhookChannel.php              | 3     | 61    | 20  | 31 %   | 0 %   | 68 %  |
+-----------------------------------------------------+-------+-------+-----+--------+-------+-------+
20/84 class displayed

```

###  Health Score

36

—

LowBetter than 81% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 98.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~24 days

Recently: every ~48 days

Total

9

Last Release

1032d ago

Major Versions

v0.1.4 → v1.0.02023-04-13

v1.1.0 → v2.0.02023-07-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/b7c883dad74109462c750a2bafef33c1d26da31c68e90b686cc0aa355b57feaf?d=identicon)[DeGraciaMathieu](/maintainers/DeGraciaMathieu)

---

Top Contributors

[![DeGraciaMathieu](https://avatars.githubusercontent.com/u/11473997?v=4)](https://github.com/DeGraciaMathieu "DeGraciaMathieu (89 commits)")[![abenevaut](https://avatars.githubusercontent.com/u/1134021?v=4)](https://github.com/abenevaut "abenevaut (1 commits)")

---

Tags

cimetricsphpqualitystatic-analyzerphpMetricsqualitycistatic analyzersmell

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/degraciamathieu-php-smelly-code-detector/health.svg)

```
[![Health](https://phpackages.com/badges/degraciamathieu-php-smelly-code-detector/health.svg)](https://phpackages.com/packages/degraciamathieu-php-smelly-code-detector)
```

###  Alternatives

[mehrancodes/laravel-harbor

A CLI tool to Quickly create On-Demand preview environment for your apps.

9989.0k](/packages/mehrancodes-laravel-harbor)[renoki-co/laravel-healthchecks

Laravel Healthchecks is a simple controller class that helps you build your own healthchecks endpoint without issues.

5654.9k](/packages/renoki-co-laravel-healthchecks)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
