-
Notifications
You must be signed in to change notification settings - Fork 51
Ensure that Typed Properties are spaced correctly #166
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
Conversation
This new rule checks for things like: - no space between the typehint and the property name - no space between the typehint and the property's modifiers - no space between the nullability symbol and the typehint This rule does not check for: - How many lines the typed properties are separated by - If two consecutive properties have default values, the `=` sign will be aligned# Please enter the commit message for your changes. Lines starting
@@ -380,6 +380,7 @@ | |||
</property> | |||
</properties> | |||
</rule> | |||
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHintSpacing"/> |
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.
The comment for this rule and the others are on lines 360-362:
coding-standard/lib/Doctrine/ruleset.xml
Lines 360 to 362 in d025e82
<!-- Require types to be written as natively if possible; | |
require iterable types to specify phpDoc with their content; | |
forbid useless/duplicated information in phpDoc --> |
@@ -29,7 +29,8 @@ index d1fdd9f..4b5f6e4 100644 | |||
tests/input/new_with_parentheses.php 18 0 | |||
tests/input/not_spacing.php 8 0 | |||
tests/input/null_coalesce_operator.php 3 0 | |||
@@ -27,21 +29,22 @@ tests/input/optimized-functions.php 1 0 | |||
tests/input/optimized-functions.php 1 0 | |||
+tests/input/PropertyTypeHintSpacing.php 6 0 |
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.
Output of ./vendor/bin/phpcs tests/input/PropertyTypeHintSpacing.php
:
E 1 / 1 (100%)
FILE: tests/input/PropertyTypeHintSpacing.php
--------------------------------------------------------------------------------------------------
FOUND 6 ERRORS AFFECTING 4 LINES
--------------------------------------------------------------------------------------------------
9 | ERROR | [x] Equals sign not aligned correctly; expected 1 space but found 2 spaces
10 | ERROR | [x] There must be 1 space after the property type declaration; 2 found
10 | ERROR | [x] There must be exactly one space between type hint and property.
11 | ERROR | [x] Scope keyword "public" must be followed by a single space; found 2
11 | ERROR | [x] There must be exactly one space before type hint.
12 | ERROR | [x] There must be no whitespace between type hint nullability symbol and type hint.
--------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------
Time: 95ms; Memory: 8MB
@carusogabriel The description looks wrong:
I think there should be |
This new rule checks for things like:
This rule does not check for:
=
sign will be alignedThis also falls under the PSR-12, by the item 4.3: