Skip to content

Commit e873602

Browse files
committed
Fixed documentation of type-specifying extensions
1 parent e6cd7ec commit e873602

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,16 +872,22 @@ public function getClass(): string
872872
return \PHPUnit\Framework\Assert::class;
873873
}
874874

875-
public function isStaticMethodSupported(MethodReflection $staticMethodReflection, StaticCall $node, TypeSpecifierContext $context): bool;
875+
public function isStaticMethodSupported(MethodReflection $staticMethodReflection, StaticCall $node, TypeSpecifierContext $context): bool
876876
{
877877
// The $context argument tells us if we're in an if condition or not (as in this case).
878-
return $staticMethodReflection->getName() === 'assertNotNull' && $context->null();
878+
// Is assertNotNull called with at least 1 argument?
879+
return $staticMethodReflection->getName() === 'assertNotNull' && $context->null() && isset($node->args[0]);
879880
}
880881

881882
public function specifyTypes(MethodReflection $staticMethodReflection, StaticCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes
882883
{
884+
$expr = $node->args[0]->value;
885+
$typeBefore = $scope->getType($expr);
886+
$type = TypeCombinator::removeNull($typeBefore);
887+
883888
// Assuming extension implements \PHPStan\Analyser\TypeSpecifierAwareExtension.
884-
return $this->typeSpecifier->create($node->var, \PHPStan\Type\TypeCombinator::removeNull($scope->getType($node->var)), $context);
889+
890+
return $this->typeSpecifier->create($expr, $type, TypeSpecifierContext::createTruthy());
885891
}
886892
```
887893

0 commit comments

Comments
 (0)