1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 13:51:54 +01:00

should be non-falsy-string instead of non-empty-string in most cases

This commit is contained in:
kkmuffme 2023-12-20 09:11:59 +01:00
parent a2bf5cb054
commit 4092618260
2 changed files with 11 additions and 2 deletions

View File

@ -277,7 +277,7 @@ abstract class Type
return new Union([$value === null ? new TString() : self::getAtomicStringFromLiteral($value)]);
}
/** @return TLiteralString|TNonEmptyString */
/** @return TLiteralString|TNonEmptyString|TNonFalsyString */
public static function getAtomicStringFromLiteral(string $value, bool $from_docblock = false): TString
{
$config = Config::getInstance();
@ -289,8 +289,10 @@ abstract class Type
if (!$type) {
if ($value === '' || strlen($value) < $config->max_string_length) {
$type = new TLiteralString($value, $from_docblock);
} else {
} elseif ($value === '0') {
$type = new TNonEmptyString($from_docblock);
} else {
$type = new TNonFalsyString($from_docblock);
}
}

View File

@ -120,6 +120,13 @@ class TypeCombinationTest extends TestCase
takesLiteralString($c);
}',
],
'tooLongLiteralShouldBeNonFalsyString' => [
'code' => '<?php
$x = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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