{"id":23036854,"url":"https://github.com/degraciamathieu/php-smelly-code-detector","last_synced_at":"2025-09-02T13:42:18.787Z","repository":{"id":65145252,"uuid":"578157364","full_name":"DeGraciaMathieu/php-smelly-code-detector","owner":"DeGraciaMathieu","description":"Detects code smells by assessing complexity to identify potentially problematic code","archived":false,"fork":false,"pushed_at":"2025-02-27T16:45:51.000Z","size":42126,"stargazers_count":27,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-01T09:42:49.745Z","etag":null,"topics":["ci","metrics","php","quality","static-analyzer"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DeGraciaMathieu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-12-14T11:49:54.000Z","updated_at":"2025-03-04T19:28:38.000Z","dependencies_parsed_at":"2025-08-14T17:32:57.430Z","dependency_job_id":"d3e690a6-8b05-4193-b01f-d040ad756504","html_url":"https://github.com/DeGraciaMathieu/php-smelly-code-detector","commit_stats":{"total_commits":81,"total_committers":1,"mean_commits":81.0,"dds":0.0,"last_synced_commit":"00867e247ca842de11ae15b57c73357fc946aacd"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/DeGraciaMathieu/php-smelly-code-detector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeGraciaMathieu%2Fphp-smelly-code-detector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeGraciaMathieu%2Fphp-smelly-code-detector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeGraciaMathieu%2Fphp-smelly-code-detector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeGraciaMathieu%2Fphp-smelly-code-detector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DeGraciaMathieu","download_url":"https://codeload.github.com/DeGraciaMathieu/php-smelly-code-detector/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeGraciaMathieu%2Fphp-smelly-code-detector/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273293719,"owners_count":25079892,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ci","metrics","php","quality","static-analyzer"],"created_at":"2024-12-15T17:27:56.450Z","updated_at":"2025-09-02T13:42:18.759Z","avatar_url":"https://github.com/DeGraciaMathieu.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://github.com/DeGraciaMathieu/php-smelly-code-detector/blob/master/arts/robot.png\" width=\"250\"\u003e\n\u003c/p\u003e\n\n[![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)\n[![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)\n![Packagist Version](https://img.shields.io/packagist/v/degraciamathieu/php-smelly-code-detector)\n![Packagist PHP Version](https://img.shields.io/packagist/dependency-v/degraciamathieu/php-smelly-code-detector/php)\n\n# php-smelly-code-detector\n\n\u003e \"A code smell is a surface indication that usually corresponds to a deeper problem in the system.\"\n\u003e ~ Martin Fowler\n\nCode smell is a potentially problematic code indicator with the following formula : `($ccn + $arg) * $loc`\n\n- ccn : [cyclomatic complexity](https://en.wikipedia.org/wiki/Cyclomatic_complexity) of the method\n- arg : number of method arguments\n- loc : number of lines in the method\n\nA high smell value will often reveal that the method is too complex.\n\nThis complexity could be detrimental to the maintainability of the method, favoring the appearance of bugs in the future.\n\nThis indicator does not replace the expertise of a developer and must above all be considered as an alarm detecting \"smelly\" code.\n\n# Installation\n\n```\nRequires \u003e= PHP 8.1\n```\n\n## Phar\nThis tool is distributed as a [PHP Archive (PHAR)](https://www.php.net/phar):\n\n```\nwget https://github.com/DeGraciaMathieu/php-smelly-code-detector/raw/master/builds/smelly-code-detector\n```\n\n```\nphp smelly-code-detector --version\n```\n\n## Composer\nAlternately, you can directly use composer :\n\n```\ncomposer require degraciamathieu/php-smelly-code-detector --dev\n```\n\n# Analyze methods\n```\nphp smelly-code-detector inspect-method {path}\n```\n## Options\n| options               | description |\n|-----------------------|-------------|\n| --min-smell= | The minimum smell threshold to show.|\n| --max-smell= | The maximum smell threshold to show.|\n| --only= | Comma-separated list of smells to show.|\n| --ignore= | Comma-separated list of smells to ignore.|\n| --limit= | The maximum number of results to show, default 20.|\n| --public | Show only public methods.|\n| --private | Show only private methods.|\n| --protected | Show only protected methods.|\n| --without-constructor | Hide constructors.|\n| --sort-by=smell | Sort order (smell, loc, arg, ccl), default smell.|\n| --json | Render metrics in JSON|\n\n\n## Examples\n20 lines are displayed by default, you can configure this with the `--limit=` option.\n```\n$ php smelly-code-detector inspect-method app --limit=5\n❀ PHP Smelly Code Detector ❀\n   84 [============================]\n+-----------------------------------------------------+--------+------------+-----+-----+-----+-------+\n| file                                                | method | visibility | loc | arg | ccn | Smell |\n+-----------------------------------------------------+--------+------------+-----+-----+-----+-------+\n| app/Http/Controllers/Blog/AdminPostController.php   | update | Public     | 25  | 2   | 3   | 125   |\n| app/Http/Controllers/Auth/NewPasswordController.php | store  | Public     | 29  | 1   | 2   | 87    |\n| app/Http/Controllers/Blog/AdminPostController.php   | store  | Public     | 26  | 1   | 2   | 78    |\n| app/Console/Commands/FetchGoogleFonts.php           | store  | Private    | 26  | 1   | 2   | 78    |\n| app/Http/Middleware/RedirectIfAuthenticated.php     | handle | Public     | 11  | 3   | 4   | 77    |\n+-----------------------------------------------------+--------+------------+-----+-----+-----+-------+\n5/183 methods displayed\n```\nYou can select scanned files with `--only=` and `--ignore=` options.\n```\n$ php smelly-code-detector inspect-method app --only=Controller.php --limit=10\n❀ PHP Smelly Code Detector ❀\n   24 [============================]\n+-----------------------------------------------------------+--------------------+------------+-----+-----+-----+-------+\n| file                                                      | method             | visibility | loc | arg | ccn | Smell |\n+-----------------------------------------------------------+--------------------+------------+-----+-----+-----+-------+\n| app/Http/Controllers/Blog/AdminPostController.php         | update             | Public     | 25  | 2   | 3   | 125   |\n| app/Http/Controllers/Auth/NewPasswordController.php       | store              | Public     | 29  | 1   | 2   | 87    |\n| app/Http/Controllers/Blog/AdminPostController.php         | store              | Public     | 26  | 1   | 2   | 78    |\n| app/Http/Controllers/User/ProfileController.php           | updateAvatar       | Public     | 21  | 1   | 2   | 63    |\n| app/Http/Controllers/Blog/GalleryController.php           | uploadPicture      | Public     | 21  | 1   | 2   | 63    |\n| app/Http/Controllers/Auth/PasswordResetLinkController.php | store              | Public     | 17  | 1   | 2   | 51    |\n| app/Http/Controllers/User/ProfileController.php           | updateInformations | Public     | 17  | 1   | 2   | 51    |\n| app/Http/Controllers/Auth/RegisteredUserController.php    | store              | Public     | 25  | 1   | 1   | 50    |\n| app/Http/Controllers/Blog/ShowPostController.php          | __invoke           | Public     | 12  | 2   | 2   | 48    |\n| app/Http/Controllers/Forum/CommentController.php          | store              | Public     | 16  | 2   | 1   | 48    |\n+-----------------------------------------------------------+--------------------+------------+-----+-----+-----+-------+\n10/50 methods displayed\n```\nYou can select the visibilities to keep with the `--public`, `--protected` and `--private` options.\n```\n$ php smelly-code-detector inspect-method app --private\n❀ PHP Smelly Code Detector ❀\n   84 [============================]\n+--------------------------------------------------+---------------------------------+------------+-----+-----+-----+-------+\n| file                                             | method                          | visibility | loc | arg | ccn | Smell |\n+--------------------------------------------------+---------------------------------+------------+-----+-----+-----+-------+\n| app/Console/Commands/FetchGoogleFonts.php        | store                           | Private    | 26  | 1   | 2   | 78    |\n| app/Services/Community/CreatorRepository.php     | instantiateCreatorsFromResponse | Private    | 24  | 1   | 2   | 72    |\n| app/Notifications/VerifyEmail.php                | verificationUrl                 | Private    | 10  | 1   | 1   | 20    |\n| app/Http/Controllers/Blog/ShowPostController.php | postAreNotDisplayable           | Private    | 3   | 2   | 2   | 12    |\n+--------------------------------------------------+---------------------------------+------------+-----+-----+-----+-------+\n4/4 methods displayed\n```\nBy 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. \n```\n$ php smelly-code-detector inspect-method app --sort-by=ccl --limit=3\n❀ PHP Smelly Code Detector ❀\n   84 [============================]\n+---------------------------------------------------+-----------------------+------------+-----+-----+-----+-------+\n| file                                              | method                | visibility | loc | arg | ccn | Smell |\n+---------------------------------------------------+-----------------------+------------+-----+-----+-----+-------+\n| app/Http/Middleware/RedirectIfAuthenticated.php   | handle                | Public     | 11  | 3   | 4   | 77    |\n| app/Http/Controllers/Blog/AdminPostController.php | update                | Public     | 25  | 2   | 3   | 125   |\n| app/Providers/RouteServiceProvider.php            | configureRateLimiting | Protected  | 5   | 0   | 2   | 10    |\n+---------------------------------------------------+-----------------------+------------+-----+-----+-----+-------+\n3/183 methods displayed\n```\n\n# Analyze class\nThis command gives the total smell of a class, as well as an average by method and a breakdown by visibility.\n```\nphp smelly-code-detector inspect-class {path}\n```\n## Options\n| options               | description |\n|-----------------------|-------------|\n| --only= | Comma-separated list of smells to show.|\n| --ignore= | Comma-separated list of smells to ignore.|\n| --limit= | The maximum number of results to show, default 20.|\n| --public | Show only public methods.|\n| --private | Show only private methods.|\n| --protected | Show only protected methods.|\n| --without-constructor | Hide constructors.|\n| --sort-by=smell | Sort order (count, smell, avg), default smell.|\n| --json | Render metrics in JSON|\n\n## Examples\n\n```\n$ php smelly-code-detector inspect-class app\n❀ PHP Smelly Code Detector ❀\n+-----------------------------------------------------+-------+-------+-----+--------+-------+-------+\n| class                                               | count | smell | avg | public | prot. | priv. |\n+-----------------------------------------------------+-------+-------+-----+--------+-------+-------+\n| app/Http/Controllers/Blog/AdminPostController.php   | 8     | 244   | 30  | 100 %  | 0 %   | 0 %   |\n| app/Http/Controllers/User/ProfileController.php     | 5     | 150   | 30  | 100 %  | 0 %   | 0 %   |\n| app/Services/Community/CreatorRepository.php        | 3     | 118   | 39  | 38 %   | 61 %  | 0 %   |\n| app/Console/Commands/FetchGoogleFonts.php           | 4     | 117   | 29  | 9 %    | 66 %  | 23 %  |\n| app/Http/Controllers/Forum/CommentController.php    | 4     | 116   | 29  | 100 %  | 0 %   | 0 %   |\n| app/Http/Controllers/Auth/NewPasswordController.php | 2     | 93    | 46  | 100 %  | 0 %   | 0 %   |\n| app/Http/Controllers/Forum/TopicController.php      | 7     | 81    | 11  | 100 %  | 0 %   | 0 %   |\n| app/Policies/UserPolicy.php                         | 8     | 77    | 9   | 100 %  | 0 %   | 0 %   |\n| app/Policies/TopicPolicy.php                        | 8     | 77    | 9   | 100 %  | 0 %   | 0 %   |\n| app/Policies/CommentPolicy.php                      | 8     | 77    | 9   | 100 %  | 0 %   | 0 %   |\n| app/Policies/SubscriberPolicy.php                   | 8     | 77    | 9   | 100 %  | 0 %   | 0 %   |\n| app/Policies/PostPolicy.php                         | 8     | 77    | 9   | 100 %  | 0 %   | 0 %   |\n| app/Http/Middleware/RedirectIfAuthenticated.php     | 1     | 77    | 77  | 100 %  | 0 %   | 0 %   |\n| app/Http/Controllers/Blog/GalleryController.php     | 3     | 76    | 25  | 100 %  | 0 %   | 0 %   |\n| app/Services/Markdown/MarkdownProvider.php          | 1     | 75    | 75  | 100 %  | 0 %   | 0 %   |\n| app/Http/Controllers/Blog/ShowPostController.php    | 3     | 74    | 24  | 64 %   | 16 %  | 18 %  |\n| app/Http/Requests/LoginRequest.php                  | 5     | 70    | 14  | 100 %  | 0 %   | 0 %   |\n| app/Models/Post.php                                 | 6     | 68    | 11  | 58 %   | 0 %   | 41 %  |\n| app/Notifications/VerifyEmail.php                   | 5     | 61    | 12  | 67 %   | 32 %  | 0 %   |\n| app/Channels/DiscordWebhookChannel.php              | 3     | 61    | 20  | 31 %   | 0 %   | 68 %  |\n+-----------------------------------------------------+-------+-------+-----+--------+-------+-------+\n20/84 class displayed\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdegraciamathieu%2Fphp-smelly-code-detector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdegraciamathieu%2Fphp-smelly-code-detector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdegraciamathieu%2Fphp-smelly-code-detector/lists"}