Skip to content

Commit 34446d4

Browse files
feat: Enhance PHPStan integration with yii2 extensions. (#13)
1 parent 1aecdf2 commit 34446d4

34 files changed

+117
-106
lines changed

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: [terabytesoftw]

.github/workflows/build.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ on:
66
- 'CHANGELOG.md'
77
- '.gitignore'
88
- '.gitattributes'
9-
- 'infection.json.dist'
10-
- 'psalm.xml'
119

1210
push:
1311
paths-ignore:
@@ -16,8 +14,6 @@ on:
1614
- 'CHANGELOG.md'
1715
- '.gitignore'
1816
- '.gitattributes'
19-
- 'infection.json.dist'
20-
- 'psalm.xml'
2117

2218
name: build
2319

@@ -26,8 +22,8 @@ jobs:
2622
uses: php-forge/actions/.github/workflows/phpunit.yml@main
2723
with:
2824
composer-command: |
29-
composer require yiisoft/yii2:^2.2.x-dev --prefer-dist --no-progress --no-interaction --no-scripts --ansi
25+
composer require yiisoft/yii2:22.0.x-dev --prefer-dist --no-progress --no-interaction --no-scripts --ansi
3026
os: >-
3127
['ubuntu-latest', 'windows-latest']
3228
php: >-
33-
['8.1', '8.2', '8.3']
29+
['8.1', '8.2', '8.3', '8.4']

.github/workflows/compatibility.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ on:
66
- 'CHANGELOG.md'
77
- '.gitignore'
88
- '.gitattributes'
9-
- 'infection.json.dist'
10-
- 'psalm.xml'
119

1210
push:
1311
paths-ignore:
@@ -16,8 +14,6 @@ on:
1614
- 'CHANGELOG.md'
1715
- '.gitignore'
1816
- '.gitattributes'
19-
- 'infection.json.dist'
20-
- 'psalm.xml'
2117

2218
name: compatibility
2319

@@ -26,7 +22,7 @@ jobs:
2622
uses: php-forge/actions/.github/workflows/phpunit.yml@main
2723
with:
2824
composer-command: |
29-
composer require yiisoft/yii2:^2.0.49 --prefer-dist --no-progress --no-interaction --no-scripts --ansi
25+
composer require yiisoft/yii2:^2.0.52 --prefer-dist --no-progress --no-interaction --no-scripts --ansi
3026
extensions: intl
3127
os: >-
3228
['ubuntu-latest', 'windows-latest']

.github/workflows/dependency-check.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ on:
66
- 'CHANGELOG.md'
77
- '.gitignore'
88
- '.gitattributes'
9-
- 'infection.json.dist'
10-
- 'phpunit.xml.dist'
11-
- 'psalm.xml'
129

1310
push:
1411
paths-ignore:
@@ -17,9 +14,6 @@ on:
1714
- 'CHANGELOG.md'
1815
- '.gitignore'
1916
- '.gitattributes'
20-
- 'infection.json.dist'
21-
- 'phpunit.xml.dist'
22-
- 'psalm.xml'
2317

2418
name: Composer require checker
2519

@@ -28,7 +22,7 @@ jobs:
2822
uses: php-forge/actions/.github/workflows/composer-require-checker.yml@main
2923
with:
3024
composer-command: |
31-
composer require yiisoft/yii2:^2.2.x-dev --prefer-dist --no-progress --no-interaction --no-scripts --ansi
25+
composer require yiisoft/yii2:22.0.x-dev --prefer-dist --no-progress --no-interaction --no-scripts --ansi
3226
os: >-
3327
['ubuntu-latest']
3428
php: >-

.github/workflows/ecs.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,14 @@ on:
66
- 'CHANGELOG.md'
77
- '.gitignore'
88
- '.gitattributes'
9-
- 'infection.json.dist'
10-
- 'phpunit.xml.dist'
119

1210
push:
13-
branches: ['main']
1411
paths-ignore:
1512
- 'docs/**'
1613
- 'README.md'
1714
- 'CHANGELOG.md'
1815
- '.gitignore'
1916
- '.gitattributes'
20-
- 'infection.json.dist'
21-
- 'phpunit.xml.dist'
2217

2318
name: ecs
2419

@@ -29,7 +24,7 @@ jobs:
2924
AUTH_TOKEN: ${{ secrets.AUTH_TOKEN }}
3025
with:
3126
composer-command: |
32-
composer require yiisoft/yii2:^2.2.x-dev --prefer-dist --no-progress --no-interaction --no-scripts --ansi
27+
composer require yiisoft/yii2:22.0.x-dev --prefer-dist --no-progress --no-interaction --no-scripts --ansi
3328
os: >-
3429
['ubuntu-latest']
3530
php: >-

.github/workflows/static.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
uses: php-forge/actions/.github/workflows/phpstan.yml@main
2727
with:
2828
composer-command: |
29-
composer require yiisoft/yii2:^2.2.x-dev --prefer-dist --no-progress --no-interaction --no-scripts --ansi
29+
composer require yiisoft/yii2:22.0.x-dev --prefer-dist --no-progress --no-interaction --no-scripts --ansi
3030
os: >-
3131
['ubuntu-latest']
3232
php: >-

composer.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"license": "mit",
1010
"require": {
1111
"php": ">=8.1",
12-
"nikic/php-parser": "^4.1",
13-
"phpstan/phpstan": "^2.0",
14-
"yiisoft/yii2": "^2.0.49 || ^22"
12+
"nikic/php-parser": "^4.1|^5.4.0",
13+
"phpstan/phpstan": "^2.1",
14+
"yiisoft/yii2": "^2.0.52 || ^22"
1515
},
1616
"require-dev": {
1717
"maglnet/composer-require-checker": "^4.7",
@@ -21,12 +21,12 @@
2121
},
2222
"autoload": {
2323
"psr-4": {
24-
"Yii2\\Extensions\\PHPStan\\": "src"
24+
"yii2\\extensions\\phpstan\\": "src"
2525
}
2626
},
2727
"autoload-dev": {
2828
"psr-4": {
29-
"Yii2\\Extensions\\PHPStan\\Tests\\": "tests"
29+
"yii2\\extensions\\phpstan\\tests\\": "tests"
3030
}
3131
},
3232
"extra": {
@@ -37,14 +37,16 @@
3737
"config": {
3838
"sort-packages": true,
3939
"allow-plugins": {
40+
"ondrejmirtes/composer-attribute-collector": true,
4041
"yiisoft/yii2-composer": true
4142
}
4243
},
4344
"scripts": {
44-
"check-dependencies": "composer-require-checker",
45-
"ecs": "ecs check",
46-
"phpstan": "phpstan",
47-
"test": "phpunit"
45+
"check-dependencies": "./vendor/bin/composer-require-checker check",
46+
"ecs": "./vendor/bin/ecs --fix",
47+
"rector": "./vendor/bin/rector process src",
48+
"static": "./vendor/bin/phpstan analyse src --memory-limit=512M",
49+
"tests": "./vendor/bin/phpunit"
4850
},
4951
"repositories": [
5052
{

ecs.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
use PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer;
66
use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer;
77
use PhpCsFixer\Fixer\ClassNotation\OrderedTraitsFixer;
8+
use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer;
89
use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer;
10+
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
11+
use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer;
912
use Symplify\EasyCodingStandard\Config\ECSConfig;
1013

1114
return ECSConfig::configure()
@@ -15,6 +18,19 @@
1518
'space_before_parenthesis' => true,
1619
],
1720
)
21+
->withConfiguredRule(
22+
OrderedImportsFixer::class,
23+
[
24+
'imports_order' => ['class', 'function', 'const'],
25+
'sort_algorithm' => 'alpha',
26+
],
27+
)
28+
->withConfiguredRule(
29+
VisibilityRequiredFixer::class,
30+
[
31+
'elements' => [],
32+
],
33+
)
1834
->withFileExtensions(['php'])
1935
->withPaths(
2036
[
@@ -28,12 +44,13 @@
2844
comments:true,
2945
docblocks: true,
3046
namespaces: true,
31-
psr12: true
47+
strict: true,
3248
)
3349
->withRules(
3450
[
3551
NoUnusedImportsFixer::class,
3652
OrderedClassElementsFixer::class,
3753
OrderedTraitsFixer::class,
54+
SingleQuoteFixer::class,
3855
]
3956
);

extension.neon

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ parametersSchema:
1111

1212
services:
1313
-
14-
class: Yii2\Extensions\PHPStan\Reflection\ApplicationPropertiesClassReflectionExtension
14+
class: yii2\extensions\phpstan\reflection\ApplicationPropertiesClassReflectionExtension
1515
tags: [phpstan.broker.propertiesClassReflectionExtension]
1616
-
17-
class: Yii2\Extensions\PHPStan\Reflection\RequestMethodsClassReflectionExtension
17+
class: yii2\extensions\phpstan\reflection\RequestMethodsClassReflectionExtension
1818
tags: [phpstan.broker.methodsClassReflectionExtension]
1919
-
20-
class: Yii2\Extensions\PHPStan\Reflection\RequestPropertiesClassReflectionExtension
20+
class: yii2\extensions\phpstan\reflection\RequestPropertiesClassReflectionExtension
2121
tags: [phpstan.broker.propertiesClassReflectionExtension]
2222
-
23-
class: Yii2\Extensions\PHPStan\Reflection\ResponsePropertiesClassReflectionExtension
23+
class: yii2\extensions\phpstan\reflection\ResponsePropertiesClassReflectionExtension
2424
tags: [phpstan.broker.propertiesClassReflectionExtension]
2525
-
26-
class: Yii2\Extensions\PHPStan\Reflection\UserPropertiesClassReflectionExtension
26+
class: yii2\extensions\phpstan\reflection\UserPropertiesClassReflectionExtension
2727
tags: [phpstan.broker.propertiesClassReflectionExtension]
2828
-
29-
class: Yii2\Extensions\PHPStan\Type\ActiveQueryDynamicMethodReturnTypeExtension
29+
class: yii2\extensions\phpstan\type\ActiveQueryDynamicMethodReturnTypeExtension
3030
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
3131
-
32-
class: Yii2\Extensions\PHPStan\Type\ActiveRecordDynamicMethodReturnTypeExtension
32+
class: yii2\extensions\phpstan\type\ActiveRecordDynamicMethodReturnTypeExtension
3333
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
3434
-
35-
class: Yii2\Extensions\PHPStan\Type\HeaderCollectionDynamicMethodReturnTypeExtension
35+
class: yii2\extensions\phpstan\type\HeaderCollectionDynamicMethodReturnTypeExtension
3636
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
3737
-
38-
class: Yii2\Extensions\PHPStan\Type\ActiveRecordDynamicStaticMethodReturnTypeExtension
38+
class: yii2\extensions\phpstan\type\ActiveRecordDynamicStaticMethodReturnTypeExtension
3939
tags: [phpstan.broker.dynamicStaticMethodReturnTypeExtension]
4040
-
41-
class: Yii2\Extensions\PHPStan\Type\ContainerDynamicMethodReturnTypeExtension
41+
class: yii2\extensions\phpstan\type\ContainerDynamicMethodReturnTypeExtension
4242
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
4343

44-
- Yii2\Extensions\PHPStan\ServiceMap(%yii2.config_path%)
44+
- yii2\extensions\phpstan\ServiceMap(%yii2.config_path%)

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ parameters:
1818
- vendor/yiisoft/yii2/Yii.php
1919

2020
yii2:
21-
config_path: tests/assets/yii-config-valid.php
21+
config_path: tests/fixture/yii-config-valid.php

0 commit comments

Comments
 (0)