-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
RFC: 4.0+ Roadmap - Remove magic method #11751
Comments
Fair points. |
This will then also require less ide annotations maybe in the future for some areas. But I am not sure if we should keep this ticket open here, if there are no more concrete things to discuss or create a plan of attack from this. |
Perhaps it can be broken down into actionable tickets which reference back to this one? |
You could also update this one with a |
@davidyell Did you add it anywhere yet? So it won't be forgotten? |
No @dereuromark I haven't |
Is there anything concrete left to be done or tracked? |
ping @davidyell |
I don't know how to add to the Roadmap. Seems I don't have permission to edit the roadmap wiki. |
You can also just outline it here, in more concrete steps - and someone can copy it over. |
Remove the |
Added to the roadmap doc. |
I added it to 4.1 yesterday :) |
This is a (multiple allowed):
bug
enhancement
feature-discussion (RFC)
CakePHP Version: 4.0 onwards
What you did
Tried to mock the
\Cake\ORM\Query
class, to create a fixed return. My IDE was suggesting that I could mockCake\ORM\Query::extract()
even though this method does not exist.It's linked via a docblock, but doesn't exist in the class.
What happened
I was unable to achieve this and had to use a Fixture, and actually execute the query with data. Rather than just mocking the query and having a fixed return.
What you expected to happen
I expected to find the methods which I wanted to mock in the class. Then setup a mock of the
Cake\ORM\Query
object and configure a fixed return of either an array, or\Cake\ORM\ResultSet
.How did I solve the issue
I had to ask both my colleagues and in the Slack channel to find out how the
\Cake\ORM\Query
class was implementing Collection class methods, when there was no obvious extension, trait, or interface implementation shown in the code.What was the solution
It turns out the
\Cake\Datasource\QueryTrait
has a__call()
method. Shown hereAs I am not overly familiar with magic methods. I was reading the source code, and 'chasing functions' in my IDE, I was unable to work out how all the methods were being made available. The code did not describe it's behaviour to me, making it hard to reason about.
RFC
I'd like to suggest an addition to the 4.x Roadmap to remove this magic method, and add concrete implementation in the ORM, so that the source code is easier to reason about, requires less docblock links and is more obvious when being read.
Side note
At PHP Conf UK one year I was talking to attendees about frameworks and they had a poor opinion of CakePHP because of its use of magic methods and it's "black box" approach. I feel that things like this are validating that opinion, rather than challenging it.
The text was updated successfully, but these errors were encountered: