10
10
use Nette \Utils \Strings ;
11
11
use PHPStan \Command \AnalysisResult ;
12
12
use PHPStan \Command \ErrorFormatter \ErrorFormatter ;
13
- use Symfony \Component \Console \Style \OutputStyle ;
13
+ use PHPStan \Command \Output ;
14
+ use Safe \Exceptions \DirException ;
14
15
use Webmozart \PathUtil \Path ;
15
16
16
- class FileOutput implements ErrorFormatter
17
+ final class FileOutput implements ErrorFormatter
17
18
{
18
19
/** @var string */
19
20
public const ERROR = 'error ' ;
@@ -53,7 +54,7 @@ class FileOutput implements ErrorFormatter
53
54
54
55
/**
55
56
* FileOutput constructor.
56
- * @throws \Safe\Exceptions\ DirException
57
+ * @throws DirException
57
58
*/
58
59
public function __construct (string $ outputFile , ?ErrorFormatter $ defaultFormatterClass = null , ?string $ customTemplate = null )
59
60
{
@@ -78,28 +79,31 @@ public function __construct(string $outputFile, ?ErrorFormatter $defaultFormatte
78
79
* Formats the errors and outputs them to the console.
79
80
* @return int Error code.
80
81
*/
81
- public function formatErrors (AnalysisResult $ analysisResult , OutputStyle $ style ): int
82
+ public function formatErrors (AnalysisResult $ analysisResult , Output $ output ): int
82
83
{
83
84
if ($ this ->defaultFormatter !== null ) {
84
- $ this ->defaultFormatter ->formatErrors ($ analysisResult , $ style );
85
+ $ this ->defaultFormatter ->formatErrors ($ analysisResult , $ output );
85
86
}
86
87
try {
87
88
$ this ->generateFile ($ analysisResult );
88
- $ style -> writeln ('Note: Analysis outputted into file ' . $ this ->outputFile . '. ' );
89
+ $ output -> getStyle ()-> note ('Note: Analysis outputted into file ' . $ this ->outputFile . '. ' );
89
90
} catch (IOException $ e ) {
90
- $ style ->error ('Analysis could not be outputted into file. ' . $ e ->getMessage ());
91
+ $ output -> getStyle () ->error ('Analysis could not be outputted into file. ' . $ e ->getMessage ());
91
92
}
92
93
93
94
return $ analysisResult ->hasErrors () ? 1 : 0 ;
94
95
}
95
96
96
97
/**
97
98
* @param mixed[] $data
99
+ * @return string
98
100
*/
99
101
public function getTable (array $ data ): string
100
102
{
101
- ob_start (function (): void {
102
- });
103
+ ob_start (
104
+ static function (): void {
105
+ }
106
+ );
103
107
require $ this ->template ;
104
108
105
109
$ output = ob_get_clean ();
@@ -131,9 +135,12 @@ private function generateFile(AnalysisResult $analysisResult): void
131
135
}
132
136
133
137
foreach ($ output [self ::FILES ] as &$ file ) {
134
- usort ($ file , function ($ a , $ b ) {
135
- return -1 * ($ a [self ::LINE ] <=> $ b [self ::LINE ]);
136
- });
138
+ usort (
139
+ $ file ,
140
+ static function ($ a , $ b ) {
141
+ return -1 * ($ a [self ::LINE ] <=> $ b [self ::LINE ]);
142
+ }
143
+ );
137
144
}
138
145
unset($ file );
139
146
}
@@ -144,21 +151,23 @@ private function generateFile(AnalysisResult $analysisResult): void
144
151
private static function formatMessage (string $ message ): string
145
152
{
146
153
$ words = explode (' ' , $ message );
147
- $ words = array_map (function ($ word ) {
148
- if (Strings::match ($ word , '/[^a-zA-Z,.]|(string)|(bool)|(boolean)|(int)|(integer)|(float)/ ' )) {
149
- $ word = '<b> ' . $ word . '</b> ' ;
150
- }
154
+ $ words = array_map (
155
+ static function ($ word ) {
156
+ if (Strings::match ($ word , '/[^a-zA-Z,.]|(string)|(bool)|(boolean)|(int)|(integer)|(float)/ ' )) {
157
+ $ word = '<b> ' . $ word . '</b> ' ;
158
+ }
151
159
152
- return $ word ;
153
- }, $ words );
160
+ return $ word ;
161
+ },
162
+ $ words
163
+ );
154
164
155
165
return implode (' ' , $ words );
156
166
}
157
167
158
168
/**
159
169
* @param string $message
160
170
* @return string
161
- * @throws RegexpException
162
171
*/
163
172
private static function formatRegex (string $ message ): string
164
173
{
0 commit comments