You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: SymfonyCustom/Sniffs/NamingConventions/ValidTypeHintSniff.php
+94-21Lines changed: 94 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -17,31 +17,60 @@ class ValidTypeHintSniff implements Sniff
17
17
/**
18
18
* <simple> is any non-array, non-generic, non-alternated type, eg `int` or `\Foo`
19
19
* <array> is array of <simple>, eg `int[]` or `\Foo[]`
20
-
* <generic> is generic collection type, like `array<string, int>`, `Collection<Item>` and more complex like `Collection<int, \null|SubCollection<string>>`
21
-
* <type> is <simple>, <array> or <generic> type, like `int`, `bool[]` or `Collection<ItemKey, ItemVal>`
20
+
* <generic> is generic collection type, like `array<string, int>`, `Collection<Item>` or more complex`
21
+
* <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
24
* <types> is one or more types alternated via `|`, like `int|bool[]|Collection<ItemKey, ItemVal>`
23
25
*/
24
26
privateconstREGEX_TYPES = '
25
27
(?<types>
26
28
(?<type>
27
29
(?<generic>
28
-
(?<genericName>(?&simple))\s*
29
-
<\s*
30
-
(?:
31
-
(?<genericKey>(?&types))\s*
32
-
,\s*
33
-
)?
34
-
(?<genericValue>(?&types)|(?&generic))\s*
35
-
>
30
+
(?<genericName>
31
+
(?&simple)
32
+
)
33
+
\s*<\s*
34
+
(?<genericContent>
35
+
(?:(?&types)\s*,\s*)*
36
+
(?&types)
37
+
)
38
+
\s*>
36
39
)
37
40
|
38
-
(?<array>(?&simple)(\s*\[\s*\])+)
41
+
(?<object>
42
+
array\s*{\s*
43
+
(?<objectContent>
44
+
(?:
45
+
(?<objectKeyValue>
46
+
(?:\w+\s*\??:\s*)?
47
+
(?&types)
48
+
)
49
+
\s*,\s*
50
+
)*
51
+
(?&objectKeyValue)
52
+
)
53
+
\s*}
54
+
)
55
+
|
56
+
(?<array>
57
+
(?&simple)(?:
58
+
\s*\[\s*\]
59
+
)+
60
+
)
61
+
|
62
+
(?<classString>
63
+
class-string(?:
64
+
\s*<\s*[\\\\\w]+\s*>
65
+
)?
66
+
)
39
67
|
40
-
(?<simple>[@$?]?[\\\\\w]+)
68
+
(?<simple>
69
+
[@$?]?[\\\\\w]+
70
+
)
41
71
)
42
72
(?:
43
-
\s*\|\s*
44
-
(?:(?&generic)|(?&array)|(?&simple))
73
+
\s*\|\s*(?&type)
45
74
)*
46
75
)
47
76
';
@@ -98,17 +127,14 @@ private function getValidTypes(string $content): string
0 commit comments