Skip to content

Commit 6dd7c08

Browse files
📦 Drop some supports
1 parent 0bddaa8 commit 6dd7c08

File tree

4 files changed

+39
-62
lines changed

4 files changed

+39
-62
lines changed

SymfonyCustom/Sniffs/NamingConventions/ValidTypeHintSniff.php

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,6 @@ class ValidTypeHintSniff implements Sniff
6666
\s*}
6767
)
6868
|
69-
(?<classString>
70-
class-string(?:
71-
\s*<\s*
72-
(?<classStringContent>
73-
(?&simple)
74-
)
75-
\s*>
76-
)?
77-
)
78-
|
7969
(?<simple>
8070
\\\\?\w+(?:\\\\\w+)*
8171
|
@@ -89,28 +79,30 @@ class-string(?:
8979
)
9080
';
9181

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',
82+
/**
83+
* False if the type is not a reserved keyword and the check can't be case insensitive
84+
**/
85+
private const TYPES = [
86+
'array' => true,
87+
'bool' => true,
88+
'callable' => true,
89+
'false' => true,
90+
'float' => true,
91+
'int' => true,
92+
'iterable' => true,
93+
'mixed' => false,
94+
'null' => true,
95+
'number' => false,
96+
'object' => true,
97+
'resource' => false,
98+
'self' => true,
99+
'static' => true,
100+
'string' => true,
101+
'true' => true,
102+
'void' => true,
103+
'$this' => true,
113104
];
105+
114106
private const ALIAS_TYPES = [
115107
'boolean' => 'bool',
116108
'integer' => 'int',
@@ -198,8 +190,6 @@ private function getValidTypes(string $content): string
198190
$validType = $this->getValidGenericType($matches['genericName'], $matches['genericContent']);
199191
} elseif (isset($matches['object']) && '' !== $matches['object']) {
200192
$validType = $this->getValidObjectType($matches['objectContent']);
201-
} elseif (isset($matches['classString']) && '' !== $matches['classString']) {
202-
$validType = preg_replace('/class-string/i', 'class-string', $matches['classString']);
203193
} else {
204194
$validType = $this->getValidType($matches['type']);
205195
}
@@ -307,12 +297,13 @@ private function getValidObjectType(string $objectContent): string
307297
private function getValidType(string $typeName): string
308298
{
309299
$lowerType = strtolower($typeName);
310-
if (in_array($lowerType, self::PRIMITIVES_TYPES) || in_array($lowerType, self::KEYWORD_TYPES)) {
311-
return $lowerType;
300+
if (isset(self::TYPES[$lowerType])) {
301+
return self::TYPES[$lowerType] ? $lowerType : $typeName;
312302
}
313303

314-
if (isset(self::ALIAS_TYPES[$lowerType])) {
315-
return self::ALIAS_TYPES[$lowerType];
304+
// This can't be case insensitive
305+
if (isset(self::ALIAS_TYPES[$typeName])) {
306+
return self::ALIAS_TYPES[$typeName];
316307
}
317308

318309
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)