Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions stubs/date.stub
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,19 @@ class DatePeriod implements \IteratorAggregate, \Traversable

}
}

interface DateTimeInterface {
/** @return \DateInterval&object{days:int} */
function diff(\DateTimeInterface $targetObject, bool $absolute = false): \DateInterval
{}
}

class DateTimeImmutable implements DateTimeInterface {
}

class DateTime implements DateTimeInterface {
}

/** @return \DateInterval&object{days:int} */
function date_diff(\DateTimeInterface $baseObject, \DateTimeInterface $targetObject, bool $absolute = false): \DateInterval
{}
31 changes: 31 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-14428.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Bug14428;

use DateInterval;
use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use function PHPStan\Testing\assertType;

function doImpure(DateInterval &$a): void {
}

function getDateTimeInterfacediff(DateTimeInterface $a, DateTimeInterface $b): void {
$interval = $a->diff($b);
assertType('int', $interval->days);
doImpure($interval);
assertType('int|false', $interval->days);
}

function getDateTimeImmutablediff(DateTimeImmutable $a, DateTimeImmutable $b): int {
return $a->diff($b)->days;
}

function getDatetimediff(DateTime $a, DateTime $b): int {
return $a->diff($b)->days;
}

function getDateDiffDays(DateTime $a, DateTime $b): int {
return date_diff($a, $b)->days;
}
7 changes: 7 additions & 0 deletions tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,11 @@ public function testBug13000(): void
$this->analyse([__DIR__ . '/data/bug-13000.php'], []);
}

public function testBug14428(): void
{
$this->checkNullables = true;
$this->checkExplicitMixed = false;
$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-14428.php'], []);
}

}
Loading