Skip to content

Commit 8bf527b

Browse files
committed
[BE] Deprecate various instanceof *Type in favour of new methods on Type interface
1 parent 27ab11b commit 8bf527b

File tree

8 files changed

+12
-20
lines changed

8 files changed

+12
-20
lines changed

UPGRADING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ return [
128128
];
129129
```
130130

131+
### Deprecate various `instanceof *Type` in favour of new methods on `Type` interface
132+
133+
Learn more: [Why Is instanceof *Type Wrong and Getting Deprecated?](https://phpstan.org/blog/why-is-instanceof-type-wrong-and-getting-deprecated)
134+
131135
### Changed `TypeSpecifier::create()` and `SpecifiedTypes` constructor parameters
132136

133137
[`PHPStan\Analyser\TypeSpecifier::create()`](https://apiref.phpstan.org/2.0.x/PHPStan.Analyser.TypeSpecifier.html#_create) now accepts (all parameters are required):

changelog-2.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Major new features 🚀
3939
* Report `instanceof` of classes not covered by backward compatibility promise (https://github.com/phpstan/phpstan-src/commit/ff4d02d62a7a2e2c4d928d48d31d49246dba7139)
4040
* Report `instanceof` of classes covered by backward compatibility promise but where the assumption might change (https://github.com/phpstan/phpstan-src/commit/996bc69fa977aa64f601bd82b8a0ae39be0cbeef)
4141
* Check that PHPStan class in class constant fetch is covered by backward compatibility promise (level 0) (https://github.com/phpstan/phpstan-src/commit/9e007251ce61788f6a0319a53f1de6cf801ed233)
42+
* Deprecate various `instanceof *Type` in favour of new methods on `Type` interface, (https://github.com/phpstan/phpstan-src/commit/436e6d3015cbeba4645d38bc7a6a865b9c6d7c74), learn more: [Why Is instanceof *Type Wrong and Getting Deprecated?](https://phpstan.org/blog/why-is-instanceof-type-wrong-and-getting-deprecated)
4243

4344
Bleeding edge (TODO move to other sections)
4445
=====================
@@ -61,7 +62,6 @@ Bleeding edge (TODO move to other sections)
6162
* Disable "unreachable branches" rules: UnreachableIfBranchesRule, UnreachableTernaryElseBranchRule, unreachable arm error in MatchExpressionRule
6263
* Because "always true" is always reported, these are no longer needed
6364
* IncompatibleDefaultParameterTypeRule for closures (https://github.com/phpstan/phpstan-src/commit/0264f5bc48448c7e02a23b82eef4177d0617a82f)
64-
* Deprecate various `instanceof *Type` in favour of new methods on `Type` interface, (https://github.com/phpstan/phpstan-src/commit/436e6d3015cbeba4645d38bc7a6a865b9c6d7c74), learn more: [Why Is instanceof *Type Wrong and Getting Deprecated?](https://phpstan.org/blog/why-is-instanceof-type-wrong-and-getting-deprecated)
6565
* Check variance of template types in properties ([#2314](https://github.com/phpstan/phpstan-src/pull/2314)), thanks @jiripudil!
6666
* 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
6767
* Check invalid PHPDocs in previously unchecked statement types (https://github.com/phpstan/phpstan-src/commit/9780d352f3264aac09ac7954f691de1877db8e01)

conf/bleedingEdge.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ parameters:
2020
disableUnreachableBranchesRules: true
2121
varTagType: true
2222
closureDefaultParameterTypeRule: true
23-
instanceofType: true
2423
propertyVariance: true
2524
callUserFunc: true
2625
magicConstantOutOfContext: true

conf/config.level0.neon

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ conditionalTags:
2323

2424
rules:
2525
- PHPStan\Rules\Api\ApiInstanceofRule
26+
- PHPStan\Rules\Api\ApiInstanceofTypeRule
2627
- PHPStan\Rules\Api\ApiInstantiationRule
2728
- PHPStan\Rules\Api\ApiClassConstFetchRule
2829
- PHPStan\Rules\Api\ApiClassExtendsRule
@@ -116,13 +117,6 @@ rules:
116117
- PHPStan\Rules\Whitespace\FileWhitespaceRule
117118

118119
services:
119-
-
120-
class: PHPStan\Rules\Api\ApiInstanceofTypeRule
121-
arguments:
122-
enabled: %featureToggles.instanceofType%
123-
deprecationRulesInstalled: %deprecationRulesInstalled%
124-
tags:
125-
- phpstan.rules.rule
126120
-
127121
class: PHPStan\Rules\Classes\ExistingClassInClassExtendsRule
128122
tags:

conf/config.neon

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ parameters:
4141
disableUnreachableBranchesRules: false
4242
varTagType: false
4343
closureDefaultParameterTypeRule: false
44-
instanceofType: false
4544
propertyVariance: false
4645
stricterFunctionMap: false
4746
callUserFunc: false
@@ -247,8 +246,6 @@ conditionalTags:
247246
phpstan.rules.rule: %exceptions.check.tooWideThrowType%
248247
PHPStan\Parser\CurlSetOptArgVisitor:
249248
phpstan.parser.richParserNodeVisitor: %featureToggles.curlSetOptTypes%
250-
PHPStan\Parser\TypeTraverserInstanceofVisitor:
251-
phpstan.parser.richParserNodeVisitor: %featureToggles.instanceofType%
252249

253250
services:
254251
-
@@ -339,6 +336,11 @@ services:
339336
tags:
340337
- phpstan.parser.richParserNodeVisitor
341338

339+
-
340+
class: PHPStan\Parser\TypeTraverserInstanceofVisitor
341+
tags:
342+
- phpstan.parser.richParserNodeVisitor
343+
342344
-
343345
class: PHPStan\Node\Printer\ExprPrinter
344346

conf/parametersSchema.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ parametersSchema:
4747
disableUnreachableBranchesRules: bool()
4848
varTagType: bool()
4949
closureDefaultParameterTypeRule: bool()
50-
instanceofType: bool()
5150
propertyVariance: bool()
5251
stricterFunctionMap: bool()
5352
callUserFunc: bool()

src/Rules/Api/ApiInstanceofTypeRule.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ final class ApiInstanceofTypeRule implements Rule
9494

9595
public function __construct(
9696
private ReflectionProvider $reflectionProvider,
97-
private bool $enabled,
98-
private bool $deprecationRulesInstalled,
9997
)
10098
{
10199
}
@@ -107,10 +105,6 @@ public function getNodeType(): string
107105

108106
public function processNode(Node $node, Scope $scope): array
109107
{
110-
if (!$this->enabled && !$this->deprecationRulesInstalled) {
111-
return [];
112-
}
113-
114108
if (!$node->class instanceof Node\Name) {
115109
return [];
116110
}

tests/PHPStan/Rules/Api/ApiInstanceofTypeRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ApiInstanceofTypeRuleTest extends RuleTestCase
1313

1414
public function getRule(): Rule
1515
{
16-
return new ApiInstanceofTypeRule($this->createReflectionProvider(), true, true);
16+
return new ApiInstanceofTypeRule($this->createReflectionProvider());
1717
}
1818

1919
public function testRule(): void

0 commit comments

Comments
 (0)