Skip to content

Commit 3758793

Browse files
committed
[BE] Support @readonly property and @immutable class PHPDoc
1 parent 4399504 commit 3758793

File tree

9 files changed

+8
-36
lines changed

9 files changed

+8
-36
lines changed

changelog-2.0.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Major new features 🚀
3636
* ArrayUnpackingRule (level 3) ([#856](https://github.com/phpstan/phpstan-src/pull/856)), thanks @canvural!
3737
* Check unresolvable parameters (level 5) ([#1319](https://github.com/phpstan/phpstan-src/pull/1319)), thanks @rvanvelzen!
3838
* Enforce `@no-named-arguments` (level 5) (https://github.com/phpstan/phpstan-src/commit/74ba8c23696948f2647d880df72f375346f41010), #5968
39+
* Support `@readonly` property and `@immutable` class PHPDoc ([#1295](https://github.com/phpstan/phpstan-src/pull/1295), [#1335](https://github.com/phpstan/phpstan-src/pull/1335)), #4082, thanks @herndlm!
40+
* Add `@readonly` rule that disallows default values (level 0) ([#1391](https://github.com/phpstan/phpstan-src/pull/1391)), thanks @herndlm!
3941
* IncompatibleDefaultParameterTypeRule for closures (level 2) (https://github.com/phpstan/phpstan-src/commit/0264f5bc48448c7e02a23b82eef4177d0617a82f)
4042
* Added previously absent type checks (level 0)
4143
* Check existing classes in `@phpstan-self-out` (https://github.com/phpstan/phpstan-src/commit/6838669976bf20232abde36ecdd52b1770fa50c9)
@@ -67,9 +69,7 @@ Bleeding edge (TODO move to other sections)
6769
=====================
6870

6971
* Rules for checking direct calls to `__construct()` (level 2) ([#1208](https://github.com/phpstan/phpstan-src/pull/1208)), #7022, thanks @muno92!
70-
* Support `@readonly` property and `@immutable` class PHPDoc ([#1295](https://github.com/phpstan/phpstan-src/pull/1295), [#1335](https://github.com/phpstan/phpstan-src/pull/1335)), #4082, thanks @herndlm!
7172
* Move IllegalConstructorMethodCallRule and IllegalConstructorStaticCallRule to phpstan-strict-rules (https://github.com/phpstan/phpstan-src/commit/124b30f98c182193187be0b9c2e151e477429b7a, https://github.com/phpstan/phpstan-strict-rules/commit/0c82c96f2a55d8b91bbc7ee6512c94f68a206b43)
72-
* Add `@readonly` rule that disallows default values ([#1391](https://github.com/phpstan/phpstan-src/pull/1391)), thanks @herndlm!
7373
* Report narrowing `PHPStan\Type\Type` interface via `@var` (https://github.com/phpstan/phpstan-src/commit/713b98fb107213c28e3d8c8b4b43c5f5fc47c144), https://github.com/nunomaduro/larastan/issues/1567#issuecomment-1460445389
7474
* Check invalid PHPDocs in previously unchecked statement types (https://github.com/phpstan/phpstan-src/commit/9780d352f3264aac09ac7954f691de1877db8e01)
7575
* InvalidPHPStanDocTagRule in StubValidator (https://github.com/phpstan/phpstan-src/commit/9c2552b7e744926d1a74c1ba8fd32c64079eed61)

conf/bleedingEdge.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ parameters:
44
skipCheckGenericClasses!: []
55
stricterFunctionMap: true
66

7-
readOnlyByPhpDoc: true
87
pure: true

conf/config.level0.neon

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ parameters:
22
customRulesetUsed: false
33

44
conditionalTags:
5-
PHPStan\Rules\Properties\MissingReadOnlyByPhpDocPropertyAssignRule:
6-
phpstan.rules.rule: %featureToggles.readOnlyByPhpDoc%
7-
PHPStan\Rules\Properties\ReadOnlyByPhpDocPropertyRule:
8-
phpstan.rules.rule: %featureToggles.readOnlyByPhpDoc%
95
PHPStan\Rules\Properties\UninitializedPropertyRule:
106
phpstan.rules.rule: %checkUninitializedProperties%
117

@@ -98,9 +94,11 @@ rules:
9894
- PHPStan\Rules\Properties\AccessStaticPropertiesInAssignRule
9995
- PHPStan\Rules\Properties\InvalidCallablePropertyTypeRule
10096
- PHPStan\Rules\Properties\MissingReadOnlyPropertyAssignRule
97+
- PHPStan\Rules\Properties\MissingReadOnlyByPhpDocPropertyAssignRule
10198
- PHPStan\Rules\Properties\PropertiesInInterfaceRule
10299
- PHPStan\Rules\Properties\PropertyAttributesRule
103100
- PHPStan\Rules\Properties\ReadOnlyPropertyRule
101+
- PHPStan\Rules\Properties\ReadOnlyByPhpDocPropertyRule
104102
- PHPStan\Rules\Regexp\RegularExpressionPatternRule
105103
- PHPStan\Rules\Regexp\RegularExpressionQuotingRule
106104
- PHPStan\Rules\Traits\ConflictingTraitConstantsRule
@@ -203,9 +201,6 @@ services:
203201
tags:
204202
- phpstan.rules.rule
205203

206-
-
207-
class: PHPStan\Rules\Properties\MissingReadOnlyByPhpDocPropertyAssignRule
208-
209204
-
210205
class: PHPStan\Rules\Properties\OverridingPropertyRule
211206
arguments:
@@ -214,9 +209,6 @@ services:
214209
tags:
215210
- phpstan.rules.rule
216211

217-
-
218-
class: PHPStan\Rules\Properties\ReadOnlyByPhpDocPropertyRule
219-
220212
-
221213
class: PHPStan\Rules\Properties\UninitializedPropertyRule
222214

conf/config.level2.neon

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ rules:
3737
- PHPStan\Rules\Generics\MethodTagTemplateTypeRule
3838
- PHPStan\Rules\Generics\MethodTagTemplateTypeTraitRule
3939
- PHPStan\Rules\Generics\MethodSignatureVarianceRule
40+
- PHPStan\Rules\Generics\PropertyVarianceRule
4041
- PHPStan\Rules\Generics\TraitTemplateTypeRule
4142
- PHPStan\Rules\Generics\UsedTraitsRule
4243
- PHPStan\Rules\Methods\CallPrivateMethodThroughStaticRule
@@ -117,12 +118,6 @@ services:
117118
class: PHPStan\Rules\PhpDoc\InvalidPHPStanDocTagRule
118119
tags:
119120
- phpstan.rules.rule
120-
-
121-
class: PHPStan\Rules\Generics\PropertyVarianceRule
122-
arguments:
123-
readOnlyByPhpDoc: %featureToggles.readOnlyByPhpDoc%
124-
tags:
125-
- phpstan.rules.rule
126121
-
127122
class: PHPStan\Rules\Pure\PureFunctionRule
128123

conf/config.level3.neon

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
includes:
22
- config.level2.neon
33

4-
conditionalTags:
5-
PHPStan\Rules\Properties\ReadOnlyByPhpDocPropertyAssignRefRule:
6-
phpstan.rules.rule: %featureToggles.readOnlyByPhpDoc%
7-
PHPStan\Rules\Properties\ReadOnlyByPhpDocPropertyAssignRule:
8-
phpstan.rules.rule: %featureToggles.readOnlyByPhpDoc%
9-
104
rules:
115
- PHPStan\Rules\Arrays\ArrayDestructuringRule
126
- PHPStan\Rules\Arrays\ArrayUnpackingRule
@@ -23,7 +17,9 @@ rules:
2317
- PHPStan\Rules\Methods\ReturnTypeRule
2418
- PHPStan\Rules\Properties\DefaultValueTypesAssignedToPropertiesRule
2519
- PHPStan\Rules\Properties\ReadOnlyPropertyAssignRule
20+
- PHPStan\Rules\Properties\ReadOnlyByPhpDocPropertyAssignRule
2621
- PHPStan\Rules\Properties\ReadOnlyPropertyAssignRefRule
22+
- PHPStan\Rules\Properties\ReadOnlyByPhpDocPropertyAssignRefRule
2723
- PHPStan\Rules\Properties\TypesAssignedToPropertiesRule
2824
- PHPStan\Rules\Variables\ParameterOutAssignedTypeRule
2925
- PHPStan\Rules\Variables\ParameterOutExecutionEndTypeRule
@@ -83,9 +79,3 @@ services:
8379
reportMaybes: %reportMaybes%
8480
tags:
8581
- phpstan.rules.rule
86-
87-
-
88-
class: PHPStan\Rules\Properties\ReadOnlyByPhpDocPropertyAssignRefRule
89-
90-
-
91-
class: PHPStan\Rules\Properties\ReadOnlyByPhpDocPropertyAssignRule

conf/config.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ parameters:
2424
bleedingEdge: false
2525
skipCheckGenericClasses: []
2626
illegalConstructorMethodCall: false
27-
readOnlyByPhpDoc: false
2827
stricterFunctionMap: false
2928
pure: false
3029
fileExtensions:

conf/parametersSchema.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ parametersSchema:
3030
bleedingEdge: bool(),
3131
skipCheckGenericClasses: listOf(string()),
3232
illegalConstructorMethodCall: bool(),
33-
readOnlyByPhpDoc: bool()
3433
stricterFunctionMap: bool()
3534
pure: bool()
3635
])

src/Rules/Generics/PropertyVarianceRule.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ final class PropertyVarianceRule implements Rule
1818

1919
public function __construct(
2020
private VarianceCheck $varianceCheck,
21-
private bool $readOnlyByPhpDoc,
2221
)
2322
{
2423
}
@@ -42,7 +41,7 @@ public function processNode(Node $node, Scope $scope): array
4241
return [];
4342
}
4443

45-
$variance = $node->isReadOnly() || ($this->readOnlyByPhpDoc && $node->isReadOnlyByPhpDoc())
44+
$variance = $node->isReadOnly() || $node->isReadOnlyByPhpDoc()
4645
? TemplateTypeVariance::createCovariant()
4746
: TemplateTypeVariance::createInvariant();
4847

tests/PHPStan/Rules/Generics/PropertyVarianceRuleTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ protected function getRule(): Rule
1616
{
1717
return new PropertyVarianceRule(
1818
self::getContainer()->getByType(VarianceCheck::class),
19-
true,
2019
);
2120
}
2221

0 commit comments

Comments
 (0)