Skip to content

✨ New WordPress.WP.GetMetaSingle sniff - #2465

Merged
dingo-d merged 11 commits into
WordPress:developfrom
rodrigoprimo:new-get-meta-single-sniff
Aug 28, 2024
Merged

dingo-d merged 11 commits into
WordPress:developfrom
rodrigoprimo:new-get-meta-single-sniff

Conversation

@rodrigoprimo

@rodrigoprimo rodrigoprimo commented Jul 12, 2024 •

Copy link
Copy Markdown
Contributor

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

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.
@jrfnl

jrfnl commented Jul 26, 2024

Copy link
Copy Markdown
Member

We reviewed this in a pairing session, formal review will follow once the next iteration is up.

@rodrigoprimo
rodrigoprimo force-pushed the new-get-meta-single-sniff branch 2 times, most recently from d60856e to ad4f238 Compare July 29, 2024 08:38
@rodrigoprimo
rodrigoprimo force-pushed the new-get-meta-single-sniff branch from ad4f238 to d189e65 Compare August 5, 2024 13:26
@rodrigoprimo

Copy link
Copy Markdown
Contributor Author

@jrfnl, I implemented the changes that you suggested during our pairing session, and this PR is ready for a final review.

@rodrigoprimo

Copy link
Copy Markdown
Contributor Author

When we checked this PR together, you suggested that I change the title of the XML documentation from Get Meta Single to Get Meta Function Single Parameter. I opted to follow the same pattern and rename the sniff as well from GetMetaSingle to GetMetaFunctionSingleParameter. Let me know if you prefer the new name or the old name.

@jrfnl jrfnl left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Single to Get Meta Function Single Parameter. I opted to follow the same pattern and rename the sniff as well from GetMetaSingle to GetMetaFunctionSingleParameter. 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:

  • CurrentTimeTimestampSniff
  • PregQuoteDelimiterSniff
  • StrictInArraySniff (wrong order, but that's historical, principle is still the same)

Comment thread WordPress/Docs/WP/GetMetaFunctionSingleParameterStandard.xml Outdated
Comment thread WordPress/Docs/WP/GetMetaFunctionSingleParameterStandard.xml
Comment thread WordPress/Docs/WP/GetMetaFunctionSingleParameterStandard.xml Outdated
Comment thread WordPress/Docs/WP/GetMetaFunctionSingleParameterStandard.xml Outdated
Comment thread WordPress/Sniffs/WP/GetMetaFunctionSingleParameterSniff.php
Comment thread WordPress/Sniffs/WP/GetMetaFunctionSingleParameterSniff.php Outdated
Comment thread WordPress/Sniffs/WP/GetMetaFunctionSingleParameterSniff.php Outdated
Comment thread WordPress/Sniffs/WP/GetMetaFunctionSingleParameterSniff.php Outdated
Comment thread WordPress/Sniffs/WP/GetMetaFunctionSingleParameterSniff.php Outdated
Comment thread WordPress/Sniffs/WP/GetMetaFunctionSingleParameterSniff.php Outdated
@jrfnl jrfnl removed this from the 3.x Next milestone Aug 20, 2024
@rodrigoprimo

Copy link
Copy Markdown
Contributor Author

Thanks for your review, @jrfnl. I added new commits addressing all the points that you raised. Could you please take another look?

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.

That makes sense. I reverted to using GetMetaSingle as the name of the sniff.

@rodrigoprimo
rodrigoprimo force-pushed the new-get-meta-single-sniff branch from ceb3d3b to c73162e Compare August 26, 2024 15:18

@jrfnl jrfnl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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!

@jrfnl jrfnl added this to the 3.x Next milestone Aug 26, 2024

@dingo-d dingo-d left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@dingo-d
dingo-d merged commit 7f76630 into WordPress:develop Aug 28, 2024
@rodrigoprimo
rodrigoprimo deleted the new-get-meta-single-sniff branch August 28, 2024 14:18
lesterchan added a commit to lesterchan/WordPress-Coding-Standards that referenced this pull request Jun 8, 2025
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants