1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #825 - ignore falsable issues on builtin *methods*

This commit is contained in:
Matt Brown 2018-06-18 10:07:05 -04:00
parent d4107f9e5e
commit 75e2be8aec
3 changed files with 14 additions and 2 deletions

View File

@ -1620,7 +1620,7 @@ return [
'DateTime::add' => ['static', 'interval'=>'DateInterval'],
'DateTime::createFromFormat' => ['static|false', 'format'=>'string', 'time'=>'string', 'timezone='=>'DateTimeZone'],
'DateTime::diff' => ['DateInterval', 'datetime2'=>'DateTimeInterface', 'absolute='=>'bool'],
'DateTime::format' => ['string', 'format'=>'string'],
'DateTime::format' => ['string|false', 'format'=>'string'],
'DateTime::getLastErrors' => ['array'],
'DateTime::getOffset' => ['int'],
'DateTime::getTimestamp' => ['int'],
@ -1639,7 +1639,7 @@ return [
'DateTimeImmutable::createFromFormat' => ['static', 'format'=>'string', 'time'=>'string', 'timezone='=>'DateTimeZone'],
'DateTimeImmutable::createFromMutable' => ['static', 'datetime'=>'DateTime'],
'DateTimeImmutable::diff' => ['DateInterval', 'datetime2'=>'DateTimeInterface', 'absolute='=>'bool'],
'DateTimeImmutable::format' => ['string', 'format'=>'string'],
'DateTimeImmutable::format' => ['string|false', 'format'=>'string'],
'DateTimeImmutable::getLastErrors' => ['array'],
'DateTimeImmutable::getOffset' => ['int'],
'DateTimeImmutable::getTimestamp' => ['int'],

View File

@ -522,6 +522,9 @@ class MethodCallChecker extends \Psalm\Checker\Statements\Expression\CallChecker
$return_type_candidate = Type::parseString('string|false');
} else {
$return_type_candidate = CallMap::getReturnTypeFromCallMap($call_map_id);
if ($return_type_candidate->isFalsable()) {
$return_type_candidate->ignore_falsable_issues = true;
}
}
}

View File

@ -146,6 +146,15 @@ class MethodCallTest extends TestCase
'$b' => 'string|bool',
],
],
'datetimeformatNotFalse' => [
'<?php
$format = random_bytes(10);
$dt = new DateTime;
$formatted = $dt->format($format);
if (false !== $formatted) {}
function takesString(string $s) : void {}
takesString($formatted);'
],
];
}