Skip to content

Fix invalid call to SerializableLimitIterator's constructor - #56

Open
arhimede wants to merge 2 commits into
laminas:2.18.xfrom
arhimede:invalid-constructor-call
Open

Fix invalid call to SerializableLimitIterator's constructor#56
arhimede wants to merge 2 commits into
laminas:2.18.xfrom
arhimede:invalid-constructor-call

Conversation

@arhimede

Copy link
Copy Markdown
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.

Signed-off-by: arhimede <julian@dotkernel.com>
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Signed-off-by: arhimede <julian@dotkernel.com>
@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