Skip to content

Commit 2c58176

Browse files
📦 Drop some supports
1 parent 0bddaa8 commit 2c58176

File tree

4 files changed

+40
-64
lines changed

4 files changed

+40
-64
lines changed

SymfonyCustom/Sniffs/NamingConventions/ValidTypeHintSniff.php

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ class ValidTypeHintSniff implements Sniff
1919
* <array> is array of <simple>, eg `int[]` or `\Foo[]`
2020
* <generic> is generic collection type, like `array<string, int>`, `Collection<Item>` or more complex`
2121
* <object> is array key => value type, like `array{type: string, name: string, value: mixed}`
22-
* <class-string> is Foo::class type, like `class-string` or `class-string<Foo>`
23-
* <type> is <simple>, <class-string>, <array>, <object> or <generic> type
22+
* <type> is <simple>, <array>, <object>, <generic> type
2423
* <types> is one or more types alternated via `|`, like `int|bool[]|Collection<ItemKey, ItemVal>`
2524
*/
2625
private const REGEX_TYPES = '
@@ -66,16 +65,6 @@ class ValidTypeHintSniff implements Sniff
6665
\s*}
6766
)
6867
|
69-
(?<classString>
70-
class-string(?:
71-
\s*<\s*
72-
(?<classStringContent>
73-
(?&simple)
74-
)
75-
\s*>
76-
)?
77-
)
78-
|
7968
(?<simple>
8069
\\\\?\w+(?:\\\\\w+)*
8170
|
@@ -89,28 +78,30 @@ class-string(?:
8978
)
9079
';
9180

92-
private const PRIMITIVES_TYPES = [
93-
'string',
94-
'int',
95-
'float',
96-
'bool',
97-
'array',
98-
'resource',
99-
'null',
100-
'callable',
101-
'iterable',
102-
];
103-
private const KEYWORD_TYPES = [
104-
'mixed',
105-
'void',
106-
'object',
107-
'number',
108-
'false',
109-
'true',
110-
'self',
111-
'static',
112-
'$this',
81+
/**
82+
* False if the type is not a reserved keyword and the check can't be case insensitive
83+
**/
84+
private const TYPES = [
85+
'array' => true,
86+
'bool' => true,
87+
'callable' => true,
88+
'false' => true,
89+
'float' => true,
90+
'int' => true,
91+
'iterable' => true,
92+
'mixed' => false,
93+
'null' => true,
94+
'number' => false,
95+
'object' => true,
96+
'resource' => false,
97+
'self' => true,
98+
'static' => true,
99+
'string' => true,
100+
'true' => true,
101+
'void' => true,
102+
'$this' => true,
113103
];
104+
114105
private const ALIAS_TYPES = [
115106
'boolean' => 'bool',
116107
'integer' => 'int',
@@ -198,8 +189,6 @@ private function getValidTypes(string $content): string
198189
$validType = $this->getValidGenericType($matches['genericName'], $matches['genericContent']);
199190
} elseif (isset($matches['object']) && '' !== $matches['object']) {
200191
$validType = $this->getValidObjectType($matches['objectContent']);
201-
} elseif (isset($matches['classString']) && '' !== $matches['classString']) {
202-
$validType = preg_replace('/class-string/i', 'class-string', $matches['classString']);
203192
} else {
204193
$validType = $this->getValidType($matches['type']);
205194
}
@@ -307,12 +296,13 @@ private function getValidObjectType(string $objectContent): string
307296
private function getValidType(string $typeName): string
308297
{
309298
$lowerType = strtolower($typeName);
310-
if (in_array($lowerType, self::PRIMITIVES_TYPES) || in_array($lowerType, self::KEYWORD_TYPES)) {
311-
return $lowerType;
299+
if (isset(self::TYPES[$lowerType])) {
300+
return self::TYPES[$lowerType] ? $lowerType : $typeName;
312301
}
313302

314-
if (isset(self::ALIAS_TYPES[$lowerType])) {
315-
return self::ALIAS_TYPES[$lowerType];
303+
// This can't be case insensitive since this is not reserved keyword
304+
if (isset(self::ALIAS_TYPES[$typeName])) {
305+
return self::ALIAS_TYPES[$typeName];
316306
}
317307

318308
return $typeName;

SymfonyCustom/Tests/NamingConventions/ValidTypeHintUnitTest.inc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
*/
1515

1616
/**
17-
* Don't care about case
17+
* Don't care about case for reserved keyword
1818
*
19-
* @return BoOlEAn $a
19+
* @return BOOL $a
2020
* @return boolean $a
21+
* @return Boolean $a
2122
*/
2223

2324
/**
@@ -51,13 +52,6 @@
5152
* @param array{foo: integer, bar: string}
5253
*/
5354

54-
/**
55-
* Class-string
56-
*
57-
* @param class-string|class-string<Client>|integer
58-
* @param class-STRING|cLass-stRIng<Client>|int
59-
*/
60-
6155
/**
6256
* Handle space (Last one is a comment, correctly not replaced)
6357
*

SymfonyCustom/Tests/NamingConventions/ValidTypeHintUnitTest.inc.fixed

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
*/
1515

1616
/**
17-
* Don't care about case
17+
* Don't care about case for reserved keyword
1818
*
1919
* @return bool $a
2020
* @return bool $a
21+
* @return Boolean $a
2122
*/
2223

2324
/**
@@ -51,13 +52,6 @@
5152
* @param array{foo: int, bar: string}
5253
*/
5354

54-
/**
55-
* Class-string
56-
*
57-
* @param class-string|class-string<Client>|int
58-
* @param class-string|class-string<Client>|int
59-
*/
60-
6155
/**
6256
* Handle space (Last one is a comment, correctly not replaced)
6357
*

SymfonyCustom/Tests/NamingConventions/ValidTypeHintUnitTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,27 @@ protected function getErrorList(): array
2626
13 => 1,
2727
19 => 1,
2828
20 => 1,
29-
26 => 1,
3029
27 => 1,
3130
28 => 1,
3231
29 => 1,
3332
30 => 1,
34-
36 => 1,
33+
31 => 1,
3534
37 => 1,
3635
38 => 1,
3736
39 => 1,
38-
45 => 1,
37+
40 => 1,
3938
46 => 1,
4039
47 => 1,
4140
48 => 1,
4241
49 => 1,
4342
50 => 1,
4443
51 => 1,
45-
57 => 1,
44+
52 => 1,
4645
58 => 1,
47-
64 => 1,
46+
59 => 1,
4847
65 => 1,
49-
71 => 1,
50-
72 => 1,
51-
73 => 1,
48+
66 => 1,
49+
67 => 1,
5250
];
5351
}
5452

0 commit comments

Comments
 (0)