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
7 changes: 6 additions & 1 deletion src/Reflection/Php/PhpClassReflectionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,8 @@ private function findMethodPhpDocIncludingAncestors(
if ($resolved !== null) {
return [$resolved, $declaringClass];
}
if (!$this->stubPhpDocProvider->isKnownClass($declaringClassName)) {
$isKnownClass = $this->stubPhpDocProvider->isKnownClass($declaringClassName);
if (!$isKnownClass && !$declaringClass->isBuiltin()) {
return null;
}

Expand All @@ -1335,6 +1336,10 @@ private function findMethodPhpDocIncludingAncestors(
continue;
}

if (!$isKnownClass && $ancestor->isGeneric()) {
continue;
}

return [$resolved, $ancestor];
}

Expand Down
6 changes: 0 additions & 6 deletions stubs/date.stub
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ interface DateTimeInterface {
{}
}

class DateTimeImmutable implements DateTimeInterface {
}

class DateTime implements DateTimeInterface {
}

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

namespace Bug14632;

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

function testDateTimeInterface(DateTimeInterface $a, DateTimeInterface $b): void {
$interval = $a->diff($b);
assertType('DateInterval&object{days: int}', $interval);
assertType('int', $interval->days);
}

function testDateTimeImmutable(DateTimeImmutable $a, DateTimeImmutable $b): void {
$interval = $a->diff($b);
assertType('DateInterval&object{days: int}', $interval);
assertType('int', $interval->days);
}

function testDateTime(DateTime $a, DateTime $b): void {
$interval = $a->diff($b);
assertType('DateInterval&object{days: int}', $interval);
assertType('int', $interval->days);
}
28 changes: 28 additions & 0 deletions tests/PHPStan/Analyser/nsrt/builtin-generic-ancestor-stubs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php // lint >= 8.4

namespace BuiltinGenericAncestorStubs;

use Dom\NodeList;
use MultipleIterator;
use SplFileObject;
use WeakMap;
use function PHPStan\Testing\assertType;

function testSplFileObject(SplFileObject $file): void {
assertType('int', $file->key());
assertType('array|string|false', $file->current());
}

function testMultipleIterator(MultipleIterator $it): void {
assertType('array', $it->key());
assertType('array', $it->current());
}

/** @param WeakMap<object, string> $map */
function testWeakMap(WeakMap $map): void {
assertType('int<0, max>', $map->count());
}

function testDomNodeList(NodeList $list): void {
assertType('int<0, max>', $list->count());
}
Loading