Skip to content

Commit 099b00e

Browse files
committed
feat(rules): format DNF types in doc comments
1 parent 63d03ff commit 099b00e

9 files changed

Lines changed: 49 additions & 33 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"require": {
2525
"php": "^7.4 || ^8.0",
2626
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0.0",
27-
"slevomat/coding-standard": "^8.28",
27+
"slevomat/coding-standard": "^8.29",
2828
"squizlabs/php_codesniffer": "^4"
2929
},
3030
"config": {

lib/Doctrine/ruleset.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@
503503
<property name="withSpacesInsideParentheses" value="no" />
504504
<property name="shortNullable" value="no" />
505505
<property name="nullPosition" value="last" />
506+
<property name="enableForDocComments" value="true" />
506507
</properties>
507508
</rule>
508509
<!-- Forbid useless @var for constants -->

tests/expected_report.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ tests/input/ControlStructures.php 27 0
1919
tests/input/doc-comment-spacing.php 11 0
2020
tests/input/duplicate-assignment-variable.php 1 0
2121
tests/input/EarlyReturn.php 8 0
22-
tests/input/example-class.php 48 0
22+
tests/input/example-class.php 49 0
2323
tests/input/ExampleBackedEnum.php 5 0
2424
tests/input/Exceptions.php 1 0
2525
tests/input/forbidden-comments.php 14 0
@@ -50,15 +50,15 @@ tests/input/test-case.php 8 0
5050
tests/input/trailing_comma_on_array.php 1 0
5151
tests/input/TrailingCommaOnFunctions.php 6 0
5252
tests/input/traits-uses.php 12 0
53-
tests/input/type-hints.php 9 0
53+
tests/input/type-hints.php 12 0
5454
tests/input/UnusedVariables.php 1 0
5555
tests/input/use-ordering.php 2 0
5656
tests/input/useless-semicolon.php 2 0
5757
tests/input/UselessConditions.php 21 0
5858
----------------------------------------------------------------------
59-
A TOTAL OF 482 ERRORS AND 2 WARNINGS WERE FOUND IN 52 FILES
59+
A TOTAL OF 486 ERRORS AND 2 WARNINGS WERE FOUND IN 52 FILES
6060
----------------------------------------------------------------------
61-
PHPCBF CAN FIX 396 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
61+
PHPCBF CAN FIX 400 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
6262
----------------------------------------------------------------------
6363

6464

tests/fixed/type-hints.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ public function get(Iterator $iterator): Traversable
2626
class UnionTypeHints
2727
{
2828
private int|string|null $x = 1;
29+
30+
/** @param array<int|string|null> $value */
31+
public function set(array $value): void
32+
{
33+
}
2934
}

tests/input/type-hints.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,9 @@ class UnionTypeHints
2727
{
2828
/** @var null|int|string */
2929
private $x = 1;
30+
31+
/** @param array<null|int|string> $value */
32+
public function set(array $value): void
33+
{
34+
}
3035
}

tests/php74-compatibility.patch

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ index 8547171..f01ece0 100644
1313
tests/input/doc-comment-spacing.php 11 0
1414
tests/input/duplicate-assignment-variable.php 1 0
1515
-tests/input/EarlyReturn.php 8 0
16-
-tests/input/example-class.php 48 0
16+
-tests/input/example-class.php 49 0
1717
-tests/input/ExampleBackedEnum.php 5 0
1818
-tests/input/Exceptions.php 1 0
1919
+tests/input/EarlyReturn.php 7 0
@@ -49,19 +49,19 @@ index 8547171..f01ece0 100644
4949
-tests/input/TrailingCommaOnFunctions.php 6 0
5050
+tests/input/TrailingCommaOnFunctions.php 2 0
5151
tests/input/traits-uses.php 12 0
52-
-tests/input/type-hints.php 9 0
53-
+tests/input/type-hints.php 8 0
52+
-tests/input/type-hints.php 12 0
53+
+tests/input/type-hints.php 9 0
5454
tests/input/UnusedVariables.php 1 0
5555
tests/input/use-ordering.php 2 0
5656
tests/input/useless-semicolon.php 2 0
5757
-tests/input/UselessConditions.php 21 0
5858
+tests/input/UselessConditions.php 20 0
5959
----------------------------------------------------------------------
60-
-A TOTAL OF 482 ERRORS AND 2 WARNINGS WERE FOUND IN 52 FILES
61-
+A TOTAL OF 434 ERRORS AND 2 WARNINGS WERE FOUND IN 48 FILES
60+
-A TOTAL OF 486 ERRORS AND 2 WARNINGS WERE FOUND IN 52 FILES
61+
+A TOTAL OF 435 ERRORS AND 2 WARNINGS WERE FOUND IN 48 FILES
6262
----------------------------------------------------------------------
63-
-PHPCBF CAN FIX 396 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
64-
+PHPCBF CAN FIX 349 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
63+
-PHPCBF CAN FIX 400 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
64+
+PHPCBF CAN FIX 350 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
6565
----------------------------------------------------------------------
6666
diff --git a/tests/fixed/ClassKeywordOrder.php b/tests/fixed/ClassKeywordOrder.php
6767
index 29f6164..4b28352 100644
@@ -409,14 +409,19 @@ diff --git a/tests/fixed/type-hints.php b/tests/fixed/type-hints.php
409409
index 5e26ed8..bfa6d4f 100644
410410
--- a/tests/fixed/type-hints.php
411411
+++ b/tests/fixed/type-hints.php
412-
@@ -25,5 +25,6 @@ class TraversableTypeHints
413-
412+
@@ -26,7 +26,8 @@
414413
class UnionTypeHints
415414
{
416415
- private int|string|null $x = 1;
416+
-
417+
- /** @param array<int|string|null> $value */
418+
- public function set(array $value): void
417419
+ /** @var int|string|null */
418420
+ private $x = 1;
419-
}
421+
+
422+
+ /** @param array<int|string|null> $value */
423+
+ public function set(array $value): void
424+
{
420425
diff --git a/tests/input/ControlStructures.php b/tests/input/ControlStructures.php
421426
index 7c20d0e..a0e0b2e 100644
422427
--- a/tests/input/ControlStructures.php

tests/php80-compatibility.patch

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ index 9b19b9e..760ee4a 100644
1313
tests/input/doc-comment-spacing.php 11 0
1414
tests/input/duplicate-assignment-variable.php 1 0
1515
tests/input/EarlyReturn.php 8 0
16-
-tests/input/example-class.php 48 0
16+
-tests/input/example-class.php 49 0
1717
-tests/input/ExampleBackedEnum.php 5 0
18-
+tests/input/example-class.php 47 0
18+
+tests/input/example-class.php 48 0
1919
tests/input/Exceptions.php 1 0
2020
tests/input/forbidden-comments.php 14 0
2121
tests/input/forbidden-functions.php 6 0
@@ -33,11 +33,11 @@ index 9b19b9e..760ee4a 100644
3333
tests/input/useless-semicolon.php 2 0
3434
tests/input/UselessConditions.php 21 0
3535
----------------------------------------------------------------------
36-
-A TOTAL OF 482 ERRORS AND 2 WARNINGS WERE FOUND IN 52 FILES
37-
+A TOTAL OF 464 ERRORS AND 2 WARNINGS WERE FOUND IN 50 FILES
36+
-A TOTAL OF 486 ERRORS AND 2 WARNINGS WERE FOUND IN 52 FILES
37+
+A TOTAL OF 468 ERRORS AND 2 WARNINGS WERE FOUND IN 50 FILES
3838
----------------------------------------------------------------------
39-
-PHPCBF CAN FIX 396 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
40-
+PHPCBF CAN FIX 379 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
39+
-PHPCBF CAN FIX 400 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
40+
+PHPCBF CAN FIX 383 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
4141
----------------------------------------------------------------------
4242
diff --git a/tests/fixed/ClassKeywordOrder.php b/tests/fixed/ClassKeywordOrder.php
4343
index 29f6164..4b28352 100644

tests/php81-compatibility.patch

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ index 8547171..a7a42fa 100644
1313
tests/input/doc-comment-spacing.php 11 0
1414
tests/input/duplicate-assignment-variable.php 1 0
1515
tests/input/EarlyReturn.php 8 0
16-
-tests/input/example-class.php 48 0
17-
+tests/input/example-class.php 47 0
16+
-tests/input/example-class.php 49 0
17+
+tests/input/example-class.php 48 0
1818
tests/input/ExampleBackedEnum.php 5 0
1919
tests/input/Exceptions.php 1 0
2020
tests/input/forbidden-comments.php 14 0
2121
@@ -55,7 +54,7 @@ tests/input/use-ordering.php 1 0
2222
tests/input/useless-semicolon.php 2 0
2323
tests/input/UselessConditions.php 21 0
2424
----------------------------------------------------------------------
25-
-A TOTAL OF 482 ERRORS AND 2 WARNINGS WERE FOUND IN 52 FILES
26-
+A TOTAL OF 474 ERRORS AND 2 WARNINGS WERE FOUND IN 51 FILES
25+
-A TOTAL OF 486 ERRORS AND 2 WARNINGS WERE FOUND IN 52 FILES
26+
+A TOTAL OF 478 ERRORS AND 2 WARNINGS WERE FOUND IN 51 FILES
2727
----------------------------------------------------------------------
28-
-PHPCBF CAN FIX 396 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
29-
+PHPCBF CAN FIX 389 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
28+
-PHPCBF CAN FIX 400 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
29+
+PHPCBF CAN FIX 393 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
3030
----------------------------------------------------------------------
3131
diff --git a/tests/fixed/ClassKeywordOrder.php b/tests/fixed/ClassKeywordOrder.php
3232
index 29f6164..4b28352 100644

tests/php82-compatibility.patch

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ index 8547171..a7a42fa 100644
1313
tests/input/doc-comment-spacing.php 11 0
1414
tests/input/duplicate-assignment-variable.php 1 0
1515
tests/input/EarlyReturn.php 8 0
16-
-tests/input/example-class.php 48 0
17-
+tests/input/example-class.php 47 0
16+
-tests/input/example-class.php 49 0
17+
+tests/input/example-class.php 48 0
1818
tests/input/ExampleBackedEnum.php 5 0
1919
tests/input/Exceptions.php 1 0
2020
tests/input/forbidden-comments.php 14 0
2121
@@ -55,7 +55,7 @@ tests/input/use-ordering.php 2 0
2222
tests/input/useless-semicolon.php 2 0
2323
tests/input/UselessConditions.php 21 0
2424
----------------------------------------------------------------------
25-
-A TOTAL OF 482 ERRORS AND 2 WARNINGS WERE FOUND IN 52 FILES
26-
+A TOTAL OF 475 ERRORS AND 2 WARNINGS WERE FOUND IN 52 FILES
25+
-A TOTAL OF 486 ERRORS AND 2 WARNINGS WERE FOUND IN 52 FILES
26+
+A TOTAL OF 479 ERRORS AND 2 WARNINGS WERE FOUND IN 52 FILES
2727
----------------------------------------------------------------------
28-
-PHPCBF CAN FIX 396 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
29-
+PHPCBF CAN FIX 390 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
28+
-PHPCBF CAN FIX 400 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
29+
+PHPCBF CAN FIX 394 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
3030
----------------------------------------------------------------------
3131
diff --git a/tests/fixed/constants-var.php b/tests/fixed/constants-var.php
3232
index f10c235..d4268cb 100644

0 commit comments

Comments
 (0)