Skip to content

Commit ee327ac

Browse files
committed
Added phpinsights
1 parent 4c2a371 commit ee327ac

File tree

3 files changed

+164
-1
lines changed

3 files changed

+164
-1
lines changed

.github/workflows/insights.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: PHP Insights
2+
3+
on: push
4+
5+
jobs:
6+
phpinsights:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
php: [8.0,8.1]
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v2
16+
17+
- name: Setup PHP
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: ${{ matrix.php }}
21+
extensions: dom, curl, libxml, mbstring, zip, json
22+
coverage: none
23+
24+
- name: Install dependencies
25+
run: |
26+
composer install --no-interaction --no-progress --no-scripts -o
27+
28+
- name: Run PHP Insights
29+
run: ./vendor/bin/phpinsights app --summary -v --min-quality=80 --min-complexity=80 --min-architecture=80 --min-style=80 --disable-security-check

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"itsgoingd/clockwork": "^5.1",
2626
"nunomaduro/collision": "^6.0",
2727
"nunomaduro/larastan": "^2.0.1",
28+
"nunomaduro/phpinsights": "^2.4",
2829
"orchestra/testbench": "^7.0",
2930
"pestphp/pest": "^1.21",
3031
"pestphp/pest-plugin-faker": "^1.0",
@@ -56,7 +57,8 @@
5657
"sort-packages": true,
5758
"allow-plugins": {
5859
"pestphp/pest-plugin": true,
59-
"phpstan/extension-installer": true
60+
"phpstan/extension-installer": true,
61+
"dealerdirect/phpcodesniffer-composer-installer": true
6062
}
6163
},
6264
"extra": {

phpinsights.config.php

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenDefineFunctions;
6+
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenFinalClasses;
7+
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenNormalClasses;
8+
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenPrivateMethods;
9+
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenTraits;
10+
use NunoMaduro\PhpInsights\Domain\Metrics\Architecture\Classes;
11+
use SlevomatCodingStandard\Sniffs\Commenting\UselessFunctionDocCommentSniff;
12+
use SlevomatCodingStandard\Sniffs\Namespaces\AlphabeticallySortedUsesSniff;
13+
use SlevomatCodingStandard\Sniffs\TypeHints\DeclareStrictTypesSniff;
14+
use SlevomatCodingStandard\Sniffs\TypeHints\DisallowMixedTypeHintSniff;
15+
use SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSniff;
16+
use SlevomatCodingStandard\Sniffs\TypeHints\PropertyTypeHintSniff;
17+
use SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSniff;
18+
19+
return [
20+
21+
/*
22+
|--------------------------------------------------------------------------
23+
| Default Preset
24+
|--------------------------------------------------------------------------
25+
|
26+
| This option controls the default preset that will be used by PHP Insights
27+
| to make your code reliable, simple, and clean. However, you can always
28+
| adjust the `Metrics` and `Insights` below in this configuration file.
29+
|
30+
| Supported: "default", "laravel", "symfony", "magento2", "drupal"
31+
|
32+
*/
33+
34+
'preset' => 'laravel',
35+
36+
/*
37+
|--------------------------------------------------------------------------
38+
| IDE
39+
|--------------------------------------------------------------------------
40+
|
41+
| This options allow to add hyperlinks in your terminal to quickly open
42+
| files in your favorite IDE while browsing your PhpInsights report.
43+
|
44+
| Supported: "textmate", "macvim", "emacs", "sublime", "phpstorm",
45+
| "atom", "vscode".
46+
|
47+
| If you have another IDE that is not in this list but which provide an
48+
| url-handler, you could fill this config with a pattern like this:
49+
|
50+
| myide://open?url=file://%f&line=%l
51+
|
52+
*/
53+
54+
'ide' => null,
55+
56+
/*
57+
|--------------------------------------------------------------------------
58+
| Configuration
59+
|--------------------------------------------------------------------------
60+
|
61+
| Here you may adjust all the various `Insights` that will be used by PHP
62+
| Insights. You can either add, remove or configure `Insights`. Keep in
63+
| mind that all added `Insights` must belong to a specific `Metric`.
64+
|
65+
*/
66+
67+
'exclude' => [
68+
// 'path/to/directory-or-file'
69+
],
70+
71+
'add' => [
72+
Classes::class => [
73+
ForbiddenFinalClasses::class,
74+
],
75+
],
76+
77+
'remove' => [
78+
AlphabeticallySortedUsesSniff::class,
79+
DeclareStrictTypesSniff::class,
80+
DisallowMixedTypeHintSniff::class,
81+
ForbiddenDefineFunctions::class,
82+
ForbiddenNormalClasses::class,
83+
ForbiddenTraits::class,
84+
ParameterTypeHintSniff::class,
85+
PropertyTypeHintSniff::class,
86+
ReturnTypeHintSniff::class,
87+
UselessFunctionDocCommentSniff::class,
88+
],
89+
90+
'config' => [
91+
ForbiddenPrivateMethods::class => [
92+
'title' => 'The usage of private methods is not idiomatic in Laravel.',
93+
],
94+
\NunoMaduro\PhpInsights\Domain\Insights\CyclomaticComplexityIsHigh::class => [
95+
'maxComplexity' => 20,
96+
],
97+
98+
],
99+
100+
/*
101+
|--------------------------------------------------------------------------
102+
| Requirements
103+
|--------------------------------------------------------------------------
104+
|
105+
| Here you may define a level you want to reach per `Insights` category.
106+
| When a score is lower than the minimum level defined, then an error
107+
| code will be returned. This is optional and individually defined.
108+
|
109+
*/
110+
111+
'requirements' => [
112+
'min-quality' => 80,
113+
'min-complexity' => 80,
114+
'min-architecture' => 80,
115+
'min-style' => 80,
116+
'disable-security-check' => true,
117+
],
118+
119+
/*
120+
|--------------------------------------------------------------------------
121+
| Threads
122+
|--------------------------------------------------------------------------
123+
|
124+
| Here you may adjust how many threads (core) PHPInsights can use to perform
125+
| the analyse. This is optional, don't provide it and the tool will guess
126+
| the max core number available. This accept null value or integer > 0.
127+
|
128+
*/
129+
130+
'threads' => null,
131+
132+
];

0 commit comments

Comments
 (0)