Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ parameters:
- FilterIterator
- RecursiveCallbackFilterIterator
- AppendIterator
- NoRewindIterator
explicitMixedInUnknownGenericNew: false
explicitMixedForGlobalVariables: false
explicitMixedViaIsArray: false
Expand Down
27 changes: 25 additions & 2 deletions stubs/iterable.stub
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ class CallbackFilterIterator extends FilterIterator

}


/**
* @template-covariant TKey
* @template-covariant TValue
Expand Down Expand Up @@ -276,7 +275,6 @@ class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator
public function uksort($cmp_function) { }
}


/**
* @template TKey of array-key
* @template TValue
Expand All @@ -298,3 +296,28 @@ class AppendIterator extends IteratorIterator {
public function getArrayIterator() {}

}

/**
* @template-covariant TKey
* @template-covariant TValue
* @template TIterator as Iterator<TKey, TValue>
*
* @template-extends IteratorIterator<TKey, TValue, TIterator>
*/
class NoRewindIterator extends IteratorIterator {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stub is different from the one in Psalm: https://github.com/vimeo/psalm/blob/36d5a2a83c1d7b3e2aca1cfe9e9dcc916619e962/stubs/CoreGenericIterators.phpstub#L581-L604 (This one uses three template types, Psalm uses two). We need to be cross-compatible here.

Copy link
Contributor

@orklah orklah Jun 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that NoRewindIterator has three templates in the next major of Psalm: https://github.com/vimeo/psalm/blob/master/stubs/CoreGenericIterators.phpstub#L593

(as well as every child of IteratorIterator IIRC)

EDIT: more context here: vimeo/psalm#6970 it originated from a change in phpstan that we duplicated in Psalm but only on our master branch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't realize that. So I'll recheck the stubs against master.

Copy link
Contributor Author

@drupol drupol Jun 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I inspired those PRs from what's in PSalm (@master branch)

/**
* @param TIterator $iterator
*/
public function __construct(Iterator $iterator) {}

/**
* @return TValue
*/
public function current() {}

/**
* @return TKey
*/
public function key() {}
}