GithubHelp home page GithubHelp logo

hhy5277 / phpinsights Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nunomaduro/phpinsights

0.0 1.0 0.0 10.78 MB

💡Instant PHP quality checks from your console

License: MIT License

PHP 100.00%

phpinsights's Introduction

PHP Insights

Build Status Total Downloads Latest Version License

PHP Insights was created by, and is maintained by Nuno Maduro, and is the perfect starting point to analyze the code quality of your PHP projects. Carefully crafted to simplify the analysis of your code directly from your terminal.

✨ Features

  • Analysis of code quality and coding style
  • Beautiful overview of code architecture and it's complexity
  • Designed to work out-of-the-box with Laravel, Symfony, and more
  • Contains built-in checks for making code reliable, loosely coupled, simple, and clean
  • Friendly console interface build on top of PHPCS, PHPLOC, and EasyCodingStandard

👉🏻 Installation & Usage

Requires:

First, install PHP Insights via the Composer package manager:

composer require nunomaduro/phpinsights --dev

Then, use the phpinsights binary:

php ./vendor/bin/phpinsights

Within Laravel

First, you should publish the config-file with:

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

Then, use the insights Artisan command:

php artisan insights

Within Symfony

First, you should create the config-file with:

cp vendor/nunomaduro/phpinsights/stubs/symfony.php phpinsights.php

Then, use the phpinsights binary:

php ./vendor/bin/phpinsights

No framework - customize Insights

You may customize insights creating and editing the configuration file:

cp vendor/nunomaduro/phpinsights/stubs/config.php phpinsights.php

Display issues omitted

PHP Insights console command have different verbosity levels, which determine the quantity of issues displayed. By default, commands display only the 3 first issues per Insight, but you can display them all with the -v option:

php ./vendor/bin/phpinsights -v

💡 How to contribute

The project is under development. As such, any help is welcome!

  1. Create a new insight from scratch
  2. Add a new insight from PHP CS Sniff
  3. Create or improve create a preset for your favorite framework
  4. Create the test suite

Create a new Insight

Imagine that you want to create a new Insight that doesn't allow the usage of final classes:

  1. Create a new file under src/Domain/Insights with the content:
final class ForbiddenFinalClasses extends Insight
{
    public function hasIssue(): bool
    {
        return (bool) count($this->collector->getConcreteFinalClasses());
    }

    public function getTitle(): string
    {
        return 'The use of `final` classes is prohibited';
    }
}
  1. Attach the Insight to a specific inside src/Domain/Metrics:
final class Classes implements HasInsights
{
    // ...

    public function getInsights(): array
    {
        return [
            ForbiddenFinalClasses::class,
        ];
    }
}

Add a new insight from PHP CS Sniff

Are you aware of a PHPCS sniff that you would like to add to PHP Insights? You can add it in the following way:

  1. Identify the related metric, and add it to the list of insights:
final class Classes implements HasInsights
{
    // ...

    public function getInsights(): array
    {
        return [
            UnusedPropertySniff::class,
        ];
    }
}

Create or improve create a preset for your favorite framework

Would you like to exclude a directory or remove an Insight for your favorite framework? You can add it in the following way:

In this example we are going to use the Laravel Framework.

  1. Open the file src/Application/Adapters/Laravel/Preset.php and update the config file:
final class Preset implements PresetContract
{
    public static function getName(): string
    {
        return 'laravel';
    }

    public static function get(): array
    {
        return [
            'exclude' => [
                'config',
                'storage',
                'resources',
                'bootstrap',
                'nova',
                'database',
                'server.php',
                '_ide_helper.php',
                '_ide_helper_models.php',
                'public',
            ],
            'add' => [
                Classes::class => [
                    ForbiddenFinalClasses::class,
                ],
            ],

            'remove' => [
                AlphabeticallySortedUsesSniff::class,
                DeclareStrictTypesSniff::class,
                DisallowMixedTypeHintSniff::class,
                ForbiddenDefineFunctions::class,
                ForbiddenNormalClasses::class,
                ForbiddenTraits::class,
                TypeHintDeclarationSniff::class,
            ],

            'config' => [
                ForbiddenPrivateMethods::class => [
                    'title' => 'The usage of private methods is not idiomatic in Laravel.',
                ],
                ForbiddenDefineGlobalConstants::class => [
                    'ignore' => ['LARAVEL_START'],
                ],
                ForbiddenFunctionsSniff::class => [
                    'forbiddenFunctions' => [
                        'dd' => null,
                        'dump' => null,
                    ],
                ],
            ],
        ];
    }
}

Create the test suite

At the moment, this package doesn't have any test. Would you like to contribute? This is the perfect task.

👏 Contributors

Thank you to all the people who have already contributed to PHP Insights!

Nuno Maduro
Nuno Maduro

Caneco
Caneco

Quynh Xuan Nguyen
Quynh Xuan Nguyen

Mike Erickson
Mike Erickson

Viktor Szépe
Viktor Szépe

Owen Voke
Owen Voke

🆓 License

PHP Insights is open-sourced software licensed under the MIT license.

phpinsights's People

Contributors

allcontributors[bot] avatar andreasherss avatar jibbarth avatar mikeerickson avatar nunomaduro avatar owenvoke avatar sarahdayan avatar seriquynh avatar szepeviktor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.