-
-
Notifications
You must be signed in to change notification settings - Fork 522
Docs: Add documentation for WordPress.PHP.TypeCasts #2591
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
base: develop
Are you sure you want to change the base?
Changes from all commits
4f38caf
795e5ff
6bf9ab7
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,56 @@ | ||||||||||||||||||||||
| <?xml version="1.0"?> | ||||||||||||||||||||||
| <documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||||||||||||||||||
| xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd" | ||||||||||||||||||||||
| title="Type Casts" | ||||||||||||||||||||||
| > | ||||||||||||||||||||||
| <standard> | ||||||||||||||||||||||
| <![CDATA[ | ||||||||||||||||||||||
| Enforce normalized and safe type casts. | ||||||||||||||||||||||
|
Collaborator
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'm unsure about a few things in this paragraph:
Here is a suggestion of a possible alternative for description. Feel free to create your own version. |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| • Use (float) instead of legacy float casts. | ||||||||||||||||||||||
| • Do not use the (unset) cast. Use unset(). | ||||||||||||||||||||||
| • Avoid the (binary) cast (discouraged). | ||||||||||||||||||||||
|
Comment on lines
+8
to
+12
Collaborator
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
|
||||||||||||||||||||||
| ]]> | ||||||||||||||||||||||
| </standard> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| <code_comparison> | ||||||||||||||||||||||
|
Member
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. The code comparison should have "valid" on the left (first code sample), "invalid" on the right (second code sample).
Author
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. Thanks for the feedback! I’ve reordered the code examples so that Valid is on the left and Invalid is on the right, as suggested. |
||||||||||||||||||||||
| <code title="Valid: Using normalized float casts."> | ||||||||||||||||||||||
| <![CDATA[ | ||||||||||||||||||||||
| $price = <em>(float)</em> $value; | ||||||||||||||||||||||
| $size = <em>(float)</em> $value; | ||||||||||||||||||||||
| ]]> | ||||||||||||||||||||||
| </code> | ||||||||||||||||||||||
| <code title="Invalid: Using legacy float casts."> | ||||||||||||||||||||||
| <![CDATA[ | ||||||||||||||||||||||
| $price = <em>(double)</em> $value; | ||||||||||||||||||||||
| $size = <em>(real)</em> $value; | ||||||||||||||||||||||
| ]]> | ||||||||||||||||||||||
| </code> | ||||||||||||||||||||||
| </code_comparison> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| <code_comparison> | ||||||||||||||||||||||
| <code title="Valid: Use unset()."> | ||||||||||||||||||||||
| <![CDATA[ | ||||||||||||||||||||||
| unset( $value ); | ||||||||||||||||||||||
|
Collaborator
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
|
||||||||||||||||||||||
| ]]> | ||||||||||||||||||||||
| </code> | ||||||||||||||||||||||
| <code title="Invalid: Using the (unset) cast."> | ||||||||||||||||||||||
| <![CDATA[ | ||||||||||||||||||||||
| result = <em>(unset)</em> $value; | ||||||||||||||||||||||
|
Collaborator
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
|
||||||||||||||||||||||
| ]]> | ||||||||||||||||||||||
| </code> | ||||||||||||||||||||||
| </code_comparison> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| <code_comparison> | ||||||||||||||||||||||
| <code title="Valid: Prefer a clear alternative."> | ||||||||||||||||||||||
|
Collaborator
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. Maybe "Valid: Using (string) cast instead."? This way the title clearly communicates what is the alternative like the other titles. That being said, I noticed that the sniff also detects the binary string prefix notation In that case, the title could be something like "Valid: (binary) is not used." or "Valid: Use (string) or regular strings." Another option is to create a separate What do you think? |
||||||||||||||||||||||
| <![CDATA[ | ||||||||||||||||||||||
| bytes = (string) $value; | ||||||||||||||||||||||
|
Collaborator
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
|
||||||||||||||||||||||
| ]]> | ||||||||||||||||||||||
| </code> | ||||||||||||||||||||||
| <code title="Invalid: Using the (binary) cast."> | ||||||||||||||||||||||
| <![CDATA[ | ||||||||||||||||||||||
| bytes = <em>(binary)</em> $value; | ||||||||||||||||||||||
| ]]> | ||||||||||||||||||||||
| </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.