@@ -19,50 +19,24 @@ final class TicketSwapErrorFormatter implements ErrorFormatter
19
19
private const LINK_FORMAT_PHPSTORM = "↳ file://{absolutePath}:{line} \n" ;
20
20
private const LINK_FORMAT_WITHOUT_EDITOR = "↳ {relativePath}:{line} \n" ;
21
21
22
- /**
23
- * @var string
24
- */
25
- private $ linkFormat ;
26
-
27
- /**
28
- * @var RelativePathHelper
29
- */
30
- private $ relativePathHelper ;
31
-
32
- /**
33
- * @var CiDetectedErrorFormatter
34
- */
35
- private $ ciDetectedErrorFormatter ;
36
-
37
- /**
38
- * @var string|null
39
- */
40
- private $ editorUrl ;
22
+ private string $ linkFormat ;
41
23
42
24
public function __construct (
43
- RelativePathHelper $ relativePathHelper ,
44
- CiDetectedErrorFormatter $ ciDetectedErrorFormatter ,
45
- ?string $ editorUrl = null
25
+ private readonly RelativePathHelper $ relativePathHelper ,
26
+ private readonly CiDetectedErrorFormatter $ ciDetectedErrorFormatter ,
27
+ private readonly ?string $ editorUrl,
46
28
) {
47
- $ this ->editorUrl = $ editorUrl ;
48
- $ this ->ciDetectedErrorFormatter = $ ciDetectedErrorFormatter ;
49
- $ this ->relativePathHelper = $ relativePathHelper ;
50
29
$ this ->linkFormat = self ::getLinkFormatFromEnv ();
51
30
}
52
31
53
32
public static function getLinkFormatFromEnv () : string
54
33
{
55
- if (getenv ('GITHUB_ACTIONS ' ) !== false ) {
56
- return self ::LINK_FORMAT_GITHUB_ACTIONS ;
57
- }
58
- if (getenv ('TERMINAL_EMULATOR ' ) !== 'JetBrains-JediTerm ' ) {
59
- return self ::LINK_FORMAT_PHPSTORM ;
60
- }
61
- if (getenv ('TERM_PROGRAM ' ) !== 'WarpTerminal ' ) {
62
- return self ::LINK_FORMAT_WARP ;
63
- }
64
-
65
- return self ::LINK_FORMAT_DEFAULT ;
34
+ return match (true ) {
35
+ getenv ('GITHUB_ACTIONS ' ) !== false => self ::LINK_FORMAT_GITHUB_ACTIONS ,
36
+ getenv ('TERMINAL_EMULATOR ' ) === 'JetBrains-JediTerm ' => self ::LINK_FORMAT_PHPSTORM ,
37
+ getenv ('TERM_PROGRAM ' ) === 'WarpTerminal ' => self ::LINK_FORMAT_WARP ,
38
+ default => self ::LINK_FORMAT_DEFAULT ,
39
+ };
66
40
}
67
41
68
42
public function formatErrors (AnalysisResult $ analysisResult , Output $ output ) : int
@@ -78,7 +52,7 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output) : i
78
52
$ output ->writeLineFormatted (
79
53
sprintf (
80
54
'<unknown location> %s ' ,
81
- $ notFileSpecificError
55
+ $ notFileSpecificError,
82
56
)
83
57
);
84
58
}
@@ -101,7 +75,7 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output) : i
101
75
$ error ->getTip ()
102
76
) : null ,
103
77
$ error ->getIdentifier (),
104
- $ output ->isDecorated ()
78
+ $ output ->isDecorated (),
105
79
),
106
80
'{identifier} ' => $ error ->getIdentifier (),
107
81
'{links} ' => implode ([
@@ -111,19 +85,19 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output) : i
111
85
$ error ->getFilePath (),
112
86
$ this ->relativePathHelper ->getRelativePath ($ error ->getFilePath ()),
113
87
$ this ->editorUrl ,
114
- $ output ->isDecorated ()
88
+ $ output ->isDecorated (),
115
89
),
116
90
$ error ->getTraitFilePath () !== null ? $ this ::link (
117
91
$ this ->linkFormat ,
118
92
(int ) $ error ->getLine (),
119
93
$ error ->getTraitFilePath (),
120
94
$ this ->relativePathHelper ->getRelativePath ($ error ->getTraitFilePath ()),
121
95
$ this ->editorUrl ,
122
- $ output ->isDecorated ()
96
+ $ output ->isDecorated (),
123
97
) : '' ,
124
98
]),
125
- ]
126
- )
99
+ ],
100
+ ),
127
101
);
128
102
}
129
103
@@ -136,7 +110,7 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output) : i
136
110
sprintf (
137
111
'<bg=red;options=bold>Found %d error%s</> ' ,
138
112
$ analysisResult ->getTotalErrorsCount (),
139
- $ analysisResult ->getTotalErrorsCount () === 1 ? '' : 's '
113
+ $ analysisResult ->getTotalErrorsCount () === 1 ? '' : 's ' ,
140
114
)
141
115
);
142
116
$ output ->writeLineFormatted ('' );
@@ -152,7 +126,7 @@ public static function link(
152
126
string $ absolutePath ,
153
127
string $ relativePath ,
154
128
?string $ editorUrl ,
155
- bool $ isDecorated
129
+ bool $ isDecorated,
156
130
) : string {
157
131
if (!$ isDecorated || $ editorUrl === null ) {
158
132
$ format = self ::LINK_FORMAT_WITHOUT_EDITOR ;
@@ -165,12 +139,12 @@ public static function link(
165
139
'{editorUrl} ' => $ editorUrl === null ? '' : str_replace (
166
140
['%relFile% ' , '%file% ' , '%line% ' ],
167
141
[$ relativePath , $ absolutePath , $ line ],
168
- $ editorUrl
142
+ $ editorUrl,
169
143
),
170
144
'{relativePath} ' => $ relativePath ,
171
145
'{shortPath} ' => self ::trimPath ($ relativePath ),
172
146
'{line} ' => $ line ,
173
- ]
147
+ ],
174
148
);
175
149
}
176
150
@@ -183,11 +157,11 @@ private static function trimPath(string $path) : string
183
157
184
158
return implode (
185
159
DIRECTORY_SEPARATOR ,
186
- array_merge (
187
- array_slice ($ parts , 0 , 3 ),
188
- [ '... ' ] ,
189
- array_slice ($ parts , -2 )
190
- )
160
+ [
161
+ ... array_slice ($ parts , 0 , 3 ),
162
+ '... ' ,
163
+ ... array_slice ($ parts , -2 ),
164
+ ],
191
165
);
192
166
}
193
167
@@ -197,7 +171,7 @@ public static function highlight(string $message, ?string $tip, ?string $identif
197
171
return $ message ;
198
172
}
199
173
200
- if (strpos ($ message , 'Ignored error pattern ' ) === 0 ) {
174
+ if (str_starts_with ($ message , 'Ignored error pattern ' )) {
201
175
return $ message ;
202
176
}
203
177
@@ -208,42 +182,42 @@ public static function highlight(string $message, ?string $tip, ?string $identif
208
182
$ message = (string ) preg_replace (
209
183
"/([A-Z0-9]{1}[A-Za-z0-9_\-]+[ \\\]+[A-Z0-9]{1}[A-Za-z0-9_\- \\\]+)/ " ,
210
184
'<fg=yellow>$1</> ' ,
211
- $ message
185
+ $ message,
212
186
);
213
187
214
188
// Quoted strings
215
189
$ message = (string ) preg_replace (
216
190
"/(?<=[ \"'])([A-Za-z0-9_\- \\\]+)(?=[ \"'])/ " ,
217
191
'<fg=yellow>$1</> ' ,
218
- $ message
192
+ $ message,
219
193
);
220
194
221
195
// Variable
222
196
$ message = (string ) preg_replace (
223
197
"/(?<=[:]{2}|[\s \"\(])([.]{3})?( \\$[A-Za-z0-9_ \\-]+)(?=[\s| \"|\)]|$)/ " ,
224
198
'<fg=green>$1$2</> ' ,
225
- $ message
199
+ $ message,
226
200
);
227
201
228
202
// Method
229
203
$ message = (string ) preg_replace (
230
204
'/(?<=[:]{2}|[\s])(\w+\(\))/ ' ,
231
205
'<fg=blue>$1</> ' ,
232
- $ message
206
+ $ message,
233
207
);
234
208
235
209
// Function
236
210
$ message = (string ) preg_replace (
237
211
'/(?<=function\s)(\w+)(?=\s)/ ' ,
238
212
'<fg=blue>$1</> ' ,
239
- $ message
213
+ $ message,
240
214
);
241
215
242
216
// Types
243
217
$ message = (string ) preg_replace (
244
218
'/(?<=[\s\|\(><])(null|true|false|int|float|bool|([-\w]+-)?string|array|object|mixed|resource|iterable|void|callable)(?=[:]{2}|[\.\s\|><,\(\)\{\}]+)/ ' ,
245
219
'<fg=magenta>$1</> ' ,
246
- $ message
220
+ $ message,
247
221
);
248
222
249
223
if ($ tip !== null ) {
0 commit comments