Skip to content

Commit bfeda8c

Browse files
Merge pull request #166 from doctrine/feature/property-type-hints-spacing
Ensure that Typed Properties are spaced correctly
2 parents d025e82 + 58ee6a2 commit bfeda8c

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

lib/Doctrine/ruleset.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@
380380
</property>
381381
</properties>
382382
</rule>
383+
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHintSpacing"/>
383384
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
384385
<properties>
385386
<property name="traversableTypeHints" type="array">
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Spacing;
6+
7+
final class PropertyTypeHintSpacing
8+
{
9+
public bool $boolPropertyWithDefaultValue = false;
10+
public string $stringProperty;
11+
public int $intProperty;
12+
public ?string $nullableString = null;
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Spacing;
6+
7+
final class PropertyTypeHintSpacing
8+
{
9+
public bool $boolPropertyWithDefaultValue = false;
10+
public string $stringProperty;
11+
public int $intProperty;
12+
public ? string $nullableString = null;
13+
}

tests/php-compatibility.patch

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
2-
index d1fdd9f..4b5f6e4 100644
2+
index d1fdd9f..577922e 100644
33
--- a/tests/expected_report.txt
44
+++ b/tests/expected_report.txt
5-
@@ -5,21 +5,23 @@ FILE ERRORS WARNINGS
5+
@@ -5,43 +5,47 @@ FILE ERRORS WARNINGS
66
----------------------------------------------------------------------
77
tests/input/array_indentation.php 10 0
88
tests/input/assignment-operators.php 4 0
@@ -29,7 +29,8 @@ index d1fdd9f..4b5f6e4 100644
2929
tests/input/new_with_parentheses.php 18 0
3030
tests/input/not_spacing.php 8 0
3131
tests/input/null_coalesce_operator.php 3 0
32-
@@ -27,21 +29,22 @@ tests/input/optimized-functions.php 1 0
32+
tests/input/optimized-functions.php 1 0
33+
+tests/input/PropertyTypeHintSpacing.php 6 0
3334
tests/input/return_type_on_closures.php 21 0
3435
tests/input/return_type_on_methods.php 17 0
3536
tests/input/semicolon_spacing.php 3 0
@@ -48,18 +49,18 @@ index d1fdd9f..4b5f6e4 100644
4849
tests/input/UselessConditions.php 20 0
4950
----------------------------------------------------------------------
5051
-A TOTAL OF 296 ERRORS AND 0 WARNINGS WERE FOUND IN 35 FILES
51-
+A TOTAL OF 349 ERRORS AND 0 WARNINGS WERE FOUND IN 38 FILES
52+
+A TOTAL OF 355 ERRORS AND 0 WARNINGS WERE FOUND IN 39 FILES
5253
----------------------------------------------------------------------
5354
-PHPCBF CAN FIX 235 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
54-
+PHPCBF CAN FIX 284 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
55+
+PHPCBF CAN FIX 290 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
5556
----------------------------------------------------------------------
5657

5758

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

@@ -78,7 +79,7 @@ index 59148a3..eb019d5 100644
7879
/** @var ControlStructureSniff|int|string|null */
7980
private $baxBax;
8081
diff --git a/tests/fixed/type-hints.php b/tests/fixed/type-hints.php
81-
index a1b1827..fb7d406 100644
82+
index 0e952fc..9824fb0 100644
8283
--- a/tests/fixed/type-hints.php
8384
+++ b/tests/fixed/type-hints.php
8485
@@ -10,7 +10,7 @@ use Traversable;

0 commit comments

Comments
 (0)