-
-
Notifications
You must be signed in to change notification settings - Fork 824
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
(REF) Civi/Schema - Extract MagicGetterSetterTrait. Add test coverage. #20865
Conversation
(Standard links)
|
@totten I tested this & have a couple of observations I feel like we should do some sort of testing or other noise to ensure that people ARE adding the annotations or it will get fugly quickly
|
@totten On first glance I read this as "Effluent" GetterSetterTrait and now can't get it out of my head. Would a better name be Otherwise seems like a good idea. |
OK - let's give it a few days to see if we can put effluent behind us (gufaw) or whether we need to rename ..... |
578becb
to
e1f0b33
Compare
Lol, I've never seen the word "Effluent" before 🚰. Agree that
Yeah, agree that's a little annoying. FWIW, I've updated the docblock to mention this and point to some examples... so at least now it's mentioned somewhere...
It's almost easier to use real getter+setters with PHPStorm's code-generator than to add those docblocks. But the magic approach is still probably a bit better (ie the class files are less noisy overall, and the magic implementations are consistently fluent - PHPStorm codegen doesn't use a fluent template.) Adding some kind of test could be nice. Maybe a
Interesting. I had been angling (in low-priority/future-maybe way) to include a type-check as part of the I guess it's conceivable to implement at the magic-setter-level. In the current regime, that would require a bit more docblock parsing - but it's fine if a request only has a handful of these classes. (It'd also be fine if only activated in some kind of strict-mode or test-mode.) FWIW, PHP 7.4 adds built-in support for type-checking of properties (e.g. https://stitcher.io/blog/typed-properties-in-php-74)... the issue might resolve itself whenever we get to use php74 typehints... |
657a4e2
to
f0b61af
Compare
@totten - @eileenmcnaughton has reported a regression caused by this PR in https://lab.civicrm.org/dev/core/-/issues/2768#note_63239 |
Overview
Creates a trait,
MagicGetterSetterTrait
, which captures the magic getter/setter behavior from APIv4'sFluentGetterSetterTrait
AbstractAction
class. This makes it easier to implement similar behavior in other classes, and it ensures that certain rules (like handling of_
) are standardized.For example:
Before
AbstractAction
implements__call()
(to handlegetFoo()
andsetFoo()
) and does scanning/filtering of the property-list.After
AbstractAction
usesMagicGetterSetterTrait
.MagicGetterSetterTrait
implements__call()
(to handlegetFoo()
andsetFoo()
)and does scanning/filtering of the property-list.MagicGetterSetterTrait
which touches on the naming and string-manipulation.Comment
The methods
AbstractAction::getParams()
(public) and theMagicGetterSetterTrait::getMagicProperties()
(private) may sound similar, but they differ:getParams()
returns all of the parameter data. In effect, it converts$this
from an object to anarray
(but filtered by the property-list).getMagicProperties()
only returns the property-list.(*Updated description to reflect name change:
FluentGetterSetterTrait
=>MagicGetterSetterTrait
)