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

Api4 - Use explicit adder functions rather than magicMethod #16372

Merged
merged 1 commit into from
Jan 27, 2020

Conversation

colemanw
Copy link
Member

Overview

Improves the way some Api4 action classes receive their parameters.

Before

Api Actions had been relying on a magic method to provide getter/setter functions for params.
That works fine for simple get/set operations but it was also attempting to provide adder functions.
Those are more nuanced and the magic method didn't do a good job of understanding whether the param was an indexed or unindexed array, and didn't do strict type checking.

After

Making our own adder functions gives better documentation, stricter checking of inputs and also
the convenience of variadic functions for adding several values at once.
Magic "addFoo" removed.

Api Actions had been relying on a magic method to provide getter/setter functions for params.
That works fine for simple get/set operations but it was also attempting to provide adder functions.
Those are more nuanced and the magic method didn't do a good job of understanding whether the param
was an indexed or unindexed array, and didn't do strict type checking.
Making our own adder functions gives better documentation, stricter checking of inputs and also
the convenience of variadic functions for adding several values at once.
@civibot
Copy link

civibot bot commented Jan 24, 2020

(Standard links)

@civibot civibot bot added the master label Jan 24, 2020
@colemanw
Copy link
Member Author

@seamuslee001 the checkStyle test doesn't understand docblocks for variadic functions. I'm using the recommended @param Type ...$var docs which is supported by PHPStorm. Do you think we could either:

  1. Upgrade our style checker to see if it's been fixed upstream
  2. Patch it ourselves
  3. Just disable those specific checks

@seamuslee001
Copy link
Contributor

@colemanw looks like we might need to apply a patch from here https://www.drupal.org/project/coder/issues/2878783 Likely patch 5 i would imagine

@seamuslee001
Copy link
Contributor

@colemanw have created a PR here civicrm/coder#9

@seamuslee001
Copy link
Contributor

Jenkins re test this please

@eileenmcnaughton
Copy link
Contributor

Our unit test cover should be pretty solid on this

@eileenmcnaughton eileenmcnaughton merged commit 22e7138 into civicrm:master Jan 27, 2020
@eileenmcnaughton eileenmcnaughton deleted the api4Magic branch January 27, 2020 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants