Skip to content

Commit

Permalink
🦺 Use PHP Insights
Browse files Browse the repository at this point in the history
  • Loading branch information
siguici committed Oct 22, 2023
1 parent 22f033d commit ae9d156
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 5 deletions.
14 changes: 10 additions & 4 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
<?php

declare(strict_types=1);

use Composer\Autoload\ClassLoader;

return (static function (string $root = __DIR__): ClassLoader {
$init_root = $root;
$autoloader = null;
do {
if (is_file($file = "$root/composer.json") && is_readable($file)) {
if (($data = @file_get_contents($file)) && ($data = @json_decode($data, true))) {
if (is_file($autoload_file = "$root/".($data['config']['vendor-dir'] ?? 'vendor').'/autoload.php') && is_readable($autoload_file)) {
$file = "{$root}/composer.json";
if (is_file($file) && is_readable($file)) {
$data = (string) file_get_contents($file);
$data = (array) json_decode($data, true);
if ($data) {
$autoload_file = "{$root}/".($data['config']['vendor-dir'] ?? 'vendor').'/autoload.php';
if (is_file($autoload_file) && is_readable($autoload_file)) {
$autoload_file = realpath($autoload_file);
if (in_array($autoload_file, get_included_files())) {
throw new RuntimeException("The $autoload_file file has already been included.");
throw new RuntimeException("The {$autoload_file} file has already been included.");
}
$autoloader = include_once $autoload_file;
}
Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"analyse": "phpstan analyse --ansi --memory-limit=-1 --debug",
"check": "pint --test -v",
"debug": [
"@validate",
"@check",
"@analyse",
"@inspect",
Expand All @@ -54,6 +55,7 @@
],
"fix": [
"@refactor",
"@sanitize",
"@format",
"@lint"
],
Expand All @@ -62,7 +64,9 @@
"lint": "pint -v",
"test": "pest --colors=always",
"review": "rector --dry-run --debug",
"refactor": "rector"
"refactor": "rector",
"sanitize": "phpinsights fix",
"validate": "phpinsights analyse"
},
"extra": {
"branch-alias": {
Expand Down
71 changes: 71 additions & 0 deletions phpinsights.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff;

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' => 'default',

/*
|--------------------------------------------------------------------------
| 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' => [
],

'add' => [
\NunoMaduro\PhpInsights\Domain\Metrics\Code\Comments::class => [
\PhpCsFixer\Fixer\Phpdoc\PhpdocSummaryFixer::class,
],
],

'remove' => [
],

'config' => [
LineLengthSniff::class => [
'lineLimit' => 120,
'absoluteLineLimit' => 120,
'ignoreComments' => true,
],
],

/*
|--------------------------------------------------------------------------
| 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' => 96.0,
'min-architecture' => 96.0,
'min-style' => 96.0,
],
];

0 comments on commit ae9d156

Please sign in to comment.