Skip to content

Commit c8fdd3c

Browse files
committed
Merge branch 'vrana-assert'
2 parents c21612b + 2d732ea commit c8fdd3c

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/TypeValidator/PHPStan/Type/ReturnTypeExtension.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,21 @@ public function setTypeSpecifier(Analyser\TypeSpecifier $typeSpecifier): void
4444
* @param array<Node\Arg> $args [0] = checked variable, [1] = type description
4545
*/
4646
protected function narrowTypes(array $args, Analyser\Scope $scope): Analyser\SpecifiedTypes
47+
{
48+
return $this->typeSpecifier->create(
49+
$args[0]->value,
50+
$this->prepareType($args[1]->value, $scope),
51+
Analyser\TypeSpecifierContext::createTruthy(),
52+
$scope,
53+
);
54+
}
55+
56+
57+
protected function prepareType(Node\Expr $typeDescriptionArg, Analyser\Scope $scope): Type\Type
4758
{
4859
$filename = $scope->getFile();
4960

50-
$typeDescriptionArg = $args[1]->value;
51-
$typeDescriptionType = $scope->getType($args[1]->value);
61+
$typeDescriptionType = $scope->getType($typeDescriptionArg);
5262
$typeDescriptionConstantStrings = $typeDescriptionType->getConstantStrings();
5363

5464
try {
@@ -61,12 +71,7 @@ protected function narrowTypes(array $args, Analyser\Scope $scope): Analyser\Spe
6171
self::$cache[$filename][$typeDescription] = (new PHPStan\Helpers\TypeConverter($this->typeNodeResolver, $filename, $typeDescription))->convertToType();
6272
}
6373

64-
return $this->typeSpecifier->create(
65-
$args[0]->value,
66-
self::$cache[$filename][$typeDescription],
67-
Analyser\TypeSpecifierContext::createTruthy(),
68-
$scope,
69-
);
74+
return self::$cache[$filename][$typeDescription];
7075
} else {
7176
self::error($filename, sprintf('Bad type description \'%s\' (only constant string type descriptions are allowed)', $typeDescriptionType->describe(Type\VerbosityLevel::precise())), $typeDescriptionArg);
7277
}

0 commit comments

Comments
 (0)