Skip to content

Mark Selectable::matching as a mutation free - #124

Open
fluffycondor wants to merge 1 commit into
psalm:2.xfrom
fluffycondor:matching-mutation-free
Open

Mark Selectable::matching as a mutation free#124
fluffycondor wants to merge 1 commit into
psalm:2.xfrom
fluffycondor:matching-mutation-free

Conversation

@fluffycondor

Copy link
Copy Markdown
Contributor

@orklah

orklah commented Aug 11, 2022

Copy link
Copy Markdown
Collaborator

Note: I don't know Doctrine enough so I may ask stupid questions :)

Is the creation of a new Collection necessarily mutable-free (if so, should Collection::__construct be flagged as mutation-free)? Does it clone the provided Collection maybe?

@fluffycondor

Copy link
Copy Markdown
Contributor Author

Is the creation of a new Collection necessarily mutable-free (if so, should Collection::__construct be flagged as mutation-free)?
Does it clone the provided Collection maybe?

Collection interface doesn't specify any requirements for realizations' constructor. The only implementation Doctrine has is ArrayCollection, which takes an array. It doesn't clone deeply array values, so if it's an array of objects, objects will be copied by ref.
So, Selectable::matching will definitely return a new Collection, but if the values are not scalar, it will be copied by ref. As far as I understand, it's still can be called mutation-free.

@ygottschalk

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants