Skip to content

Commit

Permalink
just return null instead of the default type
Browse files Browse the repository at this point in the history
  • Loading branch information
verfriemelt-dot-org committed Dec 12, 2022
1 parent eddc6a2 commit 330a2f5
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/Type/Php/DateIntervalDynamicReturnTypeExtension.php
Expand Up @@ -6,12 +6,12 @@
use PhpParser\Node\Expr\StaticCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\DynamicStaticMethodReturnTypeExtension;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeUtils;

class DateIntervalDynamicReturnTypeExtension implements DynamicStaticMethodReturnTypeExtension
{
Expand All @@ -28,16 +28,10 @@ public function isStaticMethodSupported(MethodReflection $methodReflection): boo

public function getTypeFromStaticMethodCall(MethodReflection $methodReflection, StaticCall $methodCall, Scope $scope): ?Type
{
$defaultReturnType = ParametersAcceptorSelector::selectFromArgs(
$scope,
$methodCall->getArgs(),
$methodReflection->getVariants(),
)->getReturnType();

$dateTimeString = $scope->getType($methodCall->getArgs()[0]->value);
$dateTimeString = TypeUtils::getConstantStrings($scope->getType($methodCall->getArgs()[0]->value));

if (!($dateTimeString instanceof ConstantStringType)) {
return $defaultReturnType;
return null;
}

$isValid = DateInterval::createFromDateString($dateTimeString->getValue()) !== false;
Expand Down

0 comments on commit 330a2f5

Please sign in to comment.