Repository navigation
✨ New WordPress.WP.GetMetaSingle sniff - #2465
Conversation
This sniff warns when get_*_meta() and get_metadata*() functions are used with the $meta_key/$key param, but without the $single parameter. This could lead to unexpected behavior as an array will be returned, but a string might be expected.
|
We reviewed this in a pairing session, formal review will follow once the next iteration is up. |
d60856e to
ad4f238
Compare
ad4f238 to
d189e65
Compare
|
@jrfnl, I implemented the changes that you suggested during our pairing session, and this PR is ready for a final review. |
|
When we checked this PR together, you suggested that I change the title of the XML documentation from |
There was a problem hiding this comment.
He @rodrigoprimo, thanks for updating the PR!
Mostly looking good. I did leave some remarks inline, mostly small/nitpicky things, but a few to do with precision which really should be fixed.
When we checked this PR together, you suggested that I change the title of the XML documentation from
Get Meta SingletoGet Meta Function Single Parameter. I opted to follow the same pattern and rename the sniff as well fromGetMetaSingletoGetMetaFunctionSingleParameter. Let me know if you prefer the new name or the old name.
I think the new name is very long and wordy and, like I said when we discussed this before, I think I prefer a name which is in line with prior art in this repo, which largely uses the FunctionNameParameterNameSniff pattern, which this sniff now doesn't comply with.
Examples of prior art:
CurrentTimeTimestampSniffPregQuoteDelimiterSniffStrictInArraySniff(wrong order, but that's historical, principle is still the same)
Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com>
|
Thanks for your review, @jrfnl. I added new commits addressing all the points that you raised. Could you please take another look?
That makes sense. I reverted to using |
ceb3d3b to
c73162e
Compare
jrfnl
left a comment
There was a problem hiding this comment.
@rodrigoprimo Thanks for updating the sniff, including the updates made during our video call today in which we did a final review of the sniff.
As discussed, I've now also added a metric to the sniff, just in case someone finds it useful (like when checking the state of things this sniff checks for in plugins in the plugin repo).
As far as I'm concerned, this is ready for merge.
@dingo-d @GaryJones Do you still want to have a look or can I merge this ?
Note: this should be squashed-merged!
* upstream/develop: (428 commits) Rulesets: update schema URL GH Actions: use the xmllint-validate action runner and enhance checks (WordPress#2522) AbstractFunctionParameterSniff: fix first class callables and function imports (WordPress#2518) DontExtractStandard.xml file creation (WordPress#2456) Add documentation for WordPress.NamingConventions.ValidVariableName (WordPress#2457) Remove unused variables from a few sniffs (WordPress#2514) I18nTextDomainFixer: remove unnecessary variable initialization (WordPress#2513) GH Actions: Bump codecov/codecov-action from 4 to 5 (WordPress#2510) GH Actions: PHP 8.4 has been released CS/QA: remove redundant condition GH Actions: use explicit PHPStan major Various sniffs: simplify skipping the rest of the file GH Actions: always quote variables Release checklist: add new action item AbstractClassRestrictionsSniff: fix insufficient defensive coding (WordPress#2500) ✨ New WordPress.WP.GetMetaSingle sniff (WordPress#2465) Fix typo in AbstractFunctionRestrictionsSniff::is_targetted_token() DocBlock (WordPress#2477) Fix typos (WordPress#2472) Documentation: capitalization consistency fixes (WordPress#2469) [Documentation]: WordPress.DB.PreparedSQL (WordPress#2454) ...
This sniff warns when get_*_meta() and get_metadata*() functions are used with the $meta_key/$key param, but without the $single parameter (here is the full list of functions that trigger this sniff). This could lead to unexpected behavior as an array will be returned, but a string might be expected.
This PR adds the new sniff to WordPress-Extra as suggested by Juliette in this Slack thread.
It includes tests and sniff documentation in the XML format.
Related issue: #2459