Skip to content

Commit 8848a64

Browse files
committed
Generic/LowerCaseType: examine types in arrow function declarations
PHP 7.4 arrow functions were not yet being taken into account for this sniff. Fixed now. Includes unit tests.
1 parent 53e0f59 commit 8848a64

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

src/Standards/Generic/Sniffs/PHP/LowerCaseTypeSniff.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function register()
5252
$tokens = Tokens::$castTokens;
5353
$tokens[] = T_FUNCTION;
5454
$tokens[] = T_CLOSURE;
55+
$tokens[] = T_FN;
5556
$tokens[] = T_VARIABLE;
5657
return $tokens;
5758

src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,6 @@ function (): NeVeR {
8989
function intersectionParamTypes (\Package\ClassName&\Package\Other_Class $var) {}
9090

9191
function intersectionReturnTypes ($var): \Package\ClassName&\Package\Other_Class {}
92+
93+
$arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : int => $a * $b;
94+
$arrow = fn (Int $a, String $b, BOOL $c, Array $d, Foo\Bar $e) : Float => $a * $b;

src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.inc.fixed

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,6 @@ function (): never {
8989
function intersectionParamTypes (\Package\ClassName&\Package\Other_Class $var) {}
9090

9191
function intersectionReturnTypes ($var): \Package\ClassName&\Package\Other_Class {}
92+
93+
$arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : int => $a * $b;
94+
$arrow = fn (int $a, string $b, bool $c, array $d, Foo\Bar $e) : float => $a * $b;

src/Standards/Generic/Tests/PHP/LowerCaseTypeUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function getErrorList()
6666
78 => 3,
6767
82 => 2,
6868
85 => 1,
69+
94 => 5,
6970
];
7071

7172
}//end getErrorList()

0 commit comments

Comments
 (0)