Skip to content

Instantly share code, notes, and snippets.

@d8vjork
Created April 18, 2023 14:23
Show Gist options
  • Save d8vjork/6ee0c48c8f48b06cf8bd22b429af95a7 to your computer and use it in GitHub Desktop.
Save d8vjork/6ee0c48c8f48b06cf8bd22b429af95a7 to your computer and use it in GitHub Desktop.
My php insights config
<?php
declare(strict_types=1);
return [
/*
|--------------------------------------------------------------------------
| Default Preset
|--------------------------------------------------------------------------
|
| This option controls the default preset that will be used by PHP Insights
| to make your code reliable, simple, and clean. However, you can always
| adjust the `Metrics` and `Insights` below in this configuration file.
|
| Supported: "default", "laravel", "symfony", "magento2", "drupal"
|
*/
'preset' => 'laravel',
/*
|--------------------------------------------------------------------------
| IDE
|--------------------------------------------------------------------------
|
| This options allow to add hyperlinks in your terminal to quickly open
| files in your favorite IDE while browsing your PhpInsights report.
|
| Supported: "textmate", "macvim", "emacs", "sublime", "phpstorm",
| "atom", "vscode".
|
| If you have another IDE that is not in this list but which provide an
| url-handler, you could fill this config with a pattern like this:
|
| myide://open?url=file://%f&line=%l
|
*/
'ide' => 'vscode',
/*
|--------------------------------------------------------------------------
| Configuration
|--------------------------------------------------------------------------
|
| Here you may adjust all the various `Insights` that will be used by PHP
| Insights. You can either add, remove or configure `Insights`. Keep in
| mind that all added `Insights` must belong to a specific `Metric`.
|
*/
'exclude' => [
'TestController.php',
'helpers.php',
],
'add' => [
\NunoMaduro\PhpInsights\Domain\Metrics\Architecture\Classes::class => [
\NunoMaduro\PhpInsights\Domain\Insights\ForbiddenFinalClasses::class,
],
\NunoMaduro\PhpInsights\Domain\Metrics\Style\Style::class => [
\PhpCsFixer\Fixer\Whitespace\BlankLineBetweenImportGroupsFixer::class,
],
],
'remove' => [
// Code
\SlevomatCodingStandard\Sniffs\Namespaces\AlphabeticallySortedUsesSniff::class,
\SlevomatCodingStandard\Sniffs\TypeHints\DeclareStrictTypesSniff::class,
\SlevomatCodingStandard\Sniffs\TypeHints\DisallowMixedTypeHintSniff::class,
\SlevomatCodingStandard\Sniffs\Classes\ClassConstantVisibilitySniff::class,
\SlevomatCodingStandard\Sniffs\ControlStructures\DisallowShortTernaryOperatorSniff::class,
\SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSniff::class,
\SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSniff::class,
\PHP_CodeSniffer\Standards\Generic\Sniffs\Formatting\SpaceAfterNotSniff::class,
\SlevomatCodingStandard\Sniffs\Commenting\InlineDocCommentDeclarationSniff::class,
\PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\FixmeSniff::class,
\PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\TodoSniff::class,
\NunoMaduro\PhpInsights\Domain\Insights\ForbiddenDefineFunctions::class,
\NunoMaduro\PhpInsights\Domain\Insights\ForbiddenNormalClasses::class,
\NunoMaduro\PhpInsights\Domain\Insights\ForbiddenTraits::class,
\NunoMaduro\PhpInsights\Domain\Insights\ForbiddenFinalClasses::class,
/** Until Laravel 10, because "base" classes are not typed yet */
\SlevomatCodingStandard\Sniffs\TypeHints\PropertyTypeHintSniff::class,
/** Allow assignment in condition as widely used in Laravel's core framework code */
\SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff::class,
// Code style
\PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff::class
// TODO: Remove this only on --fix
// \SlevomatCodingStandard\Sniffs\Namespaces\UnusedUsesSniff::class,
],
'config' => [
// @PER
\PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer::class => [
'inline_constructor_arguments' => false,
'space_before_parenthesis' => true,
],
\PhpCsFixer\Fixer\Basic\CurlyBracesPositionFixer::class => [
'allow_single_line_empty_anonymous_classes' => true,
],
\PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer::class => [
'on_multiline' => 'ensure_fully_multiline',
],
\PhpCsFixer\Fixer\Import\SingleImportPerStatementFixer::class => [
'group_to_single_imports' => false,
],
\PhpCsFixer\Fixer\ClassNotation\SingleClassElementPerStatementFixer::class => [
'elements' => ['property'],
],
\PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer::class => [
'order' => ['use_trait'],
],
\PhpCsFixer\Fixer\Import\OrderedImportsFixer::class => [
'imports_order' => [
'class',
'function',
'const',
],
'sort_algorithm' => 'none',
],
\SlevomatCodingStandard\Sniffs\Namespaces\UseSpacingSniff::class => [
'linesCountBetweenUseTypes' => 1,
],
\SlevomatCodingStandard\Sniffs\Classes\ForbiddenPublicPropertySniff::class => [
'exclude' => [
'app/Nova',
],
],
\SlevomatCodingStandard\Sniffs\Functions\UnusedParameterSniff::class => [
'exclude' => [
'app/Nova',
],
],
\SlevomatCodingStandard\Sniffs\Commenting\DocCommentSpacingSniff::class => [
'linesCountBetweenDifferentAnnotationsTypes' => 0,
],
\SlevomatCodingStandard\Sniffs\Classes\ClassConstantVisibilitySniff::class => [
'exclude' => [
'app/Enums',
],
],
\SlevomatCodingStandard\Sniffs\Classes\ForbiddenPublicPropertySniff::class => [
'exclude' => [
'app/Models',
'app/Listeners',
'app/Events',
'app/Mail',
'app/Jobs',
],
],
\SlevomatCodingStandard\Sniffs\Functions\UnusedParameterSniff::class => [
'exclude' => [
'app/Notifications',
'app/Policies',
'app/Rules',
],
],
\SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSniff::class => [
'exclude' => ['routes'],
],
\NunoMaduro\PhpInsights\Domain\Insights\ForbiddenPrivateMethods::class => [
'title' => 'The usage of private methods is not idiomatic in Laravel.',
],
],
/*
|--------------------------------------------------------------------------
| Requirements
|--------------------------------------------------------------------------
|
| Here you may define a level you want to reach per `Insights` category.
| When a score is lower than the minimum level defined, then an error
| code will be returned. This is optional and individually defined.
|
*/
'requirements' => [
'min-quality' => env('INSIGHTS_MIN_QUALITY', 70),
'min-complexity' => env('INSIGHTS_MIN_COMPLEXITY', 60),
'min-architecture' => env('INSIGHTS_MIN_ARCHITECTURE', 60),
'min-style' => env('INSIGHTS_MIN_STYLE', 80),
'disable-security-check' => false,
],
/*
|--------------------------------------------------------------------------
| Threads
|--------------------------------------------------------------------------
|
| Here you may adjust how many threads (core) PHPInsights can use to perform
| the analyse. This is optional, don't provide it and the tool will guess
| the max core number available. This accept null value or integer > 0.
|
*/
'threads' => null,
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment