44
55namespace PHPLint \Console \Output ;
66
7+ use PHPLint \Console \ConsoleColorEnum ;
78use PHPLint \Process \LintProcessResult ;
9+ use PHPLint \Process \StatusEnum ;
810use Symfony \Component \Console \Helper \Helper ;
911use Symfony \Component \Console \Style \SymfonyStyle ;
1012
@@ -22,6 +24,8 @@ final class LintConsoleOutput
2224
2325 private bool $ isSuccess = true ;
2426
27+ private int $ countFiles = 0 ;
28+
2529 public function __construct (
2630 private readonly SymfonyStyle $ symfonyStyle
2731 ) {
@@ -31,8 +35,13 @@ public function startApplication(string $version): void
3135 {
3236 $ argv = $ _SERVER ['argv ' ] ?? [];
3337
38+ $ message = sprintf (
39+ '<fg=blue;options=bold>PHP</><fg=yellow;options=bold>Lint</> %s - current PHP version: %s ' ,
40+ $ version ,
41+ PHP_VERSION ,
42+ );
3443 $ this ->symfonyStyle ->writeln ('> ' . implode ('' , $ argv ));
35- $ this ->symfonyStyle ->writeln (' <fg=blue;options=bold>PHP</><fg=yellow;options=bold>Lint</> ' . $ version );
44+ $ this ->symfonyStyle ->writeln ($ message );
3645 $ this ->symfonyStyle ->writeln ('' );
3746 }
3847
@@ -43,11 +52,11 @@ public function finishApplication(string $executionTime): bool
4352 $ this ->symfonyStyle ->writeln (sprintf ('Memory usage: %s ' , $ usageMemory ));
4453
4554 if (! $ this ->isSuccess ) {
46- $ this ->symfonyStyle ->error (sprintf ('Finished in %s seconds ' , $ executionTime ));
55+ $ this ->symfonyStyle ->error (sprintf ('Finished in %s ' , $ executionTime ));
4756 return true ;
4857 }
4958
50- $ this ->symfonyStyle ->success (sprintf ('Finished in %s seconds ' , $ executionTime ));
59+ $ this ->symfonyStyle ->success (sprintf ('Finished in %s ' , $ executionTime ));
5160 return false ; // false means success
5261 }
5362
@@ -71,18 +80,38 @@ public function progressBarFinish(): void
7180
7281 public function messageByProcessResult (LintProcessResult $ lintProcessResult ): void
7382 {
74- $ line01 = sprintf ('<options=bold>line %s </><fg=gray;options=bold>[%s]</> ' , $ lintProcessResult ->getLine (), $ lintProcessResult ->getFilename ());
75- $ line02 = sprintf ('<fg=bright-red>%s</> ' , $ lintProcessResult ->getResult ());
83+ $ consoleColorEnum = match ($ lintProcessResult ->getStatus ()) {
84+ StatusEnum::OK => ConsoleColorEnum::GREEN ,
85+ StatusEnum::NOTICE => ConsoleColorEnum::BLUE ,
86+ StatusEnum::WARNING => ConsoleColorEnum::YELLOW ,
87+ default => ConsoleColorEnum::RED ,
88+ };
89+
90+ ++$ this ->countFiles ;
91+
92+ $ line01 = sprintf (
93+ '<fg=white;options=bold>#%d - line %s </><fg=gray;options=bold>[%s]</> ' ,
94+ $ this ->countFiles ,
95+ $ lintProcessResult ->getLine (),
96+ $ lintProcessResult ->getFilename (),
97+ );
98+ $ line02 = sprintf (
99+ '<fg=%s;options=bold>%s</>: <fg=%s>%s</> ' ,
100+ $ consoleColorEnum ->getBrightValue (),
101+ ucfirst ($ lintProcessResult ->getStatus ()->value ),
102+ $ consoleColorEnum ->value ,
103+ $ lintProcessResult ->getResult (),
104+ );
76105
77106 $ this ->symfonyStyle ->writeln ($ line01 );
78107 $ this ->symfonyStyle ->writeln ($ line02 );
79- $ this ->loadCodeSnippet ($ lintProcessResult ->getFilename (), (int ) $ lintProcessResult ->getLine ());
108+ $ this ->loadCodeSnippet ($ lintProcessResult ->getFilename (), (int ) $ lintProcessResult ->getLine (), $ consoleColorEnum );
80109 $ this ->symfonyStyle ->newLine ();
81110
82111 $ this ->isSuccess = false ;
83112 }
84113
85- private function loadCodeSnippet (string $ filename , int $ line ): void
114+ private function loadCodeSnippet (string $ filename , int $ line, ConsoleColorEnum $ consoleColorEnum ): void
86115 {
87116 $ lineStart = $ line - self ::SNIPPED_LINE ;
88117 $ lineEnd = $ line + (self ::SNIPPED_LINE - 1 );
@@ -102,9 +131,22 @@ private function loadCodeSnippet(string $filename, int $line): void
102131 $ lineNumberPre = substr ($ tmp , 0 , self ::LINE_LENGTH - strlen ((string ) $ lineNumberPost ));
103132
104133 if ($ lineCnt + 1 === $ line ) {
105- $ result = sprintf ('<fg=bright-red;options=bold>%s</><fg=red>%s</><fg=blue;options=bold>:</> <fg=red>%s</> ' , $ lineNumberPre , $ lineNumberPost , $ contentLine );
134+ $ result = sprintf (
135+ '<fg=%s;options=bold>%s</><fg=%s>%s</><fg=blue;options=bold>:</> <fg=%s>%s</> ' ,
136+ $ consoleColorEnum ->getBrightValue (),
137+ $ lineNumberPre ,
138+ $ consoleColorEnum ->value ,
139+ $ lineNumberPost ,
140+ $ consoleColorEnum ->value ,
141+ $ contentLine ,
142+ );
106143 } else {
107- $ result = sprintf ('<fg=gray;options=bold>%s</><fg=white>%s</><fg=blue;options=bold>:</> <fg=white>%s</> ' , $ lineNumberPre , $ lineNumberPost , $ contentLine );
144+ $ result = sprintf (
145+ '<fg=gray;options=bold>%s</><fg=white>%s</><fg=blue;options=bold>:</> <fg=white>%s</> ' ,
146+ $ lineNumberPre ,
147+ $ lineNumberPost ,
148+ $ contentLine ,
149+ );
108150 }
109151
110152 $ this ->symfonyStyle ->writeln ($ result );
0 commit comments