Skip to content

Commit 47bc4b0

Browse files
committed
Fix build
1 parent 76c050d commit 47bc4b0

File tree

3 files changed

+12
-71
lines changed

3 files changed

+12
-71
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"require": {
99
"php": "^7.4 || ^8.0",
10-
"phpstan/phpstan": "^1.7"
10+
"phpstan/phpstan": "^1.12"
1111
},
1212
"conflict": {
1313
"azjezz/psl": "<1.6||>=4.0"
@@ -17,9 +17,9 @@
1717
"composer/semver": "^3.3",
1818
"nikic/php-parser": "^4.14.0",
1919
"php-parallel-lint/php-parallel-lint": "^1.2",
20-
"phpstan/phpstan-phpunit": "^1.0",
21-
"phpstan/phpstan-strict-rules": "^1.0",
22-
"phpunit/phpunit": "^9.5"
20+
"phpstan/phpstan-phpunit": "^1.4.0",
21+
"phpstan/phpstan-strict-rules": "^1.6.0",
22+
"phpunit/phpunit": "^9.6"
2323
},
2424
"config": {
2525
"sort-packages": true

src/Type/MatchesTypeSpecifyingExtension.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PHPStan\Analyser\TypeSpecifierContext;
1111
use PHPStan\Reflection\MethodReflection;
1212
use PHPStan\Type\MethodTypeSpecifyingExtension;
13-
use PHPStan\Type\TypeWithClassName;
1413
use Psl\Type\TypeInterface;
1514

1615
class MatchesTypeSpecifyingExtension implements MethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
@@ -41,29 +40,10 @@ public function specifyTypes(MethodReflection $methodReflection, MethodCall $nod
4140
}
4241

4342
$specType = $scope->getType($node->var);
44-
if (!$specType instanceof TypeWithClassName) {
45-
return new SpecifiedTypes();
46-
}
47-
48-
$specTypeReflection = $specType->getClassReflection();
49-
if ($specTypeReflection === null) {
50-
return new SpecifiedTypes();
51-
}
52-
53-
$typeInterfaceAncestor = $specTypeReflection->getAncestorWithClassName(TypeInterface::class);
54-
if ($typeInterfaceAncestor === null) {
55-
return new SpecifiedTypes();
56-
}
57-
58-
$typeMap = $typeInterfaceAncestor->getActiveTemplateTypeMap();
59-
$t = $typeMap->getType('T');
60-
if ($t === null) {
61-
return new SpecifiedTypes();
62-
}
6343

6444
return $this->typeSpecifier->create(
6545
$args[0]->value,
66-
$t,
46+
$specType->getTemplateType(TypeInterface::class, 'T'),
6747
$context
6848
);
6949
}

src/Type/TypeShapeReturnTypeExtension.php

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
use PHPStan\Type\Constant\ConstantArrayType;
99
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
1010
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
11+
use PHPStan\Type\ErrorType;
1112
use PHPStan\Type\Generic\GenericObjectType;
1213
use PHPStan\Type\Type;
1314
use PHPStan\Type\TypeCombinator;
1415
use PHPStan\Type\TypeUtils;
15-
use PHPStan\Type\TypeWithClassName;
1616
use Psl\Type\Internal\OptionalType;
1717
use Psl\Type\TypeInterface;
1818
use function count;
@@ -40,12 +40,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
4040

4141
$results = [];
4242
foreach ($arrays as $array) {
43-
$result = $this->createResult($array);
44-
if ($result === null) {
45-
return null;
46-
}
47-
48-
$results[] = $result;
43+
$results[] = $this->createResult($array);
4944
}
5045

5146
return new GenericObjectType(
@@ -56,32 +51,12 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
5651
);
5752
}
5853

59-
private function createResult(ConstantArrayType $arrayType): ?Type
54+
private function createResult(ConstantArrayType $arrayType): Type
6055
{
6156
$builder = ConstantArrayTypeBuilder::createEmpty();
6257
foreach ($arrayType->getKeyTypes() as $key) {
6358
$valueType = $arrayType->getOffsetValueType($key);
64-
if (!$valueType instanceof TypeWithClassName) {
65-
return null;
66-
}
67-
68-
$valueClassReflection = $valueType->getClassReflection();
69-
if ($valueClassReflection === null) {
70-
return null;
71-
}
72-
73-
$typeInterfaceAncestor = $valueClassReflection->getAncestorWithClassName(TypeInterface::class);
74-
if ($typeInterfaceAncestor === null) {
75-
return null;
76-
}
77-
78-
$typeMap = $typeInterfaceAncestor->getActiveTemplateTypeMap();
79-
$t = $typeMap->getType('T');
80-
if ($t === null) {
81-
return null;
82-
}
83-
84-
[$type, $optional] = $this->extractOptional($t);
59+
[$type, $optional] = $this->extractOptional($valueType->getTemplateType(TypeInterface::class, 'T'));
8560

8661
$builder->setOffsetValueType($key, $type, $optional);
8762
}
@@ -94,26 +69,12 @@ private function createResult(ConstantArrayType $arrayType): ?Type
9469
*/
9570
private function extractOptional(Type $type): array
9671
{
97-
if (!$type instanceof TypeWithClassName) {
98-
return [$type, false];
99-
}
100-
101-
$classReflection = $type->getClassReflection();
102-
if ($classReflection === null) {
103-
return [$type, false];
104-
}
105-
$optionalTypeAncestor = $classReflection->getAncestorWithClassName(OptionalType::class);
106-
if ($optionalTypeAncestor === null) {
107-
return [$type, false];
108-
}
109-
110-
$typeMap = $optionalTypeAncestor->getActiveTemplateTypeMap();
111-
$t = $typeMap->getType('T');
112-
if ($t === null) {
72+
$optionalType = $type->getTemplateType(OptionalType::class, 'T');
73+
if ($optionalType instanceof ErrorType) {
11374
return [$type, false];
11475
}
11576

116-
return [$t, true];
77+
return [$optionalType, true];
11778
}
11879

11980
}

0 commit comments

Comments
 (0)