Skip to content

Commit 6f90b62

Browse files
✨ null at last
1 parent 606c99d commit 6f90b62

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

SymfonyCustom/Sniffs/NamingConventions/ValidTypeHintSniff.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ private function getValidTypes(string $content): string
141141
$types[$index] = $validType;
142142
}
143143

144+
$types = array_unique($types);
145+
usort($types, function ($type1, $type2) {
146+
if ('null' === $type1) {
147+
return 1;
148+
}
149+
150+
if ('null' === $type2) {
151+
return -1;
152+
}
153+
154+
return 0;
155+
});
156+
144157
return implode('|', $types);
145158
}
146159

SymfonyCustom/Tests/NamingConventions/ValidTypeHintUnitTest.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ echo ( float ) $a;
4545
/** @method integer|string */
4646
/** @method array<integer,boolean>|integer[]|array<integer> truc */
4747
/** @method array<integer, boolean|null>|integer[]|array<array<integer>> truc */
48+
49+
/**
50+
* @return null|int
51+
* @return string[]|null|int[]
52+
* @return Foo<integer|null|string, boolean|null|string>|null|int[]
53+
*/

SymfonyCustom/Tests/NamingConventions/ValidTypeHintUnitTest.inc.fixed

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ echo ( float ) $a;
4545
/** @method int|string */
4646
/** @method array<int, bool>|int[]|array<int> truc */
4747
/** @method array<int, bool|null>|int[]|array<array<int>> truc */
48+
49+
/**
50+
* @return int|null
51+
* @return string[]|int[]|null
52+
* @return Foo<int|string|null, bool|string|null>|int[]|null
53+
*/

SymfonyCustom/Tests/NamingConventions/ValidTypeHintUnitTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ protected function getErrorList(): array
3737
45 => 1,
3838
46 => 1,
3939
47 => 1,
40+
50 => 1,
41+
51 => 1,
42+
52 => 1,
4043
];
4144
}
4245

0 commit comments

Comments
 (0)