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 invalid call to SerializableLimitIterator's constructor #56

Open
wants to merge 2 commits into
base: 2.18.x
Choose a base branch
from

Conversation

arhimede
Copy link
Member

Q A
Documentation no
Bugfix no
BC Break no
New Feature no
RFC no
QA yes

Description

This pull request fixes an error identified by Psalm during the validation of src/SerializableLimitIterator.php:

Error: src/SerializableLimitIterator.php:82:9: DirectConstructorCall: Constructors should not be called directly (see https://psalm.dev/318)

The error is caused by a direct call to SerializableLimitIterator's constructor from its __unserialize method.

Comment on lines 82 to 84
$this->__construct($data['it'], $data['offset'], $data['count']);
$this->seek($data['pos'] + $data['offset']);
$this->offset = (int) $data['offset'];
$this->count = (int) $data['count'];
parent::__construct($data['it'], $this->offset, $this->count);
Copy link
Member

Choose a reason for hiding this comment

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

Any way we can test how it was broken before? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Calling a constructor directly from another method is valid PHP code (though not the best practice) so it's not about testing how it was broken.
It's only Psalm that reports errors here and here

Copy link
Member

Choose a reason for hiding this comment

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

Besides the constructor and Psalm: the call of seek has been removed without any effect, which indicates that tests are missing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, missing seek issue is fixed now

@arhimede arhimede requested a review from Ocramius March 29, 2023 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants