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 0bab166 commit f0ad821
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
23 changes: 15 additions & 8 deletions src/Type/Php/DatePeriodConstructorReturnTypeExtension.php
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);
}

}
8 changes: 4 additions & 4 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Expand Up @@ -623,16 +623,16 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5698-php7.php');
}

if (PHP_VERSION_ID < 70304) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/date-period-return-types.php');
}

yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6404.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-6399.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-4357.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-5817.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/array-column.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/template-null-bound.php');

if (PHP_VERSION_ID >= 70304) {
yield from $this->gatherAssertTypes(__DIR__ . '/data/date-period-return-types.php');
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/PHPStan/Analyser/data/date-period-return-types.php
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 f0ad821

Please sign in to comment.