-
-
Notifications
You must be signed in to change notification settings - Fork 490
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
Add documentation for WordPress.PHP.NoSilencedErrors #2495
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||||||||||||||||||||
<?xml version="1.0"?> | ||||||||||||||||||||||||
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||||||||||||||||||||
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd" | ||||||||||||||||||||||||
title="Discourage the use of the PHP error silencing operator" | ||||||||||||||||||||||||
> | ||||||||||||||||||||||||
<standard> | ||||||||||||||||||||||||
<![CDATA[ | ||||||||||||||||||||||||
Silencing errors is strongly discouraged. Use proper error checking instead. | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Using the error operator with certain functions is allowed because no amount of error checking can fully prevent PHP from throwing errors when these functions are executed. The functions where this is permitted include, but are not limited to: | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that we should not include all the allowed functions, as the list is very long. But I'm unsure about adding just a few. I don't really know what criteria would be good for deciding which functions to include. What criteria did you use? I'd be more inclined to just mention that some functions are allowed and point users to search for the In the WPCS repository, there is one sniff documentation that uses an external link in a different context: WordPress-Coding-Standards/WordPress/Docs/NamingConventions/PrefixAllGlobalsStandard.xml Lines 6 to 16 in cdb29b5
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
- `file_exists()` | ||||||||||||||||||||||||
- `file_get_contents()` | ||||||||||||||||||||||||
- `filesize()` | ||||||||||||||||||||||||
- `filetype()` | ||||||||||||||||||||||||
- `fopen()` | ||||||||||||||||||||||||
- `ftp_login()` | ||||||||||||||||||||||||
- `ftp_rename()` | ||||||||||||||||||||||||
]]> | ||||||||||||||||||||||||
</standard> | ||||||||||||||||||||||||
<code_comparison> | ||||||||||||||||||||||||
<code title="Valid: Using proper error checking when calling functions not in the allowed list."> | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To me, the valid message should be about what the sniff considers valid. The sniff doesn't check for proper error checking. Instead, it checks whether the For the same reason, I'm unsure if error handling should be included in the code sample. Maybe checking the documentation of other sniffs might help you decide which approach you want to take? Also, feel free to wait for the input of one of the maintainers regarding this. |
||||||||||||||||||||||||
<![CDATA[ | ||||||||||||||||||||||||
$conn_id = ftp_connect( $ftp_server ); | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
if ( ! $conn_id ) { | ||||||||||||||||||||||||
// Handle it as needed. | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
]]> | ||||||||||||||||||||||||
</code> | ||||||||||||||||||||||||
<code title="Invalid: Using the error operator to silence errors."> | ||||||||||||||||||||||||
<![CDATA[ | ||||||||||||||||||||||||
$conn_id = <em>@ftp_connect( $ftp_server );</em> | ||||||||||||||||||||||||
]]> | ||||||||||||||||||||||||
</code> | ||||||||||||||||||||||||
</code_comparison> | ||||||||||||||||||||||||
</documentation> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, the title should match the name of the sniff (with some rare exceptions).