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

Update CachingIterator::getCache stub. #8282

Merged
merged 4 commits into from Jul 22, 2022
Merged
Changes from 3 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
34 changes: 7 additions & 27 deletions stubs/CoreGenericIterators.phpstub
Expand Up @@ -355,10 +355,10 @@ class CachingIterator extends IteratorIterator implements OuterIterator , ArrayA
const TOSTRING_USE_CURRENT = 4 ;
const TOSTRING_USE_INNER = 8 ;
const FULL_CACHE = 256 ;

/**
* @param TIterator $iterator
* @param int-mask-of<self::*> $flags
* @param int-mask<1,2,4,8,16,256> $flags
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why change this? The previous type should work the same way but is more flexible to future changes, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But then we need to provide a template when creating the CachingIterator, and this is what we want to avoid based on what I read on previous comments, no ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

unless I'm mistaken, int-mask-of<self::*> should not need any template

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know, could you confirm?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, that's what it had before this PR, so if it works on psalm.dev right now it should be fine: https://psalm.dev/r/ecacca8230

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

*/
public function __construct(Iterator $iterator, int $flags = self::CALL_TOSTRING) {}

Expand All @@ -376,6 +376,11 @@ class CachingIterator extends IteratorIterator implements OuterIterator , ArrayA
* @psalm-ignore-nullable-return
*/
public function key() {}

/**
* @return array<array-key, TValue>
AndrolGenhald marked this conversation as resolved.
Show resolved Hide resolved
*/
public function getCache() {}
}

/**
Expand Down Expand Up @@ -799,19 +804,6 @@ class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator
* @template-extends CachingIterator<TKey, TValue, TIterator>
*/
class RecursiveCachingIterator extends CachingIterator implements RecursiveIterator {

const CALL_TOSTRING = 1 ;
const CATCH_GET_CHILD = 16 ;
const TOSTRING_USE_KEY = 2 ;
const TOSTRING_USE_CURRENT = 4 ;
const TOSTRING_USE_INNER = 8 ;
const FULL_CACHE = 256 ;

/**
* @param TIterator $iterator
* @param int-mask-of<self::*> $flags
*/
public function __construct(Iterator $iterator, int $flags = 0) {}
/**
* @return RecursiveCachingIterator<TKey,TValue, TIterator>
*/
Expand All @@ -821,18 +813,6 @@ class RecursiveCachingIterator extends CachingIterator implements RecursiveItera
* @return bool
*/
public function hasChildren() {}

/**
* @return TValue|null current value or null when iterator is drained
* @psalm-ignore-nullable-return
*/
public function current() {}

/**
* @return TKey|null current key or null when iterator is drained
* @psalm-ignore-nullable-return
*/
public function key() {}
}

/**
Expand Down