Skip to content

Commit b910ed8

Browse files
feat(): Enable strict rules and bleeding edge analysis, and update README.md with strict configuration examples. (#29)
1 parent 20e4bfc commit b910ed8

13 files changed

+61
-17
lines changed

.github/workflows/dependency-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ jobs:
2626
os: >-
2727
['ubuntu-latest']
2828
php: >-
29-
['8.1']
29+
['8.4']

.github/workflows/ecs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ jobs:
2828
os: >-
2929
['ubuntu-latest']
3030
php: >-
31-
['8.1']
31+
['8.4']

.github/workflows/static.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ jobs:
3030
os: >-
3131
['ubuntu-latest']
3232
php: >-
33-
['8.1']
33+
['8.4']

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
## 0.2.3 June 06, 2025
44

5-
- Enh #25: Add support for PHPStan Extension Installer (@samuelrajan747)
6-
- Enh #26: Add PHPStan extension installer instructions and improve `ServiceMap` configuration handling (@terabytesoftw)
5+
- Enh #25: Add support for `PHPStan` Extension Installer (@samuelrajan747)
6+
- Enh #26: Add `PHPStan` extension installer instructions and improve `ServiceMap` configuration handling (@terabytesoftw)
77
- Bug #27: Enhance error handling in `ServiceMap` for invalid configuration structures and add corresponding test cases (@terabytesoftw)
88
- Bug #28: Refactor component handling in `ServiceMap` to improve variable naming and streamline logic (@terabytesoftw)
9+
- Enh #29: Enable strict rules and bleeding edge analysis, and update `README.md` with strict configuration examples (@terabytesoftw)
910

1011
## 0.2.2 June 04, 2025
1112

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,12 @@ constants.
119119
To maintain the `Yii2` constants recognition, you must include them explicitly along with your custom constants, as
120120
shown above.
121121

122-
### Advanced Configuration Example
122+
### Strict Configuration
123123

124124
```neon
125125
includes:
126+
- phar://phpstan.phar/conf/bleedingEdge.neon
127+
- vendor/phpstan/phpstan-strict-rules/rules.neon
126128
- vendor/yii2-extensions/phpstan/extension.neon
127129
128130
parameters:
@@ -154,6 +156,16 @@ parameters:
154156
155157
yii2:
156158
config_path: %currentWorkingDirectory%/config/web.php
159+
160+
# Enable strict advanced checks
161+
checkImplicitMixed: true
162+
checkBenevolentUnionTypes: true
163+
checkUninitializedProperties: true
164+
checkMissingCallableSignature: true
165+
checkTooWideReturnTypesInProtectedAndPublicMethods: true
166+
reportAnyTypeWideningInVarTag: true
167+
reportPossiblyNonexistentConstantArrayOffset: true
168+
reportPossiblyNonexistentGeneralArrayOffset: true
157169
```
158170

159171
### PHPstan extension installer

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"require-dev": {
1717
"maglnet/composer-require-checker": "^4.7",
1818
"phpstan/phpstan-phpunit": "^2.0",
19+
"phpstan/phpstan-strict-rules": "^2.0.3",
1920
"phpunit/phpunit": "^10.2",
2021
"symplify/easy-coding-standard": "^12.1"
2122
},

phpstan.neon

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
includes:
2-
- extension.neon
3-
- vendor/phpstan/phpstan-phpunit/extension.neon
4-
- vendor/phpstan/phpstan-phpunit/rules.neon
5-
- phar://phpstan.phar/conf/bleedingEdge.neon
2+
- extension.neon
3+
- phar://phpstan.phar/conf/bleedingEdge.neon
4+
- vendor/phpstan/phpstan-strict-rules/rules.neon
65

76
parameters:
87
bootstrapFiles:
@@ -16,3 +15,13 @@ parameters:
1615

1716
paths:
1817
- src
18+
19+
# Enable strict advanced checks
20+
checkImplicitMixed: true
21+
checkBenevolentUnionTypes: true
22+
checkUninitializedProperties: true
23+
checkMissingCallableSignature: true
24+
checkTooWideReturnTypesInProtectedAndPublicMethods: true
25+
reportAnyTypeWideningInVarTag: true
26+
reportPossiblyNonexistentConstantArrayOffset: true
27+
reportPossiblyNonexistentGeneralArrayOffset: true

src/reflection/ApplicationPropertiesClassReflectionExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,6 @@ public function hasProperty(ClassReflection $classReflection, string $propertyNa
142142

143143
return $classReflection->hasNativeProperty($propertyName)
144144
|| $this->annotationsProperties->hasProperty($classReflection, $propertyName)
145-
|| $this->serviceMap->getComponentClassById($propertyName);
145+
|| $this->serviceMap->getComponentClassById($propertyName) !== null;
146146
}
147147
}

src/type/ActiveQueryDynamicMethodReturnTypeExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ final class ActiveQueryDynamicMethodReturnTypeExtension implements DynamicMethod
6262
* Returns the class name for which this dynamic return type extension applies.
6363
*
6464
* @return string Fully qualified class name of the supported class.
65+
*
66+
* @phpstan-return class-string
6567
*/
6668
public function getClass(): string
6769
{

src/type/ActiveRecordDynamicMethodReturnTypeExtension.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use yii\db\ActiveRecord;
1414

1515
use function count;
16-
use function get_class;
1716
use function in_array;
1817
use function sprintf;
1918

@@ -60,6 +59,8 @@ final class ActiveRecordDynamicMethodReturnTypeExtension implements DynamicMetho
6059
* autocompletion for dynamic relation definitions.
6160
*
6261
* @return string Fully qualified class name of the supported {@see ActiveRecord} class.
62+
*
63+
* @phpstan-return class-string
6364
*/
6465
public function getClass(): string
6566
{
@@ -90,13 +91,12 @@ public function getTypeFromMethodCall(
9091
MethodCall $methodCall,
9192
Scope $scope,
9293
): Type {
93-
$arg = $methodCall->args[0];
94+
$arg = $methodCall->getRawArgs()[0] ?? null;
9495

9596
if ($arg instanceof Arg === false) {
9697
throw new ShouldNotHappenException(
9798
sprintf(
98-
'Unexpected arg %s during method call %s at line %d',
99-
get_class($arg),
99+
'Invalid or missing argument for method %s at line %d',
100100
$methodReflection->getName(),
101101
$methodCall->getLine(),
102102
),

0 commit comments

Comments
 (0)