Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix template param for SplDoublyLinkedList #8579

Merged
merged 1 commit into from Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/annotating_code/templated_annotations.md
Expand Up @@ -448,5 +448,5 @@ Psalm has support for a number of builtin classes and interfaces that you can ex
- `class ArrayObject<TKey, TValue> implements IteratorAggregate<TKey, TValue>, ArrayAccess<TKey, TValue>`
- `class ArrayIterator<TKey of array-key, TValue> implements SeekableIterator<TKey, TValue>, ArrayAccess<TKey, TValue>`
- `class DOMNodeList<TNode of DOMNode> implements Traversable<int, TNode>`
- `class SplDoublyLinkedList<TKey, TValue> implements Iterator<TKey, TValue>, ArrayAccess<TKey, TValue>`
- `class SplQueue<TValue> extends SplDoublyLinkedList<int, TValue>`
- `class SplDoublyLinkedList<TValue> implements Iterator<TKey, TValue>, ArrayAccess<TKey, TValue>`
- `class SplQueue<TValue> extends SplDoublyLinkedList<TValue>`
21 changes: 10 additions & 11 deletions stubs/SPL.phpstub
Expand Up @@ -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<TKey, TValue>
* @template-implements ArrayAccess<TKey, TValue>
* @template-implements Iterator<int, TValue>
* @template-implements ArrayAccess<int, TValue>
*/
class SplDoublyLinkedList implements Iterator, Countable, ArrayAccess, Serializable
{
Expand All @@ -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
*
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
*
Expand All @@ -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
Expand All @@ -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
*/
Expand Down Expand Up @@ -346,7 +345,7 @@ class SplFixedArray implements Iterator, ArrayAccess, Countable {
* @link https://php.net/manual/en/class.splstack.php
*
* @template TValue
* @template-extends SplDoublyLinkedList<int, TValue>
* @template-extends SplDoublyLinkedList<TValue>
*/
class SplStack extends SplDoublyLinkedList {
}
Expand All @@ -356,7 +355,7 @@ class SplStack extends SplDoublyLinkedList {
* @link https://php.net/manual/en/class.splqueue.php
*
* @template TValue
* @template-extends SplDoublyLinkedList<int, TValue>
* @template-extends SplDoublyLinkedList<TValue>
*/
class SplQueue extends SplDoublyLinkedList {
/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Template/ClassTemplateTest.php
Expand Up @@ -1039,9 +1039,9 @@ public function partition() {}
'code' => '<?php
$list = new SplDoublyLinkedList();
$list->add(5, "hello");
$list->add("hello", 5);
$list->add(5, 1);

/** @var SplDoublyLinkedList<int, string> */
/** @var SplDoublyLinkedList<string> */
$templated_list = new SplDoublyLinkedList();
$templated_list->add(5, "hello");
$a = $templated_list->bottom();',
Expand Down Expand Up @@ -3937,7 +3937,7 @@ function violate($p) {}',
],
'doublyLinkedListBadParam' => [
'code' => '<?php
/** @var SplDoublyLinkedList<int, string> */
/** @var SplDoublyLinkedList<string> */
$templated_list = new SplDoublyLinkedList();
$templated_list->add(5, []);',
'error_message' => 'InvalidArgument',
Expand Down