From 9bd4d7a74054580b0237cb81fa2315d548e83111 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 13 Oct 2022 18:49:48 +0530 Subject: [PATCH] Fix template param for SplDoublyLinkedList. It's key is always an integer. --- docs/annotating_code/templated_annotations.md | 4 ++-- stubs/SPL.phpstub | 21 +++++++++---------- tests/Template/ClassTemplateTest.php | 6 +++--- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/docs/annotating_code/templated_annotations.md b/docs/annotating_code/templated_annotations.md index fac681b3bad..471f6f3fa00 100644 --- a/docs/annotating_code/templated_annotations.md +++ b/docs/annotating_code/templated_annotations.md @@ -448,5 +448,5 @@ Psalm has support for a number of builtin classes and interfaces that you can ex - `class ArrayObject implements IteratorAggregate, ArrayAccess` - `class ArrayIterator implements SeekableIterator, ArrayAccess` - `class DOMNodeList implements Traversable` -- `class SplDoublyLinkedList implements Iterator, ArrayAccess` -- `class SplQueue extends SplDoublyLinkedList` +- `class SplDoublyLinkedList implements Iterator, ArrayAccess` +- `class SplQueue extends SplDoublyLinkedList` diff --git a/stubs/SPL.phpstub b/stubs/SPL.phpstub index 90c06d943e1..288ceba770a 100644 --- a/stubs/SPL.phpstub +++ b/stubs/SPL.phpstub @@ -4,10 +4,9 @@ * The SplDoublyLinkedList class provides the main functionalities of a doubly linked list. * @link https://php.net/manual/en/class.spldoublylinkedlist.php * - * @template TKey * @template TValue - * @template-implements Iterator - * @template-implements ArrayAccess + * @template-implements Iterator + * @template-implements ArrayAccess */ class SplDoublyLinkedList implements Iterator, Countable, ArrayAccess, Serializable { @@ -16,7 +15,7 @@ class SplDoublyLinkedList implements Iterator, Countable, ArrayAccess, Serializa /** * Add/insert a new value at the specified index * - * @param TKey $index The index where the new value is to be inserted. + * @param int $index The index where the new value is to be inserted. * @param TValue $newval The new value for the index. * @return void * @@ -111,7 +110,7 @@ class SplDoublyLinkedList implements Iterator, Countable, ArrayAccess, Serializa * Returns whether the requested $index exists * @link https://php.net/manual/en/spldoublylinkedlist.offsetexists.php * - * @param TKey $index The index being checked. + * @param int $index The index being checked. * @return bool true if the requested index exists, otherwise false * * @since 5.3.0 @@ -122,7 +121,7 @@ class SplDoublyLinkedList implements Iterator, Countable, ArrayAccess, Serializa * Returns the value at the specified $index * @link https://php.net/manual/en/spldoublylinkedlist.offsetget.php * - * @param TKey $index The index with the value. + * @param int $index The index with the value. * @return TValue The value at the specified index. * * @since 5.3.0 @@ -133,7 +132,7 @@ class SplDoublyLinkedList implements Iterator, Countable, ArrayAccess, Serializa * Sets the value at the specified $index to $newval * @link https://php.net/manual/en/spldoublylinkedlist.offsetset.php * - * @param TKey $index The index being set. + * @param int $index The index being set. * @param TValue $newval The new value for the index. * @return void * @@ -145,7 +144,7 @@ class SplDoublyLinkedList implements Iterator, Countable, ArrayAccess, Serializa * Unsets the value at the specified $index * @link https://php.net/manual/en/spldoublylinkedlist.offsetunset.php * - * @param TKey $index The index being unset. + * @param int $index The index being unset. * @return void * * @since 5.3.0 @@ -166,7 +165,7 @@ class SplDoublyLinkedList implements Iterator, Countable, ArrayAccess, Serializa * Return current node index * @link https://php.net/manual/en/spldoublylinkedlist.key.php * - * @return TKey The current node index. + * @return int The current node index. * * @since 5.3.0 */ @@ -346,7 +345,7 @@ class SplFixedArray implements Iterator, ArrayAccess, Countable { * @link https://php.net/manual/en/class.splstack.php * * @template TValue - * @template-extends SplDoublyLinkedList + * @template-extends SplDoublyLinkedList */ class SplStack extends SplDoublyLinkedList { } @@ -356,7 +355,7 @@ class SplStack extends SplDoublyLinkedList { * @link https://php.net/manual/en/class.splqueue.php * * @template TValue - * @template-extends SplDoublyLinkedList + * @template-extends SplDoublyLinkedList */ class SplQueue extends SplDoublyLinkedList { /** diff --git a/tests/Template/ClassTemplateTest.php b/tests/Template/ClassTemplateTest.php index 6dc1a02a118..896cd11f971 100644 --- a/tests/Template/ClassTemplateTest.php +++ b/tests/Template/ClassTemplateTest.php @@ -1039,9 +1039,9 @@ public function partition() {} 'code' => 'add(5, "hello"); - $list->add("hello", 5); + $list->add(5, 1); - /** @var SplDoublyLinkedList */ + /** @var SplDoublyLinkedList */ $templated_list = new SplDoublyLinkedList(); $templated_list->add(5, "hello"); $a = $templated_list->bottom();', @@ -3937,7 +3937,7 @@ function violate($p) {}', ], 'doublyLinkedListBadParam' => [ 'code' => ' */ + /** @var SplDoublyLinkedList */ $templated_list = new SplDoublyLinkedList(); $templated_list->add(5, []);', 'error_message' => 'InvalidArgument',