Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
Alban-io committed Jan 30, 2022
1 parent 362f9bf commit 133991a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
23 changes: 15 additions & 8 deletions src/Type/Php/DatePeriodConstructorReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,28 @@ public function getTypeFromStaticMethodCall(MethodReflection $methodReflection,
$thirdArgType = $scope->getType($methodCall->getArgs()[2]->value);
}

if (
$thirdArgType instanceof ObjectType
&& (new ObjectType(DateTimeInterface::class))->isSuperTypeOf($thirdArgType)->yes()
) {
if (!$thirdArgType instanceof Type) {
return new GenericObjectType(DatePeriod::class, [
new NullType(),
new IntegerType(),
]);
}

if ((new ObjectType(DateTimeInterface::class))->isSuperTypeOf($thirdArgType)->yes()) {
return new GenericObjectType(DatePeriod::class, [
new ObjectType(DateTimeInterface::class),
new NullType(),
]);
}

if ((new IntegerType())->isSuperTypeOf($thirdArgType)->yes()) {
return new GenericObjectType(DatePeriod::class, [
new ObjectType(DateTimeInterface::class),
new NullType(),
]);
}

return new GenericObjectType(DatePeriod::class, [
new NullType(),
new IntegerType(),
]);
return new ObjectType(DatePeriod::class);
}

}
6 changes: 3 additions & 3 deletions tests/PHPStan/Analyser/data/date-period-return-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
$datePeriodList = [];

$datePeriod = new DatePeriod($start, $interval, $end);
assertType(\DatePeriod::class, $datePeriod);
assertType(\DatePeriod::class . '<DateTimeInterface, null>', $datePeriod);
assertType(\DateTimeInterface::class, $datePeriod->getEndDate());
assertType('null', $datePeriod->getRecurrences());
$datePeriodList[] = $datePeriod;

$datePeriod = new DatePeriod($start, $interval, $recurrences);
assertType(\DatePeriod::class, $datePeriod);
assertType(\DatePeriod::class . '<null, int>', $datePeriod);
assertType('null', $datePeriod->getEndDate());
assertType('int', $datePeriod->getRecurrences());
$datePeriodList[] = $datePeriod;

$datePeriod = new DatePeriod($iso);
assertType(\DatePeriod::class, $datePeriod);
assertType(\DatePeriod::class . '<null, int>', $datePeriod);
assertType('null', $datePeriod->getEndDate());
assertType('int', $datePeriod->getRecurrences());
$datePeriodList[] = $datePeriod;
Expand Down

0 comments on commit 133991a

Please sign in to comment.