Skip to content

Commit 27a2342

Browse files
authored
Merge pull request #270 from simPod/traling
2 parents cd23eb3 + 87fa8be commit 27a2342

File tree

9 files changed

+485
-26
lines changed

9 files changed

+485
-26
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ jobs:
130130
matrix:
131131
php-version:
132132
- "7.2"
133+
- "7.3"
133134
- "7.4"
134135
- "8.0"
135136
- "8.1"

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ test-report: vendor
88
test-fix: vendor
99
./bin/test-fix
1010

11+
update-compatibility-patch-73:
12+
@git apply tests/php73-compatibility.patch
13+
@printf "Please open your editor and apply your changes\n"
14+
@until [ "$${compatibility_resolved}" == "y" ]; do read -p "Have finished your changes (y|n)? " compatibility_resolved; done && compatibility_resolved=
15+
@git diff -- tests/expected_report.txt tests/fixed tests/input > .tmp-patch && mv .tmp-patch tests/php73-compatibility.patch && git apply -R tests/php73-compatibility.patch
16+
@git commit -m 'Update compatibility patch' tests/php73-compatibility.patch
17+
1118
update-compatibility-patch-74:
1219
@git apply tests/php74-compatibility.patch
1320
@printf "Please open your editor and apply your changes\n"

lib/Doctrine/ruleset.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,28 @@
291291
<property name="spacesCountAfterArrow" value="1"/>
292292
</properties>
293293
</rule>
294+
<!-- Disallow trailing commas in single line function calls -->
295+
<rule ref="SlevomatCodingStandard.Functions.DisallowTrailingCommaInCall">
296+
<properties>
297+
<property name="onlySingleLine" value="true" />
298+
</properties>
299+
</rule>
300+
<!-- Disallow trailing commas in single line closure use -->
301+
<rule ref="SlevomatCodingStandard.Functions.DisallowTrailingCommaInClosureUse">
302+
<properties>
303+
<property name="onlySingleLine" value="true" />
304+
</properties>
305+
</rule>
294306
<!-- Disallow trailing commas in single line function declarations -->
295307
<rule ref="SlevomatCodingStandard.Functions.DisallowTrailingCommaInDeclaration">
296308
<properties>
297309
<property name="onlySingleLine" value="true" />
298310
</properties>
299311
</rule>
312+
<!-- Require trailing commas in multiline function calls -->
313+
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
314+
<!-- Require trailing commas in multiline closure use -->
315+
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInClosureUse"/>
300316
<!-- Require trailing commas in multiline function declarations -->
301317
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
302318
<!-- Require closures not referencing $this be static -->

tests/fixed/TrailingCommaOnFunctions.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
namespace Doctrine;
66

7+
use function var_dump;
8+
9+
// phpcs:disable PSR1.Files.SideEffects
10+
711
class TrailingCommaOnFunctions
812
{
913
public function a(int $arg): void
@@ -14,4 +18,27 @@ public function b(
1418
int $arg
1519
): void {
1620
}
21+
22+
public function uses(): void
23+
{
24+
$var = null;
25+
26+
$singleLine = static function (int $arg) use ($var): void {
27+
var_dump($var);
28+
};
29+
30+
$multiLine = static function (int $arg) use (
31+
$var
32+
): void {
33+
var_dump($var);
34+
};
35+
}
1736
}
37+
38+
$class = new TrailingCommaOnFunctions();
39+
40+
$class->a(1);
41+
42+
$class->a(
43+
1
44+
);

tests/input/TrailingCommaOnFunctions.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
namespace Doctrine;
66

7+
use function var_dump;
8+
9+
// phpcs:disable PSR1.Files.SideEffects
10+
711
class TrailingCommaOnFunctions
812
{
913
public function a(int $arg): void
@@ -14,4 +18,27 @@ public function b(
1418
int $arg
1519
): void {
1620
}
21+
22+
public function uses(): void
23+
{
24+
$var = null;
25+
26+
$singleLine = static function (int $arg) use ($var): void {
27+
var_dump($var);
28+
};
29+
30+
$multiLine = static function (int $arg) use (
31+
$var
32+
): void {
33+
var_dump($var);
34+
};
35+
}
1736
}
37+
38+
$class = new TrailingCommaOnFunctions();
39+
40+
$class->a(1);
41+
42+
$class->a(
43+
1
44+
);

tests/php73-compatibility.patch

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
2+
index 1d5a7d3..fae9e70 100644
3+
--- a/tests/expected_report.txt
4+
+++ b/tests/expected_report.txt
5+
@@ -39,6 +39,7 @@ tests/input/strings.php 1 0
6+
tests/input/superfluous-naming.php 11 0
7+
tests/input/test-case.php 8 0
8+
tests/input/trailing_comma_on_array.php 1 0
9+
+tests/input/TrailingCommaOnFunctions.php 2 0
10+
tests/input/traits-uses.php 11 0
11+
tests/input/type-hints.php 7 0
12+
tests/input/UnusedVariables.php 1 0
13+
@@ -46,9 +47,9 @@ tests/input/use-ordering.php 1 0
14+
tests/input/useless-semicolon.php 2 0
15+
tests/input/UselessConditions.php 20 0
16+
----------------------------------------------------------------------
17+
-A TOTAL OF 381 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
18+
+A TOTAL OF 383 ERRORS AND 0 WARNINGS WERE FOUND IN 43 FILES
19+
----------------------------------------------------------------------
20+
-PHPCBF CAN FIX 315 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
21+
+PHPCBF CAN FIX 317 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
22+
----------------------------------------------------------------------
23+
24+
25+
diff --git a/tests/fixed/TrailingCommaOnFunctions.php b/tests/fixed/TrailingCommaOnFunctions.php
26+
index f3ffa91..67173b3 100644
27+
--- a/tests/fixed/TrailingCommaOnFunctions.php
28+
+++ b/tests/fixed/TrailingCommaOnFunctions.php
29+
@@ -37,8 +37,9 @@ class TrailingCommaOnFunctions
30+
31+
$class = new TrailingCommaOnFunctions();
32+
33+
+// phpcs:ignore Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma
34+
$class->a(1);
35+
36+
$class->a(
37+
- 1
38+
+ 1,
39+
);
40+
diff --git a/tests/fixed/arrow-functions-format.php b/tests/fixed/arrow-functions-format.php
41+
index a45074f..4da39b8 100644
42+
--- a/tests/fixed/arrow-functions-format.php
43+
+++ b/tests/fixed/arrow-functions-format.php
44+
@@ -18,10 +18,10 @@ $returningObject = static fn () => new stdClass();
45+
46+
$multiLineArrowFunctions = Collection::from([1, 2])
47+
->map(
48+
- static fn (int $v): int => $v * 2
49+
+ static fn (int $v): int => $v * 2,
50+
)
51+
->reduce(
52+
- static fn (int $tmp, int $v): int => $tmp + $v
53+
+ static fn (int $tmp, int $v): int => $tmp + $v,
54+
);
55+
56+
$thisIsNotAnArrowFunction = [$this->fn => 'value'];
57+
diff --git a/tests/fixed/namespaces-spacing.php b/tests/fixed/namespaces-spacing.php
58+
index d42bbfe..36cbae2 100644
59+
--- a/tests/fixed/namespaces-spacing.php
60+
+++ b/tests/fixed/namespaces-spacing.php
61+
@@ -16,5 +16,5 @@ use const DATE_RFC3339;
62+
strrev(
63+
(new DateTimeImmutable('@' . time(), new DateTimeZone('UTC')))
64+
->sub(new DateInterval('P1D'))
65+
- ->format(DATE_RFC3339)
66+
+ ->format(DATE_RFC3339),
67+
);
68+
diff --git a/tests/input/TrailingCommaOnFunctions.php b/tests/input/TrailingCommaOnFunctions.php
69+
index f3ffa91..8adcedf 100644
70+
--- a/tests/input/TrailingCommaOnFunctions.php
71+
+++ b/tests/input/TrailingCommaOnFunctions.php
72+
@@ -37,7 +37,8 @@ class TrailingCommaOnFunctions
73+
74+
$class = new TrailingCommaOnFunctions();
75+
76+
-$class->a(1);
77+
+// phpcs:ignore Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma
78+
+$class->a(1,);
79+
80+
$class->a(
81+
1
82+
diff --git a/tests/input/arrow-functions-format.php b/tests/input/arrow-functions-format.php
83+
index 8a358e8..d3903ff 100644
84+
--- a/tests/input/arrow-functions-format.php
85+
+++ b/tests/input/arrow-functions-format.php
86+
@@ -18,10 +18,10 @@ $returningObject = static fn () => new stdClass();
87+
88+
$multiLineArrowFunctions = Collection::from([1, 2])
89+
->map(
90+
- static fn (int $v): int => $v * 2
91+
+ static fn (int $v): int => $v * 2,
92+
)
93+
->reduce(
94+
- static fn (int $tmp, int $v): int => $tmp + $v
95+
+ static fn (int $tmp, int $v): int => $tmp + $v,
96+
);
97+
98+
$thisIsNotAnArrowFunction = [$this->fn => 'value'];
99+
diff --git a/tests/input/namespaces-spacing.php b/tests/input/namespaces-spacing.php
100+
index e1ab639..e7be018 100644
101+
--- a/tests/input/namespaces-spacing.php
102+
+++ b/tests/input/namespaces-spacing.php
103+
@@ -11,5 +11,5 @@ use const DATE_RFC3339;
104+
strrev(
105+
(new DateTimeImmutable('@' . time(), new DateTimeZone('UTC')))
106+
->sub(new DateInterval('P1D'))
107+
- ->format(DATE_RFC3339)
108+
+ ->format(DATE_RFC3339),
109+
);

tests/php74-compatibility.patch

Lines changed: 90 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
2-
index c644926..7d122d2 100644
2+
index 1d5a7d3..91e97e7 100644
33
--- a/tests/expected_report.txt
44
+++ b/tests/expected_report.txt
55
@@ -15,7 +15,7 @@ tests/input/ControlStructures.php 28 0
@@ -23,14 +23,11 @@ index c644926..7d122d2 100644
2323
tests/input/null_coalesce_operator.php 3 0
2424
tests/input/optimized-functions.php 1 0
2525
tests/input/PropertyDeclaration.php 6 0
26-
@@ -35,20 +35,20 @@ tests/input/semicolon_spacing.php 3 0
27-
tests/input/single-line-array-spacing.php 5 0
28-
tests/input/spread-operator.php 6 0
29-
tests/input/static-closures.php 1 0
30-
tests/input/strings.php 1 0
26+
@@ -39,16 +39,17 @@ tests/input/strings.php 1 0
3127
tests/input/superfluous-naming.php 11 0
3228
tests/input/test-case.php 8 0
3329
tests/input/trailing_comma_on_array.php 1 0
30+
+tests/input/TrailingCommaOnFunctions.php 2 0
3431
tests/input/traits-uses.php 11 0
3532
-tests/input/type-hints.php 7 0
3633
+tests/input/type-hints.php 8 0
@@ -40,13 +37,45 @@ index c644926..7d122d2 100644
4037
tests/input/UselessConditions.php 20 0
4138
----------------------------------------------------------------------
4239
-A TOTAL OF 381 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
43-
+A TOTAL OF 390 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
40+
+A TOTAL OF 392 ERRORS AND 0 WARNINGS WERE FOUND IN 43 FILES
4441
----------------------------------------------------------------------
4542
-PHPCBF CAN FIX 315 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
46-
+PHPCBF CAN FIX 324 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
43+
+PHPCBF CAN FIX 326 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
4744
----------------------------------------------------------------------
4845

4946

47+
diff --git a/tests/fixed/TrailingCommaOnFunctions.php b/tests/fixed/TrailingCommaOnFunctions.php
48+
index f3ffa91..67173b3 100644
49+
--- a/tests/fixed/TrailingCommaOnFunctions.php
50+
+++ b/tests/fixed/TrailingCommaOnFunctions.php
51+
@@ -37,8 +37,9 @@ class TrailingCommaOnFunctions
52+
53+
$class = new TrailingCommaOnFunctions();
54+
55+
+// phpcs:ignore Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma
56+
$class->a(1);
57+
58+
$class->a(
59+
- 1
60+
+ 1,
61+
);
62+
diff --git a/tests/fixed/arrow-functions-format.php b/tests/fixed/arrow-functions-format.php
63+
index a45074f..4da39b8 100644
64+
--- a/tests/fixed/arrow-functions-format.php
65+
+++ b/tests/fixed/arrow-functions-format.php
66+
@@ -18,10 +18,10 @@ $returningObject = static fn () => new stdClass();
67+
68+
$multiLineArrowFunctions = Collection::from([1, 2])
69+
->map(
70+
- static fn (int $v): int => $v * 2
71+
+ static fn (int $v): int => $v * 2,
72+
)
73+
->reduce(
74+
- static fn (int $tmp, int $v): int => $tmp + $v
75+
+ static fn (int $tmp, int $v): int => $tmp + $v,
76+
);
77+
78+
$thisIsNotAnArrowFunction = [$this->fn => 'value'];
5079
diff --git a/tests/fixed/example-class.php b/tests/fixed/example-class.php
5180
index 998e51d..7866379 100644
5281
--- a/tests/fixed/example-class.php
@@ -69,6 +98,17 @@ index 998e51d..7866379 100644
6998

7099
/** @var ControlStructureSniff|int|string|null */
71100
private $baxBax;
101+
diff --git a/tests/fixed/namespaces-spacing.php b/tests/fixed/namespaces-spacing.php
102+
index d42bbfe..36cbae2 100644
103+
--- a/tests/fixed/namespaces-spacing.php
104+
+++ b/tests/fixed/namespaces-spacing.php
105+
@@ -16,5 +16,5 @@ use const DATE_RFC3339;
106+
strrev(
107+
(new DateTimeImmutable('@' . time(), new DateTimeZone('UTC')))
108+
->sub(new DateInterval('P1D'))
109+
- ->format(DATE_RFC3339)
110+
+ ->format(DATE_RFC3339),
111+
);
72112
diff --git a/tests/fixed/new_with_parentheses.php b/tests/fixed/new_with_parentheses.php
73113
index 6e81bbe..47a06ec 100644
74114
--- a/tests/fixed/new_with_parentheses.php
@@ -129,3 +169,45 @@ index 10e6f34..bfa6d4f 100644
129169

130170
/**
131171
* @param Iterator $iterator
172+
diff --git a/tests/input/TrailingCommaOnFunctions.php b/tests/input/TrailingCommaOnFunctions.php
173+
index f3ffa91..8adcedf 100644
174+
--- a/tests/input/TrailingCommaOnFunctions.php
175+
+++ b/tests/input/TrailingCommaOnFunctions.php
176+
@@ -37,7 +37,8 @@ class TrailingCommaOnFunctions
177+
178+
$class = new TrailingCommaOnFunctions();
179+
180+
-$class->a(1);
181+
+// phpcs:ignore Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma
182+
+$class->a(1,);
183+
184+
$class->a(
185+
1
186+
diff --git a/tests/input/arrow-functions-format.php b/tests/input/arrow-functions-format.php
187+
index 8a358e8..d3903ff 100644
188+
--- a/tests/input/arrow-functions-format.php
189+
+++ b/tests/input/arrow-functions-format.php
190+
@@ -18,10 +18,10 @@ $returningObject = static fn () => new stdClass();
191+
192+
$multiLineArrowFunctions = Collection::from([1, 2])
193+
->map(
194+
- static fn (int $v): int => $v * 2
195+
+ static fn (int $v): int => $v * 2,
196+
)
197+
->reduce(
198+
- static fn (int $tmp, int $v): int => $tmp + $v
199+
+ static fn (int $tmp, int $v): int => $tmp + $v,
200+
);
201+
202+
$thisIsNotAnArrowFunction = [$this->fn => 'value'];
203+
diff --git a/tests/input/namespaces-spacing.php b/tests/input/namespaces-spacing.php
204+
index e1ab639..e7be018 100644
205+
--- a/tests/input/namespaces-spacing.php
206+
+++ b/tests/input/namespaces-spacing.php
207+
@@ -11,5 +11,5 @@ use const DATE_RFC3339;
208+
strrev(
209+
(new DateTimeImmutable('@' . time(), new DateTimeZone('UTC')))
210+
->sub(new DateInterval('P1D'))
211+
- ->format(DATE_RFC3339)
212+
+ ->format(DATE_RFC3339),
213+
);

0 commit comments

Comments
 (0)