Skip to content

Add documentation for WordPress.PHP.DevelopmentFunctions - #2490

Closed
gogdzl wants to merge 2 commits into
WordPress:developfrom
gogdzl:docs/WordPress.PHP.DevelopmentFunctions
Closed

gogdzl wants to merge 2 commits into
WordPress:developfrom
gogdzl:docs/WordPress.PHP.DevelopmentFunctions

Conversation

@gogdzl

@gogdzl gogdzl commented Sep 17, 2024

Copy link
Copy Markdown
Contributor

Related to #1722

@jrfnl jrfnl mentioned this pull request Sep 17, 2024
51 of 61 tasks

@rodrigoprimo rodrigoprimo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for working on this PR, @gogdzl! I'm not a maintainer of the project so take my review with a grain of salt. That being said, I left some comments based on my own experience creating PHPCS and WPCS sniffs.

Debug code should not normally be used in production.

Typically, this rule verifies if function calls to the PHP native `error_log()`, `var_dump()`, `var_export()`, `print_r()`, `trigger_error()`, `set_error_handler()`, `debug_backtrace`, `debug_print_backtrace` and `wp_debug_backtrace_summary()` functions are present in the code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Typically, this rule verifies if function calls to the PHP native `error_log()`, `var_dump()`, `var_export()`, `print_r()`, `trigger_error()`, `set_error_handler()`, `debug_backtrace`, `debug_print_backtrace` and `wp_debug_backtrace_summary()` functions are present in the code.
This rule verifies if calls to the `error_log()`, `var_dump()`, `var_export()`, `print_r()`, `trigger_error()`, `set_error_handler()`, `debug_backtrace()`, `debug_print_backtrace()` and `wp_debug_backtrace_summary()` functions are present in the code.

I'm suggesting the removal of the PHP native part as wp_debug_backtrace_summary() is not a PHP native function.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe instead of verifies, we could use warns to more accurately describe what the rule does? Just thinking out loud here.

>
Debug code should not normally be used in production.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know that this is the warning message displayed by the sniff, but I believe that the documentation (and maybe also the sniff messages) usually only uses should/should not when describing an error. Since this is a warning, maybe we could say that it is recommended or something like that?

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 This is incorrect.

For the record - "should"/"should not" translates to warnings, "must"/"must not" translates to errors.

This is based on an official RFC about this type of terminology: https://www.rfc-editor.org/rfc/rfc2119

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the reminder. I have learned that since I left this comment, but I must say that sometimes I mix the two. I suggest adding a note about this to the "Guidelines for the documentation and the code samples" section of #1722. What do you think?

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.

I don't think an issue is the right place for that and more than anything, this RFC applies to the standards as described in the handbook, with WPCS following, not the other way around.

@rodrigoprimo rodrigoprimo Feb 3, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest this because I think it is the kind of information that will be useful for those who work on creating WPCS sniff documentation.

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.

Agreed, but I just don't think the issue is the right place. Maybe a CONTRIBUTING file for the wpcs-docs repo ? Maybe the CONTRIBUTING file for this repo ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree that a CONTRIBUTING file is a better place for this.

Assuming this applies to PHPCS as well, maybe we should add a note on when to use must/should to its CONTRIBUTING.md file? We could add it to the "Writing Sniff Documentation" section. I know this doesn't apply only to sniff documentation but also to the error/warning messages generated by sniffs, but I'm not sure where else to add it.

Then, in the WPCS CONTRIBUTING file, we could address #2462 by creating a section pointing to "Writing Sniff Documentation" in the PHPCS repository and also add a new sub-section under "Considerations when writing sniffs".

As for the wpcs-docs repo, it doesn't have a CONTRIBUTING file, and I'm not sure where this guidance would fit there.

How does this sound?

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.

The RFC standard I referenced is primarily about the meaning of certain phrases in standards.

PHP_CodeSniffer and WPCS are not the standards. They are tools to enforce standards. The standards themselves are described in the WP Core handbook (for WPCS), the PEAR project or the FIG published PSRs.
And each of those has to decide for themselves whether they want to follow the RFC. After all, that's not a given perse.

So, more than anything, this is something which should be in the contributing guides of the verbal standards.
And both sniffs as well as the XML docs for those sniffs should follow the lead of the actual standards.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for clarifying the parts I was getting wrong.

That said, I think there's still value in having a brief note in the WPCS CONTRIBUTING file to help contributors be consistent when writing XML docs and sniff messages. Not to define the convention in the WPCS repository, but to remind contributors to mirror the language used in the standard (e.g., "must" for errors, "should" for warnings). Especially considering that, unless I'm missing something, there is no clear place at the moment to add this instruction in the wpcs-docs repository.

Would that be acceptable?

]]>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not is in between parenthesis?

Also, I wonder if the message should be more generic and mention debug code/functions instead of singling out var_dump()? I'm ok with a single example with just var_dump().

@rodrigoprimo

Copy link
Copy Markdown
Contributor

@gogdzl, I was just wondering if you'll have a chance to finish this off in the near future. It would be great if this PR could be included in the next WPCS release.

If you haven't got time or lost interest, please let us know and we'll see if we can find someone to take over. Thanks!

@rodrigoprimo

Copy link
Copy Markdown
Contributor

@gogdzl, please let us know within a week if you are still interested in finishing this PR. If we don't hear back from you, we will presume you don't have time, and we will see if we can find someone else to take over and finish it. Thanks for your work so far!

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