Skip to content

Commit 03de28b

Browse files
committed
Add rule to ensure Arrow Functions declaration format
1 parent c665bae commit 03de28b

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

lib/Doctrine/ruleset.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@
267267
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch"/>
268268
<!-- Require using Throwable instead of Exception -->
269269
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
270+
<!-- Ensure Arrow Functions declaration format 9 -->
271+
<rule ref="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration">
272+
<properties>
273+
<property name="spacesCountAfterKeyword" value="1"/>
274+
<property name="spacesCountBeforeArrow" value="1"/>
275+
<property name="spacesCountAfterArrow" value="1"/>
276+
</properties>
277+
</rule>
270278
<!-- Require closures not referencing $this be static -->
271279
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/>
272280
<!-- Forbid unused variables passed to closures via `use` -->
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$missingStatic = static fn ($a, $b) => $a + $b;
6+
7+
$uselessParentheses = static fn ($x) => $x + $y;
8+
9+
$withReturnType = static fn (): int => 1 + 2;
10+
11+
$withTypesInArguments = static fn (int $a, int $b): int => $a + $b;
12+
13+
$spacing = static fn (int $x) => $x * 2;
14+
15+
$nested = static fn ($x) => static fn ($y) => $x * $y + $z;
16+
17+
$returningObject = static fn () => new stdClass();
18+
19+
Collection::from([1, 2])
20+
->map(static fn (int $v): int => $v * 2)
21+
->reduce(static fn (int $tmp, int $v): int => $tmp + $v, 0);
22+
23+
$thisIsNotAnArrowFunction = [$this->fn => 'value'];
24+
25+
$arrayWithArrowFunctions = [
26+
'true' => static fn () => true,
27+
'false' => static fn () => false,
28+
];
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$missingStatic = fn ($a, $b) => $a + $b;
6+
7+
$uselessParentheses = static fn ($x) => ($x + $y);
8+
9+
$withReturnType = static fn () : int => 1 + 2;
10+
11+
$withTypesInArguments = static fn (int $a , int $b): int => $a + $b;
12+
13+
$spacing = static fn(int $x) => $x * 2;
14+
15+
$nested = static fn ($x)=>static fn ($y) => $x * $y + $z;
16+
17+
$returningObject = static fn () => new stdClass();
18+
19+
Collection::from([1, 2])
20+
->map(static fn (int $v): int => $v * 2)
21+
->reduce(static fn (int $tmp, int $v): int => $tmp + $v, 0);
22+
23+
$thisIsNotAnArrowFunction = [$this->fn => 'value'];
24+
25+
$arrayWithArrowFunctions = [
26+
'true' => static fn () => true,
27+
'false' => static fn () => false,
28+
];

0 commit comments

Comments
 (0)