-
-
Notifications
You must be signed in to change notification settings - Fork 518
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 1 commit
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,38 @@ | ||||||
<?xml version="1.0"?> | ||||||
<documentation title="Type Casts"> | ||||||
<standard> | ||||||
<![CDATA[ | ||||||
This sniff normalizes float type cast keywords. | ||||||
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. This sentence seems redundant. 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. Reworded the opener to be shorter and clearer. It now states the rules enforced without repeating itself. |
||||||
|
||||||
Use (float) instead of legacy synonyms: | ||||||
- Disallowed: (double), (real) | ||||||
- Allowed: (float) | ||||||
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. This is incorrect/incomplete. The sniff:
Considering the above, I believe the code samples also need work. 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. Updated the standard text and the code examples to cover all three behaviors: |
||||||
|
||||||
Note: Other type-cast rules in the WordPress standard | ||||||
are enforced by different sniffs: | ||||||
- Short forms like (int), (bool), (string): | ||||||
PSR12.Keywords.ShortFormTypeKeywords | ||||||
- No spaces inside parentheses: | ||||||
Squiz.WhiteSpace.CastSpacing | ||||||
- Exactly one space after the cast: | ||||||
Generic.Formatting.SpaceAfterCast | ||||||
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. This whole block doesn't belong here. Each sniff functions independently of other sniffs. That also means that the docs should be independent of each other and should just focus on what this sniff does. 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! I’ve removed the paragraph referencing other sniffs. The docs now only describe what WordPress.PHP.TypeCasts enforces. |
||||||
]]> | ||||||
</standard> | ||||||
|
||||||
<code_comparison> | ||||||
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). 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="Invalid: legacy float casts"> | ||||||
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
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. Adjusted the code block titles to your suggested wording. |
||||||
<![CDATA[ | ||||||
<?php | ||||||
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. PHP open tag is not needed here. (Same for the "invalid" code sample) 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. Removed <?php from all code samples as suggested. |
||||||
$price = <em>(double)</em> $value; | ||||||
$size = <em>(real)</em> $value; | ||||||
]]> | ||||||
</code> | ||||||
<code title="Valid: normalized float cast"> | ||||||
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
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. Adjusted the code block titles to your suggested wording. 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. Updated code block titles to “Valid: Using normalized float casts.” (and similar phrasing for the other examples), as suggested. |
||||||
<![CDATA[ | ||||||
<?php | ||||||
$price = <em>(float)</em> $value; | ||||||
$size = <em>(float)</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.
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.
Added the schema header and xsi:noNamespaceSchemaLocation pointing to phpcsdocs.xsd.