Skip to content

Commit 5c43044

Browse files
authored
Merge pull request #13 from MatanYadaev/phpinsights
PHPInsights
2 parents d39caa8 + 0c5cd62 commit 5c43044

19 files changed

+498
-157
lines changed

.github/workflows/phpinsights.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Code quality analysis
2+
3+
on: [push]
4+
5+
jobs:
6+
phpstan:
7+
name: PHPInsights
8+
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
15+
- name: Setup PHP
16+
uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: 8.0
19+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
20+
coverage: none
21+
22+
- name: Install dependencies
23+
run: composer install --prefer-dist --no-interaction
24+
25+
- name: Run PHPInsights
26+
run: ./vendor/bin/phpinsights --no-interaction --ansi --format=github-action

.php_cs.dist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
return (new MattAllan\LaravelCodeStyle\Config())
44
->setFinder(
55
PhpCsFixer\Finder::create()
6-
->in('src')
7-
->in('tests')
6+
->in(__DIR__)
87
)
98
->setRules([
109
'@Laravel' => true,

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@
2525
"friendsofphp/php-cs-fixer": "^2.17",
2626
"matt-allan/laravel-code-style": "^0.6.0",
2727
"nunomaduro/larastan": "^0.7.0",
28+
"nunomaduro/phpinsights": "dev-feature/php8-and-github-action",
2829
"orchestra/testbench": "^6.0",
2930
"phpunit/phpunit": "^9.3"
3031
},
3132
"autoload": {
3233
"psr-4": {
3334
"MatanYadaev\\EloquentSpatial\\": "src",
3435
"MatanYadaev\\EloquentSpatial\\Database\\Factories\\": "database/factories"
35-
},
36-
"files": [
37-
"src/helpers.php"
38-
]
36+
}
3937
},
4038
"autoload-dev": {
4139
"psr-4": {
@@ -44,9 +42,11 @@
4442
},
4543
"scripts": {
4644
"php-cs-fixer": "./vendor/bin/php-cs-fixer fix --allow-risky=yes",
47-
"phpstan": "vendor/bin/phpstan analyse --memory-limit=2G",
48-
"test": "vendor/bin/phpunit --colors=always",
49-
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
45+
"phpstan": "./vendor/bin/phpstan analyse --memory-limit=2G",
46+
"phpunit": "./vendor/bin/phpunit --colors=always",
47+
"phpunit-coverage": "./vendor/bin/phpunit --coverage-html coverage",
48+
"phpinsights": "./vendor/bin/phpinsights",
49+
"phpinsights-fix": "./vendor/bin/phpinsights fix"
5050
},
5151
"config": {
5252
"sort-packages": true

phpinsights.php

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use NunoMaduro\PhpInsights\Domain\Insights\CyclomaticComplexityIsHigh;
6+
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenNormalClasses;
7+
use ObjectCalisthenics\Sniffs\Files\ClassTraitAndInterfaceLengthSniff;
8+
use ObjectCalisthenics\Sniffs\Files\FunctionLengthSniff;
9+
use ObjectCalisthenics\Sniffs\Metrics\MaxNestingLevelSniff;
10+
use ObjectCalisthenics\Sniffs\Metrics\MethodPerClassLimitSniff;
11+
use PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\UselessOverridingMethodSniff;
12+
use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff;
13+
use SlevomatCodingStandard\Sniffs\Classes\SuperfluousExceptionNamingSniff;
14+
use SlevomatCodingStandard\Sniffs\Functions\UnusedParameterSniff;
15+
use SlevomatCodingStandard\Sniffs\TypeHints\DisallowMixedTypeHintSniff;
16+
use SlevomatCodingStandard\Sniffs\TypeHints\ParameterTypeHintSniff;
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' => 'default',
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' => 'phpstorm',
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+
// ExampleMetric::class => [
73+
// ExampleInsight::class,
74+
// ]
75+
],
76+
77+
'remove' => [
78+
ParameterTypeHintSniff::class,
79+
ReturnTypeHintSniff::class,
80+
UselessOverridingMethodSniff::class,
81+
DisallowMixedTypeHintSniff::class,
82+
ForbiddenNormalClasses::class,
83+
SuperfluousExceptionNamingSniff::class,
84+
],
85+
86+
'config' => [
87+
LineLengthSniff::class => [
88+
'lineLimit' => 110,
89+
'absoluteLineLimit' => 150,
90+
'ignoreComments' => false,
91+
],
92+
MaxNestingLevelSniff::class => [
93+
'exclude' => [
94+
'src/Objects/Geometry.php',
95+
],
96+
],
97+
UnusedParameterSniff::class => [
98+
'exclude' => [
99+
'src/Objects/Geometry.php',
100+
'src/Objects/GeometryCast.php',
101+
],
102+
],
103+
MethodPerClassLimitSniff::class => [
104+
'exclude' => [
105+
'src/Builders/SpatialBuilder.php',
106+
'src/Objects/Geometry.php',
107+
],
108+
],
109+
ClassTraitAndInterfaceLengthSniff::class => [
110+
'exclude' => [
111+
'src/Builders/SpatialBuilder.php',
112+
],
113+
],
114+
FunctionLengthSniff::class => [
115+
'exclude' => [
116+
'src/Factory.php',
117+
],
118+
],
119+
CyclomaticComplexityIsHigh::class => [
120+
'exclude' => [
121+
'src/Factory.php',
122+
],
123+
],
124+
],
125+
126+
/*
127+
|--------------------------------------------------------------------------
128+
| Requirements
129+
|--------------------------------------------------------------------------
130+
|
131+
| Here you may define a level you want to reach per `Insights` category.
132+
| When a score is lower than the minimum level defined, then an error
133+
| code will be returned. This is optional and individually defined.
134+
|
135+
*/
136+
137+
'requirements' => [
138+
'min-quality' => 90,
139+
'min-complexity' => 90,
140+
'min-architecture' => 90,
141+
'min-style' => 90,
142+
'disable-security-check' => true,
143+
],
144+
145+
/*
146+
|--------------------------------------------------------------------------
147+
| Threads
148+
|--------------------------------------------------------------------------
149+
|
150+
| Here you may adjust how many threads (core) PHPInsights can use to perform
151+
| the analyse. This is optional, don't provide it and the tool will guess
152+
| the max core number available. This accept null value or integer > 0.
153+
|
154+
*/
155+
156+
'threads' => null,
157+
158+
];

0 commit comments

Comments
 (0)