Skip to content

Commit dbd50be

Browse files
authored
Add baseline for PHPStan 1.10 new deprecations (#518)
* Add baseline for PHPStan 1.10 new deprecations * fix constructor to ImpossibleCheckTypeMethodCallRule in test
1 parent e6f6191 commit dbd50be

10 files changed

+85
-32
lines changed

phpstan-baseline.neon

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
5+
count: 1
6+
path: src/Rules/Deprecations/ConditionManagerCreateInstanceContextConfigurationRule.php
7+
8+
-
9+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
10+
count: 1
11+
path: src/Rules/Deprecations/ConditionManagerCreateInstanceContextConfigurationRule.php
12+
13+
-
14+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
15+
count: 1
16+
path: src/Rules/Drupal/LoadIncludeBase.php
17+
18+
-
19+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantArrayType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantArrays\\(\\) instead\\.$#"
20+
count: 1
21+
path: src/Rules/Drupal/RenderCallbackRule.php
22+
23+
-
24+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantStringType is error\\-prone and deprecated\\. Use Type\\:\\:getConstantStrings\\(\\) instead\\.$#"
25+
count: 3
26+
path: src/Rules/Drupal/RenderCallbackRule.php
27+
28+
-
29+
message: "#^Doing instanceof PHPStan\\\\Type\\\\Generic\\\\GenericClassStringType is error\\-prone and deprecated\\. Use Type\\:\\:isClassStringType\\(\\) and Type\\:\\:getClassStringObjectType\\(\\) instead\\.$#"
30+
count: 1
31+
path: src/Rules/Drupal/RenderCallbackRule.php
32+
33+
-
34+
message: "#^Doing instanceof PHPStan\\\\Type\\\\IntersectionType is error\\-prone and deprecated\\.$#"
35+
count: 1
36+
path: src/Rules/Drupal/RenderCallbackRule.php
37+
38+
-
39+
message: "#^Doing instanceof PHPStan\\\\Type\\\\ObjectType is error\\-prone and deprecated\\. Use Type\\:\\:isObject\\(\\) or Type\\:\\:getObjectClassNames\\(\\) instead\\.$#"
40+
count: 1
41+
path: src/Rules/Drupal/Tests/BrowserTestBaseDefaultThemeRule.php
42+
43+
-
44+
message: "#^Doing instanceof PHPStan\\\\Type\\\\ObjectType is error\\-prone and deprecated\\. Use Type\\:\\:isObject\\(\\) or Type\\:\\:getObjectClassNames\\(\\) instead\\.$#"
45+
count: 1
46+
path: src/Type/DrupalStaticEntityQueryDynamicReturnTypeExtension.php
47+
48+
-
49+
message: "#^Doing instanceof PHPStan\\\\Type\\\\ObjectType is error\\-prone and deprecated\\. Use Type\\:\\:isObject\\(\\) or Type\\:\\:getObjectClassNames\\(\\) instead\\.$#"
50+
count: 1
51+
path: src/Type/EntityQuery/EntityQueryDynamicReturnTypeExtension.php
52+
53+
-
54+
message: "#^Doing instanceof PHPStan\\\\Type\\\\ObjectType is error\\-prone and deprecated\\. Use Type\\:\\:isObject\\(\\) or Type\\:\\:getObjectClassNames\\(\\) instead\\.$#"
55+
count: 1
56+
path: src/Type/EntityStorage/EntityStorageDynamicReturnTypeExtension.php
57+
58+
-
59+
message: "#^Doing instanceof PHPStan\\\\Type\\\\ObjectType is error\\-prone and deprecated\\. Use Type\\:\\:isObject\\(\\) or Type\\:\\:getObjectClassNames\\(\\) instead\\.$#"
60+
count: 2
61+
path: src/Type/EntityStorage/GetQueryReturnTypeExtension.php
62+
63+
-
64+
message: "#^Doing instanceof PHPStan\\\\Type\\\\ObjectType is error\\-prone and deprecated\\. Use Type\\:\\:isObject\\(\\) or Type\\:\\:getObjectClassNames\\(\\) instead\\.$#"
65+
count: 1
66+
path: src/Type/EntityTypeManagerGetStorageDynamicReturnTypeExtension.php

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ parameters:
1212
- tests/src/Rules/data/*.php
1313
dynamicConstantNames:
1414
- Drupal::VERSION
15+
includes:
16+
- phpstan-baseline.neon

src/Type/DrupalClassResolverReturnType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PHPStan\Analyser\Scope;
1111
use PHPStan\Reflection\MethodReflection;
1212
use PHPStan\Reflection\ParametersAcceptorSelector;
13-
use PHPStan\Type\Constant\ConstantStringType;
1413
use PHPStan\Type\ObjectType;
1514
use PHPStan\Type\Type;
1615

@@ -24,15 +23,16 @@ public static function getType(
2423
ServiceMap $serviceMap
2524
): Type {
2625
$arg1 = $scope->getType($methodCall->getArgs()[0]->value);
27-
if (!$arg1 instanceof ConstantStringType) {
26+
if (count($arg1->getConstantStrings()) === 0) {
2827
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
2928
}
3029

31-
$serviceDefinition = $serviceMap->getService($arg1->getValue());
30+
$serviceName = $arg1->getConstantStrings()[0];
31+
$serviceDefinition = $serviceMap->getService($serviceName->getValue());
3232
if ($serviceDefinition instanceof DrupalServiceDefinition) {
3333
return $serviceDefinition->getType();
3434
}
3535

36-
return new ObjectType($arg1->getValue());
36+
return new ObjectType($serviceName->getValue());
3737
}
3838
}

src/Type/DrupalStaticEntityQueryDynamicReturnTypeExtension.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use PHPStan\Analyser\Scope;
1313
use PHPStan\Reflection\MethodReflection;
1414
use PHPStan\Reflection\ParametersAcceptorSelector;
15-
use PHPStan\Type\Constant\ConstantStringType;
1615
use PHPStan\Type\DynamicStaticMethodReturnTypeExtension;
1716
use PHPStan\Type\ObjectType;
1817
use PHPStan\Type\Type;
@@ -54,9 +53,8 @@ public function getTypeFromStaticMethodCall(
5453
return $returnType;
5554
}
5655
$type = $scope->getType($args[0]->value);
57-
if ($type instanceof ConstantStringType) {
58-
$entityTypeId = $type->getValue();
59-
} else {
56+
57+
if (count($type->getConstantStrings()) === 0) {
6058
// We're unsure what specific EntityQueryType it is, so let's stick
6159
// with the general class itself to ensure it gets access checked.
6260
return new EntityQueryType(
@@ -65,6 +63,7 @@ public function getTypeFromStaticMethodCall(
6563
$returnType->getClassReflection()
6664
);
6765
}
66+
$entityTypeId = $type->getConstantStrings()[0]->getValue();
6867
$entityType = $this->entityDataRepository->get($entityTypeId);
6968
$entityStorageType = $entityType->getStorageType();
7069
if ($entityStorageType === null) {

src/Type/EntityAccessControlHandlerReturnTypeExtension.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PHPStan\Analyser\Scope;
99
use PHPStan\Reflection\MethodReflection;
1010
use PHPStan\Type\BooleanType;
11-
use PHPStan\Type\Constant\ConstantBooleanType;
1211
use PHPStan\Type\DynamicMethodReturnTypeExtension;
1312
use PHPStan\Type\ObjectType;
1413
use PHPStan\Type\Type;
@@ -47,9 +46,9 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
4746
}
4847

4948
$returnAsObjectArg = $scope->getType($arg->value);
50-
if (!$returnAsObjectArg instanceof ConstantBooleanType) {
49+
if (!$returnAsObjectArg->isBoolean()->yes()) {
5150
return $returnType;
5251
}
53-
return $returnAsObjectArg->getValue() ? new ObjectType(AccessResultInterface::class) : new BooleanType();
52+
return $returnAsObjectArg->isTrue()->yes() ? new ObjectType(AccessResultInterface::class) : new BooleanType();
5453
}
5554
}

src/Type/EntityTypeManagerGetStorageDynamicReturnTypeExtension.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use PHPStan\Reflection\MethodReflection;
1212
use PHPStan\Reflection\ParametersAcceptorSelector;
1313
use PHPStan\ShouldNotHappenException;
14-
use PHPStan\Type\Constant\ConstantStringType;
1514
use PHPStan\Type\DynamicMethodReturnTypeExtension;
1615
use PHPStan\Type\ObjectType;
1716

@@ -71,13 +70,11 @@ public function getTypeFromMethodCall(
7170
}
7271

7372
$type = $scope->getType($arg1);
74-
if ($type instanceof ConstantStringType) {
75-
$entityTypeId = $type->getValue();
76-
} else {
77-
// @todo determine what these types are, and try to resolve entity name from.
73+
if (count($type->getConstantStrings()) === 0) {
7874
return $returnType;
7975
}
8076

77+
$entityTypeId = $type->getConstantStrings()[0]->getValue();
8178
$storageType = $this->entityDataRepository->get($entityTypeId)->getStorageType();
8279
if ($storageType !== null) {
8380
return $storageType;

src/Type/UrlToStringDynamicReturnTypeExtension.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PHPStan\Analyser\Scope;
99
use PHPStan\Reflection\MethodReflection;
1010
use PHPStan\Reflection\ParametersAcceptorSelector;
11-
use PHPStan\Type\Constant\ConstantBooleanType;
1211
use PHPStan\Type\DynamicMethodReturnTypeExtension;
1312
use PHPStan\Type\ObjectType;
1413
use PHPStan\Type\StringType;
@@ -37,14 +36,13 @@ public function getTypeFromMethodCall(
3736
}
3837

3938
$arg1 = $scope->getType($methodCall->getArgs()[0]->value);
40-
if (!$arg1 instanceof ConstantBooleanType) {
39+
if (!$arg1->isBoolean()->yes()) {
4140
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
4241
}
4342

44-
if (true === $arg1->getValue()) {
43+
if ($arg1->isTrue()->yes()) {
4544
return new ObjectType(GeneratedUrl::class);
4645
}
47-
4846
return new StringType();
4947
}
5048
}

tests/src/Reflection/EntityFieldsViaMagicReflectionExtensionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ public function testGetPropertyEntity(): void
9696
$classReflection = $this->createReflectionProvider()->getClass(EntityTest::class);
9797
$propertyReflection = $this->extension->getProperty($classReflection, 'field_myfield');
9898
$readableType = $propertyReflection->getReadableType();
99-
assert($readableType instanceof ObjectType);
99+
self::assertInstanceOf(ObjectType::class, $readableType);
100100
self::assertEquals(FieldItemListInterface::class, $readableType->getClassName());
101101
$writeableType = $propertyReflection->getWritableType();
102-
assert($writeableType instanceof ObjectType);
102+
self::assertInstanceOf(ObjectType::class, $writeableType);
103103
self::assertEquals(FieldItemListInterface::class, $writeableType->getClassName());
104104

105105
$originalPropertyReflection = $this->extension->getProperty($classReflection, 'original');
106106
$readableType = $originalPropertyReflection->getReadableType();
107-
assert($readableType instanceof ObjectType);
107+
self::assertInstanceOf(ObjectType::class, $readableType);
108108
self::assertEquals(ContentEntityInterface::class, $readableType->getClassName());
109109
}
110110

tests/src/Rules/AccessCheckImpossibleTypeCallRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ protected function getRule(): Rule
2626
),
2727
true,
2828
false,
29+
false,
2930
);
3031
}
3132

tests/src/Type/EntityTypeManagerGetStorageDynamicReturnTypeExtensionTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,8 @@
22

33
namespace mglaman\PHPStanDrupal\Tests\Type;
44

5-
use Drupal\Core\Entity\EntityTypeManager;
65
use mglaman\PHPStanDrupal\Tests\AdditionalConfigFilesTrait;
7-
use mglaman\PHPStanDrupal\Type\EntityTypeManagerGetStorageDynamicReturnTypeExtension;
8-
use PhpParser\Node\Arg;
9-
use PhpParser\Node\Expr;
10-
use PhpParser\Node\Expr\MethodCall;
11-
use PHPStan\Analyser\OutOfClassScope;
12-
use PHPStan\ShouldNotHappenException;
136
use PHPStan\Testing\TypeInferenceTestCase;
14-
use PHPStan\Type\ObjectType;
15-
use Prophecy\Prophet;
167

178
final class EntityTypeManagerGetStorageDynamicReturnTypeExtensionTest extends TypeInferenceTestCase
189
{

0 commit comments

Comments
 (0)