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