Skip to content

Commit

Permalink
Update src/Type/Php/DateIntervalDynamicReturnTypeExtension.php
Browse files Browse the repository at this point in the history
Co-authored-by: Markus Staab <maggus.staab@googlemail.com>
  • Loading branch information
verfriemelt-dot-org and staabm committed Dec 14, 2022
1 parent 330a2f5 commit b00058d
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/Type/Php/DateIntervalDynamicReturnTypeExtension.php
Expand Up @@ -28,15 +28,26 @@ public function isStaticMethodSupported(MethodReflection $methodReflection): boo

public function getTypeFromStaticMethodCall(MethodReflection $methodReflection, StaticCall $methodCall, Scope $scope): ?Type
{
$dateTimeString = TypeUtils::getConstantStrings($scope->getType($methodCall->getArgs()[0]->value));

if (!($dateTimeString instanceof ConstantStringType)) {
return null;
$strings = $scope->getType($methodCall->getArgs()[0]->value)->getConstantStrings();

if ($strings === []) {
return null;
}

if (count($strings) === 1) {
if (DateInterval::createFromDateString($dateTimeString->getValue()) === false) {
return new ConstantBooleanType(false);
}
return new ObjectType(DateInterval::class);
}

foreach($strings as $string) {
if (DateInterval::createFromDateString($dateTimeString->getValue()) === false) {
return null;
}
}

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

return $isValid ? new ObjectType(DateInterval::class) : new ConstantBooleanType(false);
return new ObjectType(DateInterval::class);
}

}

0 comments on commit b00058d

Please sign in to comment.