mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
add scalar & numeric handling for all cases where appropriate and ensure no more generic types being added for int/float (previous commit)
This commit is contained in:
parent
551625aa4b
commit
7023855fb3
@ -33,6 +33,7 @@ use Psalm\Type\Atomic\TNonFalsyString;
|
||||
use Psalm\Type\Atomic\TNull;
|
||||
use Psalm\Type\Atomic\TNumeric;
|
||||
use Psalm\Type\Atomic\TNumericString;
|
||||
use Psalm\Type\Atomic\TScalar;
|
||||
use Psalm\Type\Atomic\TString;
|
||||
use Psalm\Type\Atomic\TTrue;
|
||||
use Psalm\Type\Union;
|
||||
@ -42,6 +43,7 @@ use function array_diff;
|
||||
use function array_keys;
|
||||
use function array_merge;
|
||||
use function filter_var;
|
||||
use function get_class;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
use function preg_match;
|
||||
@ -919,7 +921,11 @@ final class FilterUtils
|
||||
$filter_types[] = new TFloat();
|
||||
}
|
||||
|
||||
if ($atomic_type instanceof TMixed || $atomic_type instanceof TNumeric) {
|
||||
// only these specific classes, not any class that extends either
|
||||
// to avoid matching already better handled cases from above, e.g. float is numeric and scalar
|
||||
if ($atomic_type instanceof TMixed
|
||||
|| get_class($atomic_type) === TNumeric::class
|
||||
|| get_class($atomic_type) === TScalar::class) {
|
||||
$filter_types[] = new TFloat();
|
||||
}
|
||||
|
||||
@ -967,7 +973,9 @@ final class FilterUtils
|
||||
if ($atomic_type instanceof TMixed
|
||||
|| $atomic_type instanceof TString
|
||||
|| $atomic_type instanceof TInt
|
||||
|| $atomic_type instanceof TFloat) {
|
||||
|| $atomic_type instanceof TFloat
|
||||
|| $atomic_type instanceof TNumeric
|
||||
|| $atomic_type instanceof TScalar) {
|
||||
$filter_types[] = new TBool();
|
||||
}
|
||||
|
||||
@ -1109,7 +1117,9 @@ final class FilterUtils
|
||||
$filter_types[] = $int_type;
|
||||
}
|
||||
|
||||
if ($atomic_type instanceof TMixed || $atomic_type instanceof TNumeric) {
|
||||
if ($atomic_type instanceof TMixed
|
||||
|| get_class($atomic_type) === TNumeric::class
|
||||
|| get_class($atomic_type) === TScalar::class) {
|
||||
$filter_types[] = $int_type;
|
||||
}
|
||||
|
||||
@ -1130,9 +1140,7 @@ final class FilterUtils
|
||||
$filter_types[] = $atomic_type;
|
||||
} elseif ($atomic_type instanceof TString) {
|
||||
$filter_types[] = new TNonFalsyString();
|
||||
}
|
||||
|
||||
if ($atomic_type instanceof TMixed) {
|
||||
} elseif ($atomic_type instanceof TMixed || $atomic_type instanceof TScalar) {
|
||||
$filter_types[] = new TNonFalsyString();
|
||||
}
|
||||
|
||||
@ -1160,6 +1168,7 @@ final class FilterUtils
|
||||
|| $atomic_type instanceof TInt
|
||||
|| $atomic_type instanceof TFloat
|
||||
|| $atomic_type instanceof TNumeric
|
||||
|| $atomic_type instanceof TScalar
|
||||
|| $atomic_type instanceof TMixed) {
|
||||
$filter_types[] = new TString();
|
||||
}
|
||||
@ -1184,11 +1193,10 @@ final class FilterUtils
|
||||
} else {
|
||||
$filter_types[] = $atomic_type;
|
||||
}
|
||||
}
|
||||
|
||||
if ($atomic_type instanceof TMixed
|
||||
} elseif ($atomic_type instanceof TMixed
|
||||
|| $atomic_type instanceof TInt
|
||||
|| $atomic_type instanceof TFloat) {
|
||||
|| $atomic_type instanceof TFloat
|
||||
|| $atomic_type instanceof TScalar) {
|
||||
$filter_types[] = $string_type;
|
||||
}
|
||||
|
||||
@ -1231,7 +1239,7 @@ final class FilterUtils
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($atomic_type instanceof TMixed) {
|
||||
if ($atomic_type instanceof TMixed || $atomic_type instanceof TScalar) {
|
||||
$filter_types[] = new TString();
|
||||
}
|
||||
|
||||
@ -1311,7 +1319,7 @@ final class FilterUtils
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($atomic_type instanceof TMixed) {
|
||||
if ($atomic_type instanceof TMixed || $atomic_type instanceof TScalar) {
|
||||
$filter_types[] = new TString();
|
||||
}
|
||||
|
||||
@ -1330,7 +1338,7 @@ final class FilterUtils
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($atomic_type instanceof TMixed) {
|
||||
if ($atomic_type instanceof TMixed || $atomic_type instanceof TScalar) {
|
||||
$filter_types[] = new TString();
|
||||
}
|
||||
|
||||
@ -1387,7 +1395,7 @@ final class FilterUtils
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($atomic_type instanceof TMixed) {
|
||||
if ($atomic_type instanceof TMixed || $atomic_type instanceof TScalar) {
|
||||
$filter_types[] = new TNumericString();
|
||||
$filter_types[] = Type::getAtomicStringFromLiteral('');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user