Skip to content

Commit

Permalink
better handling of having wrong argumenttypes provided
Browse files Browse the repository at this point in the history
  • Loading branch information
verfriemelt-dot-org committed Dec 15, 2022
1 parent ba37e65 commit 31606d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Type/Php/DateIntervalDynamicReturnTypeExtension.php
Expand Up @@ -12,6 +12,7 @@
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use function array_map;
use function count;
use function gettype;
use function in_array;

Expand Down Expand Up @@ -44,6 +45,11 @@ public function getTypeFromStaticMethodCall(MethodReflection $methodReflection,
$strings,
);

// the error case, when wrong types are passed
if (count($possibleReturnTypes) === 0) {
return null;
}

if (in_array('boolean', $possibleReturnTypes, true) && in_array('object', $possibleReturnTypes, true)) {
return null;
}
Expand Down
4 changes: 3 additions & 1 deletion tests/PHPStan/Analyser/data/bug-8442.php
Expand Up @@ -2,6 +2,7 @@

namespace Bug8442;

use stdClass;
use function PHPStan\Testing\assertType;
use DateInterval;

Expand Down Expand Up @@ -33,6 +34,7 @@ function () {

assertType('false', DateInterval::createFromDateString($interval));

DateInterval::createFromDateString();
assertType('DateInterval|false',DateInterval::createFromDateString());
assertType('DateInterval|false',DateInterval::createFromDateString(new stdClass()));
};

0 comments on commit 31606d6

Please sign in to comment.