1010use Nette \Utils \Strings ;
1111use PHPStan \Command \AnalysisResult ;
1212use PHPStan \Command \ErrorFormatter \ErrorFormatter ;
13- use Symfony \Component \Console \Style \OutputStyle ;
13+ use PHPStan \Command \Output ;
14+ use Safe \Exceptions \DirException ;
1415use Webmozart \PathUtil \Path ;
1516
16- class FileOutput implements ErrorFormatter
17+ final class FileOutput implements ErrorFormatter
1718{
1819 /** @var string */
1920 public const ERROR = 'error ' ;
@@ -53,7 +54,7 @@ class FileOutput implements ErrorFormatter
5354
5455 /**
5556 * FileOutput constructor.
56- * @throws \Safe\Exceptions\ DirException
57+ * @throws DirException
5758 */
5859 public function __construct (string $ outputFile , ?ErrorFormatter $ defaultFormatterClass = null , ?string $ customTemplate = null )
5960 {
@@ -78,28 +79,31 @@ public function __construct(string $outputFile, ?ErrorFormatter $defaultFormatte
7879 * Formats the errors and outputs them to the console.
7980 * @return int Error code.
8081 */
81- public function formatErrors (AnalysisResult $ analysisResult , OutputStyle $ style ): int
82+ public function formatErrors (AnalysisResult $ analysisResult , Output $ output ): int
8283 {
8384 if ($ this ->defaultFormatter !== null ) {
84- $ this ->defaultFormatter ->formatErrors ($ analysisResult , $ style );
85+ $ this ->defaultFormatter ->formatErrors ($ analysisResult , $ output );
8586 }
8687 try {
8788 $ this ->generateFile ($ analysisResult );
88- $ style -> writeln ('Note: Analysis outputted into file ' . $ this ->outputFile . '. ' );
89+ $ output -> getStyle ()-> note ('Note: Analysis outputted into file ' . $ this ->outputFile . '. ' );
8990 } 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 ());
9192 }
9293
9394 return $ analysisResult ->hasErrors () ? 1 : 0 ;
9495 }
9596
9697 /**
9798 * @param mixed[] $data
99+ * @return string
98100 */
99101 public function getTable (array $ data ): string
100102 {
101- ob_start (function (): void {
102- });
103+ ob_start (
104+ static function (): void {
105+ }
106+ );
103107 require $ this ->template ;
104108
105109 $ output = ob_get_clean ();
@@ -131,9 +135,12 @@ private function generateFile(AnalysisResult $analysisResult): void
131135 }
132136
133137 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+ );
137144 }
138145 unset($ file );
139146 }
@@ -144,21 +151,23 @@ private function generateFile(AnalysisResult $analysisResult): void
144151 private static function formatMessage (string $ message ): string
145152 {
146153 $ 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+ }
151159
152- return $ word ;
153- }, $ words );
160+ return $ word ;
161+ },
162+ $ words
163+ );
154164
155165 return implode (' ' , $ words );
156166 }
157167
158168 /**
159169 * @param string $message
160170 * @return string
161- * @throws RegexpException
162171 */
163172 private static function formatRegex (string $ message ): string
164173 {
0 commit comments