1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Rename class and make it type-hintable

This commit is contained in:
Matt Brown 2021-06-14 16:02:59 -04:00
parent 5ae8b2a23f
commit 4941b9e5d2
7 changed files with 31 additions and 18 deletions

View File

@ -173,7 +173,7 @@ class ConcatAnalyzer
if ($literal_concat) {
$result_type = new Type\Union($result_type_parts);
} else {
$result_type = new Type\Union([new Type\Atomic\TNonspecificNonEmptyLiteralString]);
$result_type = new Type\Union([new Type\Atomic\TNonEmptyNonspecificLiteralString]);
}
return;
@ -238,7 +238,7 @@ class ConcatAnalyzer
if ($left_is_non_empty || $right_is_non_empty) {
if ($left_type->allLiterals() && $right_type->allLiterals()) {
$result_type = new Type\Union([new Type\Atomic\TNonspecificNonEmptyLiteralString]);
$result_type = new Type\Union([new Type\Atomic\TNonEmptyNonspecificLiteralString]);
} else {
$result_type = Type::getNonEmptyString();
}

View File

@ -81,7 +81,7 @@ class EncapsulatedStringAnalyzer
if ($non_empty) {
if ($all_literals) {
$new_type = new Type\Union([new Type\Atomic\TNonspecificNonEmptyLiteralString()]);
$new_type = new Type\Union([new Type\Atomic\TNonEmptyNonspecificLiteralString()]);
} else {
$new_type = new Type\Union([new Type\Atomic\TNonEmptyString()]);
}

View File

@ -25,10 +25,10 @@ use Psalm\Type\Atomic\TLiteralInt;
use Psalm\Type\Atomic\TLiteralString;
use Psalm\Type\Atomic\TLowercaseString;
use Psalm\Type\Atomic\TNamedObject;
use Psalm\Type\Atomic\TNonEmptyNonspecificLiteralString;
use Psalm\Type\Atomic\TNonEmptyString;
use Psalm\Type\Atomic\TNonFalsyString;
use Psalm\Type\Atomic\TNonspecificLiteralString;
use Psalm\Type\Atomic\TNonspecificNonEmptyLiteralString;
use Psalm\Type\Atomic\TNumeric;
use Psalm\Type\Atomic\TNumericString;
use Psalm\Type\Atomic\TPositiveInt;
@ -88,7 +88,7 @@ class ScalarTypeComparator
if ($container_type_part instanceof TNonspecificLiteralString
&& ($input_type_part instanceof TLiteralString
|| $input_type_part instanceof TNonspecificLiteralString
|| $input_type_part instanceof TNonspecificNonEmptyLiteralString)
|| $input_type_part instanceof TNonEmptyNonspecificLiteralString)
) {
return true;
}
@ -299,7 +299,7 @@ class ScalarTypeComparator
}
if ((get_class($container_type_part) === TNonEmptyString::class
|| get_class($container_type_part) === TNonspecificNonEmptyLiteralString::class)
|| get_class($container_type_part) === TNonEmptyNonspecificLiteralString::class)
&& $input_type_part instanceof TNonFalsyString
) {
return true;
@ -313,7 +313,7 @@ class ScalarTypeComparator
if ($container_type_part instanceof TNonFalsyString
&& ($input_type_part instanceof TNonEmptyString
|| $input_type_part instanceof TNonspecificNonEmptyLiteralString)
|| $input_type_part instanceof TNonEmptyNonspecificLiteralString)
) {
if ($atomic_comparison_result) {
$atomic_comparison_result->type_coerced = true;
@ -437,7 +437,7 @@ class ScalarTypeComparator
if ($container_type_part instanceof TTraitString
&& (get_class($input_type_part) === TString::class
|| $input_type_part instanceof TNonEmptyString
|| $input_type_part instanceof TNonspecificNonEmptyLiteralString)
|| $input_type_part instanceof TNonEmptyNonspecificLiteralString)
) {
if ($atomic_comparison_result) {
$atomic_comparison_result->type_coerced = true;

View File

@ -49,6 +49,7 @@ class TypeTokenizer
'mysql-escaped-string' => true, // deprecated
'html-escaped-string' => true, // deprecated
'literal-string' => true,
'non-empty-literal-string' => true,
'lowercase-string' => true,
'non-empty-lowercase-string' => true,
'positive-int' => true,

View File

@ -263,6 +263,9 @@ abstract class Atomic implements TypeNode
case 'literal-string':
return new Type\Atomic\TNonspecificLiteralString();
case 'non-empty-literal-string':
return new Type\Atomic\TNonEmptyNonspecificLiteralString();
case 'false-y':
return new TAssertionFalsy();

View File

@ -0,0 +1,19 @@
<?php
namespace Psalm\Type\Atomic;
/**
* Denotes the `literal-string` type, where the exact value is unknown but
* we know that the string is not from user input
*/
class TNonEmptyNonspecificLiteralString extends TNonspecificLiteralString
{
public function getKey(bool $include_extra = true): string
{
return 'string';
}
public function getId(bool $nested = false): string
{
return 'non-empty-literal-string';
}
}

View File

@ -1,10 +0,0 @@
<?php
namespace Psalm\Type\Atomic;
/**
* Denotes the `literal-string` type, where the exact value is unknown but
* we know that the string is not from user input
*/
class TNonspecificNonEmptyLiteralString extends TNonspecificLiteralString
{
}