diff --git a/UPGRADING.md b/UPGRADING.md index ad63118b236..9f2ad3f0dd1 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -42,7 +42,7 @@ - `Psalm\Type\Atomic\TIntRange` - `Psalm\Type\Atomic\TIterable` - `Psalm\Type\Atomic\TKeyedArray` - - `Psalm\Type\Atomic\TKeyOfArray` + - `Psalm\Type\Atomic\TKeyOf` - `Psalm\Type\Atomic\TList` - `Psalm\Type\Atomic\TLiteralClassString` - `Psalm\Type\Atomic\TLowercaseString` @@ -92,7 +92,7 @@ - `Psalm\Type\Atomic\TInt` - `Psalm\Type\Atomic\TIterable` - `Psalm\Type\Atomic\TKeyedArray` - - `Psalm\Type\Atomic\TKeyOfArray` + - `Psalm\Type\Atomic\TKeyOf` - `Psalm\Type\Atomic\TList` - `Psalm\Type\Atomic\TLiteralClassString` - `Psalm\Type\Atomic\TMixed` @@ -155,7 +155,7 @@ - [BC] Atomic::getId() has now a first param $exact. Calling the method with false will return a less detailed version of the type in some cases (similarly to what `__toString` used to return) - [BC] To remove a variable from the context, use `Context::remove()`. Calling `unset($context->vars_in_scope[$var_id])` can cause problems when using references. -- [BC] `TKeyOfClassConstant` has been renamed to `TKeyOfArray`. +- [BC] `TKeyOfClassConstant` has been renamed to `TKeyOf`. - [BC] `TValueOfClassConstant` has been renamed to `TValueOf`. - [BC] `TKeyOfTemplate` base class has been changed from `Scalar` to `Atomic`. - [BC] Class `Psalm\FileManipulation` became final @@ -748,7 +748,7 @@ - [BC] Class `Psalm\Type\Atomic\TEnumCase` became final - [BC] Class `Psalm\Type\Atomic\TCallableKeyedArray` became final - [BC] Class `Psalm\Type\Atomic\TDependentGetDebugType` became final - - [BC] Class `Psalm\Type\Atomic\TKeyOfArray` became final + - [BC] Class `Psalm\Type\Atomic\TKeyOf` became final - [BC] Class `Psalm\Type\Atomic\TNonspecificLiteralInt` became final - [BC] Class `Psalm\Type\Atomic\TObjectWithProperties` became final - [BC] Class `Psalm\Type\Atomic\TTemplateValueOf` became final diff --git a/docs/running_psalm/plugins/plugins_type_system.md b/docs/running_psalm/plugins/plugins_type_system.md index ff185ee198e..fcddb74e004 100644 --- a/docs/running_psalm/plugins/plugins_type_system.md +++ b/docs/running_psalm/plugins/plugins_type_system.md @@ -49,13 +49,13 @@ The classes are as follows: `TIntMaskOf` - as above, but used with a reference to constants in code `int-mask-of` will corresponds to `1|2|3|4|5|6|7` if there are three constant 1, 2 and 4 -`TKeyOfArray` - Represents an offset of an array (e.g. `key-of`). +`TKeyOf` - Represents an offset of an array (e.g. `key-of`). `TValueOf` - Represents a value of an array or enum (e.g. `value-of`). `TTemplateIndexedAccess` - To be documented -`TTemplateKeyOf` - Represents the type used when using TKeyOfArray when the type of the array is a template +`TTemplateKeyOf` - Represents the type used when using TKeyOf when the type of the array is a template `TTemplateValueOf` - Represents the type used when using TValueOf when the type of the array or enum is a template diff --git a/src/Psalm/Internal/Type/Comparator/AtomicTypeComparator.php b/src/Psalm/Internal/Type/Comparator/AtomicTypeComparator.php index d009b9fd5d8..28064420305 100644 --- a/src/Psalm/Internal/Type/Comparator/AtomicTypeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/AtomicTypeComparator.php @@ -19,7 +19,7 @@ use Psalm\Type\Atomic\TEnumCase; use Psalm\Type\Atomic\TGenericObject; use Psalm\Type\Atomic\TIterable; -use Psalm\Type\Atomic\TKeyOfArray; +use Psalm\Type\Atomic\TKeyOf; use Psalm\Type\Atomic\TKeyedArray; use Psalm\Type\Atomic\TList; use Psalm\Type\Atomic\TLiteralString; @@ -341,7 +341,7 @@ public static function isContainedBy( } if ($input_type_part instanceof TTemplateKeyOf) { - $array_key_type = TKeyOfArray::getArrayKeyType($input_type_part->as); + $array_key_type = TKeyOf::getArrayKeyType($input_type_part->as); if ($array_key_type === null) { return false; } diff --git a/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php b/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php index 4a855429faf..6d4d753157b 100644 --- a/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php +++ b/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php @@ -11,7 +11,7 @@ use Psalm\Type\Atomic\TConditional; use Psalm\Type\Atomic\TInt; use Psalm\Type\Atomic\TIterable; -use Psalm\Type\Atomic\TKeyOfArray; +use Psalm\Type\Atomic\TKeyOf; use Psalm\Type\Atomic\TKeyedArray; use Psalm\Type\Atomic\TLiteralInt; use Psalm\Type\Atomic\TLiteralString; @@ -345,9 +345,9 @@ private static function replaceTemplateKeyOfValueOf( ); if ($atomic_type instanceof TTemplateKeyOf - && TKeyOfArray::isViableTemplateType($template_type) + && TKeyOf::isViableTemplateType($template_type) ) { - return new TKeyOfArray(clone $template_type); + return new TKeyOf(clone $template_type); } if ($atomic_type instanceof TTemplateValueOf diff --git a/src/Psalm/Internal/Type/TypeExpander.php b/src/Psalm/Internal/Type/TypeExpander.php index c849fc1ff2f..9fb1230a07b 100644 --- a/src/Psalm/Internal/Type/TypeExpander.php +++ b/src/Psalm/Internal/Type/TypeExpander.php @@ -22,7 +22,7 @@ use Psalm\Type\Atomic\TIntMask; use Psalm\Type\Atomic\TIntMaskOf; use Psalm\Type\Atomic\TIterable; -use Psalm\Type\Atomic\TKeyOfArray; +use Psalm\Type\Atomic\TKeyOf; use Psalm\Type\Atomic\TKeyedArray; use Psalm\Type\Atomic\TList; use Psalm\Type\Atomic\TLiteralClassString; @@ -363,7 +363,7 @@ public static function expandAtomic( return [$return_type]; } - if ($return_type instanceof TKeyOfArray + if ($return_type instanceof TKeyOf || $return_type instanceof TValueOf ) { return self::expandKeyOfValueOf( @@ -965,7 +965,7 @@ function (?Union $property_type): bool { } /** - * @param TKeyOfArray|TValueOf $return_type + * @param TKeyOf|TValueOf $return_type * @param string|TNamedObject|TTemplateParam|null $static_class_type * @return non-empty-list */ @@ -1025,8 +1025,8 @@ private static function expandKeyOfValueOf( if (!$constant_type || ( - $return_type instanceof TKeyOfArray - && !TKeyOfArray::isViableTemplateType($constant_type) + $return_type instanceof TKeyOf + && !TKeyOf::isViableTemplateType($constant_type) ) || ( $return_type instanceof TValueOf @@ -1049,8 +1049,8 @@ private static function expandKeyOfValueOf( return [$return_type]; } - if ($return_type instanceof TKeyOfArray) { - $new_return_types = TKeyOfArray::getArrayKeyType(new Union($type_atomics)); + if ($return_type instanceof TKeyOf) { + $new_return_types = TKeyOf::getArrayKeyType(new Union($type_atomics)); } else { $new_return_types = TValueOf::getValueType(new Union($type_atomics), $codebase); } diff --git a/src/Psalm/Internal/Type/TypeParser.php b/src/Psalm/Internal/Type/TypeParser.php index 00b61b9c31a..614be8b3c5c 100644 --- a/src/Psalm/Internal/Type/TypeParser.php +++ b/src/Psalm/Internal/Type/TypeParser.php @@ -41,7 +41,7 @@ use Psalm\Type\Atomic\TIntMaskOf; use Psalm\Type\Atomic\TIntRange; use Psalm\Type\Atomic\TIterable; -use Psalm\Type\Atomic\TKeyOfArray; +use Psalm\Type\Atomic\TKeyOf; use Psalm\Type\Atomic\TKeyedArray; use Psalm\Type\Atomic\TList; use Psalm\Type\Atomic\TLiteralClassString; @@ -743,13 +743,13 @@ private static function getTypeFromGenericTree( ); } - if (!TKeyOfArray::isViableTemplateType($generic_params[0])) { + if (!TKeyOf::isViableTemplateType($generic_params[0])) { throw new TypeParseTreeException( 'Untemplated key-of param ' . $param_name . ' should be an array' ); } - return new TKeyOfArray($generic_params[0]); + return new TKeyOf($generic_params[0]); } if ($generic_type_value === 'value-of') { @@ -843,7 +843,7 @@ private static function getTypeFromGenericTree( if (!$param_type instanceof TClassConstant && !$param_type instanceof TValueOf - && !$param_type instanceof TKeyOfArray + && !$param_type instanceof TKeyOf ) { throw new TypeParseTreeException( 'Invalid reference passed to int-mask-of' diff --git a/src/Psalm/Type/Atomic/TIntMaskOf.php b/src/Psalm/Type/Atomic/TIntMaskOf.php index c7c2ca058ad..3e210e409e8 100644 --- a/src/Psalm/Type/Atomic/TIntMaskOf.php +++ b/src/Psalm/Type/Atomic/TIntMaskOf.php @@ -11,11 +11,11 @@ */ final class TIntMaskOf extends TInt { - /** @var TClassConstant|TKeyOfArray|TValueOf */ + /** @var TClassConstant|TKeyOf|TValueOf */ public $value; /** - * @param TClassConstant|TKeyOfArray|TValueOf $value + * @param TClassConstant|TKeyOf|TValueOf $value */ public function __construct(Atomic $value) { diff --git a/src/Psalm/Type/Atomic/TKeyOfArray.php b/src/Psalm/Type/Atomic/TKeyOf.php similarity index 98% rename from src/Psalm/Type/Atomic/TKeyOfArray.php rename to src/Psalm/Type/Atomic/TKeyOf.php index 632a28524c1..027a0e04fb5 100644 --- a/src/Psalm/Type/Atomic/TKeyOfArray.php +++ b/src/Psalm/Type/Atomic/TKeyOf.php @@ -11,7 +11,7 @@ /** * Represents an offset of an array. */ -final class TKeyOfArray extends TArrayKey +final class TKeyOf extends TArrayKey { /** @var Union */ public $type; diff --git a/src/Psalm/Type/Atomic/TTemplateKeyOf.php b/src/Psalm/Type/Atomic/TTemplateKeyOf.php index 9a679df4164..bb2f5f947e0 100644 --- a/src/Psalm/Type/Atomic/TTemplateKeyOf.php +++ b/src/Psalm/Type/Atomic/TTemplateKeyOf.php @@ -9,7 +9,7 @@ use Psalm\Type\Union; /** - * Represents the type used when using TKeyOfArray when the type of the array is a template + * Represents the type used when using TKeyOf when the type of the array is a template */ final class TTemplateKeyOf extends Atomic {