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: 8 additions & 8 deletions src/Type/Php/DatePeriodConstructorReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ public function isStaticMethodSupported(MethodReflection $methodReflection): boo
return $methodReflection->getName() === '__construct';
}

public function getTypeFromStaticMethodCall(MethodReflection $methodReflection, StaticCall $methodCall, Scope $scope): Type
public function getTypeFromStaticMethodCall(MethodReflection $methodReflection, StaticCall $methodCall, Scope $scope): ?Type
{
if (!isset($methodCall->getArgs()[0])) {
return new ObjectType(DatePeriod::class);
}

if (!$methodCall->class instanceof Name) {
return new ObjectType(DatePeriod::class);
return null;
}

$className = $scope->resolveName($methodCall->class);
if (strtolower($className) !== 'dateperiod') {
return new ObjectType($className);
return null;
}

if (!isset($methodCall->getArgs()[0])) {
return null;
}

$firstArgType = $scope->getType($methodCall->getArgs()[0]->value);
Expand Down Expand Up @@ -80,7 +80,7 @@ public function getTypeFromStaticMethodCall(MethodReflection $methodReflection,
]);
}

return new ObjectType(DatePeriod::class);
return null;
}

}
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Functions/ReturnTypeRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,14 @@ public function testBug12274(): void
]);
}

public function testBug13484(): void
{
$this->checkExplicitMixed = true;
$this->checkNullables = true;

$this->analyse([__DIR__ . '/data/bug-13484.php'], []);
}

public function testBug9401(): void
{
$this->checkExplicitMixed = true;
Expand Down
15 changes: 15 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-13484.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types = 1);

namespace Bug13484;

class MyPeriod extends \DatePeriod {
protected array $arguments;
public function __construct(...$arguments) {
$this->arguments = $arguments;
}
}

function test(): MyPeriod
{
return new MyPeriod();
}
Loading