Skip to content

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

Merged
merged 1 commit into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Doctrine/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@
</property>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHintSpacing"/>
Copy link
Contributor Author

@carusogabriel carusogabriel Mar 22, 2020

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:

<!-- Require types to be written as natively if possible;
require iterable types to specify phpDoc with their content;
forbid useless/duplicated information in phpDoc -->

<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
<properties>
<property name="traversableTypeHints" type="array">
Expand Down
13 changes: 13 additions & 0 deletions tests/fixed/PropertyTypeHintSpacing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Spacing;

final class PropertyTypeHintSpacing
{
public bool $boolPropertyWithDefaultValue = false;
public string $stringProperty;
public int $intProperty;
public ?string $nullableString = null;
}
13 changes: 13 additions & 0 deletions tests/input/PropertyTypeHintSpacing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Spacing;

final class PropertyTypeHintSpacing
{
public bool $boolPropertyWithDefaultValue = false;
public string $stringProperty;
public int $intProperty;
public ? string $nullableString = null;
}
17 changes: 9 additions & 8 deletions tests/php-compatibility.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
index d1fdd9f..4b5f6e4 100644
index d1fdd9f..577922e 100644
--- a/tests/expected_report.txt
+++ b/tests/expected_report.txt
@@ -5,21 +5,23 @@ FILE ERRORS WARNINGS
@@ -5,43 +5,47 @@ FILE ERRORS WARNINGS
----------------------------------------------------------------------
tests/input/array_indentation.php 10 0
tests/input/assignment-operators.php 4 0
Expand All @@ -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
Copy link
Contributor Author

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

tests/input/return_type_on_closures.php 21 0
tests/input/return_type_on_methods.php 17 0
tests/input/semicolon_spacing.php 3 0
Expand All @@ -48,18 +49,18 @@ index d1fdd9f..4b5f6e4 100644
tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 296 ERRORS AND 0 WARNINGS WERE FOUND IN 35 FILES
+A TOTAL OF 349 ERRORS AND 0 WARNINGS WERE FOUND IN 38 FILES
+A TOTAL OF 355 ERRORS AND 0 WARNINGS WERE FOUND IN 39 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 235 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 284 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 290 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


diff --git a/tests/fixed/example-class.php b/tests/fixed/example-class.php
index 59148a3..eb019d5 100644
index dbec9cb..dca22ed 100644
--- a/tests/fixed/example-class.php
+++ b/tests/fixed/example-class.php
@@ -23,14 +23,12 @@ class Example implements IteratorAggregate
@@ -25,14 +25,12 @@ class Example implements IteratorAggregate
{
private const VERSION = PHP_VERSION - (PHP_MINOR_VERSION * 100) - PHP_PATCH_VERSION;

Expand All @@ -78,7 +79,7 @@ index 59148a3..eb019d5 100644
/** @var ControlStructureSniff|int|string|null */
private $baxBax;
diff --git a/tests/fixed/type-hints.php b/tests/fixed/type-hints.php
index a1b1827..fb7d406 100644
index 0e952fc..9824fb0 100644
--- a/tests/fixed/type-hints.php
+++ b/tests/fixed/type-hints.php
@@ -10,7 +10,7 @@ use Traversable;
Expand Down