phpinsights Documentation

Instant PHP quality checks from your console

5,597 stars PHP PHP 1 file ยท ~2,555 tokens #analytics#architecture#cli#code#complexity#console#cs#hacktoberfest
RAW Doc

1. Project Overview & Quickstart (nunomaduro/phpinsights)

File: README.md

PHP Insights was carefully crafted to simplify the analysis of your code directly from your terminal, and is the perfect starting point to analyze the code quality of your PHP projects.

๐Ÿš€ Quick start

First, install:

text
composer require nunomaduro/phpinsights --dev

Then, use it:

text
./vendor/bin/phpinsights

For Laravel:

First, publish the configuration file:

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

Then, use it:

text
php artisan insights

โœจ Features

  • Analysis of code quality and coding style
  • Beautiful overview of code architecture and its complexity
  • Designed to work out-of-the-box with Laravel, Symfony, Yii, Magento, and more
  • Contains built-in checks for making code reliable, loosely coupled, simple, and clean

๐Ÿ’– Support the development

Do you like this project? Support it by donating

Click the "๐Ÿ’– Sponsor" at the top of this repo.

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


File: docs/README.md


home: true
title: PHP Insights
heroImage: /logo.gif
actionText: Get Started โ†’
actionLink: /get-started
sidebar: true
features:
- title: Static Analysis Tool
details: Analysis of code quality and coding style. Beautiful overview of code architecture and it's complexity.
- title: Tailored for your framework
details: Designed to work out-of-the-box with Laravel, Symfony, Yii, WordPress, Magento2, and more.
- title: Quality Checks
details: Contains built-in checks for making code reliable, loosely coupled, simple, and clean.

Quick start

bash
# First, install:
composer require nunomaduro/phpinsights --dev

# Then, use it:
./vendor/bin/phpinsights

File: docs/Readme.md


home: true
title: PHP Insights
heroImage: /logo.gif
actionText: Get Started โ†’
actionLink: /get-started
sidebar: true
features:
- title: Static Analysis Tool
details: Analysis of code quality and coding style. Beautiful overview of code architecture and it's complexity.
- title: Tailored for your framework
details: Designed to work out-of-the-box with Laravel, Symfony, Yii, WordPress, Magento2, and more.
- title: Quality Checks
details: Contains built-in checks for making code reliable, loosely coupled, simple, and clean.

Quick start

bash
# First, install:
composer require nunomaduro/phpinsights --dev

# Then, use it:
./vendor/bin/phpinsights

File: docs/readme.md


home: true
title: PHP Insights
heroImage: /logo.gif
actionText: Get Started โ†’
actionLink: /get-started
sidebar: true
features:
- title: Static Analysis Tool
details: Analysis of code quality and coding style. Beautiful overview of code architecture and it's complexity.
- title: Tailored for your framework
details: Designed to work out-of-the-box with Laravel, Symfony, Yii, WordPress, Magento2, and more.
- title: Quality Checks
details: Contains built-in checks for making code reliable, loosely coupled, simple, and clean.

Quick start

bash
# First, install:
composer require nunomaduro/phpinsights --dev

# Then, use it:
./vendor/bin/phpinsights

File: docs/get-started.md

Get started

Requires: PHP 8.4+

First, install PHP Insights via the Composer package manager:

bash
composer require nunomaduro/phpinsights --dev

Then, use the phpinsights binary:

bash
# Mac & Linux
./vendor/bin/phpinsights

# Windows
.\vendor\bin\phpinsights.bat

Within Laravel

First, you should publish the config-file with:

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

Then, use the insights Artisan command:

bash
php artisan insights

With Docker

You can also use phpinsights via Docker:

bash
docker run -it --rm -v "$(pwd):/app" nunomaduro/phpinsights

Analyse a sub-directory or a specific file

You can ask phpinsights to analyse only a directory or even a specific file by providing path with analyse command:

bash
# For a directory
./vendor/bin/phpinsights analyse path/to/analyse

# For a file
./vendor/bin/phpinsights analyse path/to/analyse.php

In laravel, launch command as usual with your path:

bash
php artisan insights path/to/analyse

Fixing errors automatically

Some Insights support automatic fixing.
To fix your code automatically, there are two possibilities:

  • Add --fix option to your command. The output will be the classical output, with a summary of all issues fixed.
  • Or launch phpinsights fix [directory]
bash
# Classical command with --fix option
vendor/bin/phpinsights analyse path/to/analyse --fix

# In laravel
php artisan insights path/to/analyse --fix

# Just fix
vendor/bin/phpinsights fix path/to/analyse

Analyse multiple paths

You can ask phpinsights to analyse multiple directories, multiple files or even combining them by providing multiple paths with analyse command:

bash
# For multiple directories
./vendor/bin/phpinsights analyse path/to/dir1 path/to/dir2

# For multiple files
./vendor/bin/phpinsights analyse path/to/file1.php path/to/file2.php

# Combined
./vendor/bin/phpinsights analyse path/to/dir path/to/file.php

In laravel, launch command as usual with your paths:

bash
php artisan insights path/to/dir path/to/file.php

Specify composer file

Optionally, you can specify your composer file by adding the composer flag as below:

bash
./vendor/bin/phpinsights analyse --composer=/var/www/composer.json

Formatting the output

For changing the output format you can add the format flag. The following formats are supported:

  • console
  • json
  • checkstyle
bash
./vendor/bin/phpinsights analyse --format=json

Saving output to file

You can pipe the result to a file or to anywhere you like.
A common use case is parsing the output formatted as json to a json file.

bash
./vendor/bin/phpinsights analyse --format=json > test.json

When piping the result remember to add the no interaction flag -n, as the part where you need to interact is also getting piped. (the json format does not have any interaction)
While piping data, if you want the progress bar to refresh itself instead of printing a new one, add the --ansi flag.

Allowed memory size of X bytes exhausted

If you encounter the error Allowed memory size of XXXXX bytes exhausted, the current workaround is to increase the memory limit:

text
php -d memory_limit=2000M ./vendor/bin/phpinsights

Display issues omitted

The PHP Insights console command has 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:

bash
./vendor/bin/phpinsights -v

Avoid Composer conflicts

If you have trouble while requiring phpinsights with composer, try installing it with bamarni/composer-bin-plugin to isolate it from others dependencies:

bash
composer require --dev bamarni/composer-bin-plugin
composer bin phpinsights require nunomaduro/phpinsights
./vendor/bin/phpinsights

Flush cache results

Between 2 analyses, issues are cached.
PHPInsights is smart enough to invalidate cache when it detects changes in your code, but you may completely flush cache before analysis by adding --flush-cache flag.

Configure diff

Some insights display a diff output.
If you want more context on the diff, configure it in the phpinsights.php file:

php
<?php

return [
    // ...
    'diff_context' => 3,
    // ...
];

2. Official Technical Reference & Guides (nunomaduro/docs)

File: README.md

Laravel Documentation

You can find the online version of the Laravel documentation at https://laravel.com/docs

Contribution Guidelines

If you are submitting documentation for the current stable release, submit it to the corresponding branch. For example, documentation for Laravel 5.7 would be submitted to the 5.7 branch. Documentation intended for the next release of Laravel should be submitted to the master branch.


File: Readme.md

Laravel Documentation

You can find the online version of the Laravel documentation at https://laravel.com/docs

Contribution Guidelines

If you are submitting documentation for the current stable release, submit it to the corresponding branch. For example, documentation for Laravel 5.7 would be submitted to the 5.7 branch. Documentation intended for the next release of Laravel should be submitted to the master branch.


File: readme.md

Laravel Documentation

You can find the online version of the Laravel documentation at https://laravel.com/docs

Contribution Guidelines

If you are submitting documentation for the current stable release, submit it to the corresponding branch. For example, documentation for Laravel 5.7 would be submitted to the 5.7 branch. Documentation intended for the next release of Laravel should be submitted to the master branch.