add phpinsights in your laravel project

phpinsights is a helpful package to add code quality analysis, it measure the code in four areas:

Code (code reliable, loosely coupled, simple, and clean).
Complexity (check the statements and methods complexity).
Architecture (check the patterns and…


This content originally appeared on DEV Community and was authored by Ariel Mejia

phpinsights is a helpful package to add code quality analysis, it measure the code in four areas:

  • Code (code reliable, loosely coupled, simple, and clean).

  • Complexity (check the statements and methods complexity).

  • Architecture (check the patterns and directories that you add, traits, interfaces, etc).

  • Style (check how you follow PSR-4 or PSR-12).

So it makes sense right?, lets install it.

How to install it

composer require nunomaduro/phpinsights --dev

Publish config file

php artisan vendor:publish --provider="NunoMaduro\PhpInsights\Application\Adapters\Laravel\InsightsServiceProvider"

Execute PHPinsights

php artisan insights

Customize it

On Laravel there are some code standards that could mismatch on how PHPInsights works, so you can edit the config file to adjust to your project/needs/packages etc.

Here an example of how I use it with a Laravel project with Jetstream.

You can exclude files by typing the full path name, as an array item.

On config/insights.php:

    'exclude' => [
        'app/Actions/Jetstream',
        'HandleInertiaRequests.php',
        '_ide_macros.php'
    ],

You can add custom rules:

    'add' => [
        Classes::class => [
            ForbiddenFinalClasses::class,
        ],
    ],

You can even remove rules that does not make sense, you can customize it as you need:

    'remove' => [
        AlphabeticallySortedUsesSniff::class,
        DeclareStrictTypesSniff::class,
        DisallowMixedTypeHintSniff::class,
        ForbiddenDefineFunctions::class,
        ForbiddenNormalClasses::class,
        ForbiddenTraits::class,
        ParameterTypeHintSniff::class,
        PropertyTypeHintSniff::class,
        ReturnTypeHintSniff::class,
        UselessFunctionDocCommentSniff::class,
        UnusedParameterSniff::class,
        LineLengthSniff::class,
        DocCommentSpacingSniff::class,
        ClassInstantiationSniff::class,
        NewWithBracesFixer::class,
        NullableTypeForNullDefaultValueSniff::class,
        DisallowArrayTypeHintSyntaxSniff::class,
        NoEmptyCommentFixer::class,
        DisallowShortTernaryOperatorSniff::class,
        ForbiddenPublicPropertySniff::class,
        DisallowEmptySniff::class

    ],

Another cool feature that you can customize is the "level" of qualification to print it as "green", "yellow" for example, you can customize it on requirements key, but if you comment, all the content it will work as it is designed by default:

    'requirements' => [
//        'min-quality' => 0,
//        'min-complexity' => 0,
//        'min-architecture' => 0,
//        'min-style' => 0,
//        'disable-security-check' => false,
    ],

This are some useful customizations, if you want to run automatically PHPInsights on every commit or push you can install husky and configure it to run PHPInsights on the husky hooks, is just a cool idea to make your work easier.

That is all for this post, thanks for reading!


This content originally appeared on DEV Community and was authored by Ariel Mejia


Print Share Comment Cite Upload Translate Updates
APA

Ariel Mejia | Sciencx (2021-06-01T01:51:58+00:00) add phpinsights in your laravel project. Retrieved from https://www.scien.cx/2021/06/01/add-phpinsights-in-your-laravel-project/

MLA
" » add phpinsights in your laravel project." Ariel Mejia | Sciencx - Tuesday June 1, 2021, https://www.scien.cx/2021/06/01/add-phpinsights-in-your-laravel-project/
HARVARD
Ariel Mejia | Sciencx Tuesday June 1, 2021 » add phpinsights in your laravel project., viewed ,<https://www.scien.cx/2021/06/01/add-phpinsights-in-your-laravel-project/>
VANCOUVER
Ariel Mejia | Sciencx - » add phpinsights in your laravel project. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/01/add-phpinsights-in-your-laravel-project/
CHICAGO
" » add phpinsights in your laravel project." Ariel Mejia | Sciencx - Accessed . https://www.scien.cx/2021/06/01/add-phpinsights-in-your-laravel-project/
IEEE
" » add phpinsights in your laravel project." Ariel Mejia | Sciencx [Online]. Available: https://www.scien.cx/2021/06/01/add-phpinsights-in-your-laravel-project/. [Accessed: ]
rf:citation
» add phpinsights in your laravel project | Ariel Mejia | Sciencx | https://www.scien.cx/2021/06/01/add-phpinsights-in-your-laravel-project/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.