PHP code example of degraciamathieu / php-smelly-code-detector
1. Go to this page and download the library: Download degraciamathieu/php-smelly-code-detector library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
degraciamathieu / php-smelly-code-detector example snippets
Requires >= PHP 8.1
wget https://github.com/DeGraciaMathieu/php-smelly-code-detector/raw/master/builds/smelly-code-detector
php smelly-code-detector --version
php smelly-code-detector inspect-method {path}
$ 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
$ 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
$ 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
$ 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
php smelly-code-detector inspect-class {path}
$ 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