44
55namespace PHPLint \Console \Output ;
66
7- use PHPLint \Console \ConsoleColorEnum ;
7+ use PHPLint \Config \LintConfig ;
8+ use PHPLint \Console \OutputColorEnum ;
89use PHPLint \Process \LintProcessResult ;
910use PHPLint \Process \StatusEnum ;
1011use Symfony \Component \Console \Helper \Helper ;
@@ -27,7 +28,8 @@ final class LintConsoleOutput
2728 private int $ countFiles = 0 ;
2829
2930 public function __construct (
30- private readonly SymfonyStyle $ symfonyStyle
31+ private readonly SymfonyStyle $ symfonyStyle ,
32+ private readonly LintConfig $ lintConfig ,
3133 ) {
3234 }
3335
@@ -62,29 +64,38 @@ public function finishApplication(string $executionTime): bool
6264
6365 public function progressBarStart (int $ count ): void
6466 {
65- $ this ->symfonyStyle ->writeln ('Linting files... ' );
66- $ this ->symfonyStyle ->newLine ();
67+ if ($ this ->lintConfig ->isIgnoreProcessBar ()) {
68+ return ;
69+ }
6770
6871 $ this ->symfonyStyle ->progressStart ($ count );
6972 }
7073
7174 public function progressBarAdvance (): void
7275 {
76+ if ($ this ->lintConfig ->isIgnoreProcessBar ()) {
77+ return ;
78+ }
79+
7380 $ this ->symfonyStyle ->progressAdvance ();
7481 }
7582
7683 public function progressBarFinish (): void
7784 {
85+ if ($ this ->lintConfig ->isIgnoreProcessBar ()) {
86+ return ;
87+ }
88+
7889 $ this ->symfonyStyle ->progressFinish ();
7990 }
8091
8192 public function messageByProcessResult (LintProcessResult $ lintProcessResult ): void
8293 {
83- $ consoleColorEnum = match ($ lintProcessResult ->getStatus ()) {
84- StatusEnum::OK => ConsoleColorEnum ::GREEN ,
85- StatusEnum::NOTICE => ConsoleColorEnum ::BLUE ,
86- StatusEnum::WARNING => ConsoleColorEnum ::YELLOW ,
87- default => ConsoleColorEnum ::RED ,
94+ $ outputColorEnum = match ($ lintProcessResult ->getStatus ()) {
95+ StatusEnum::OK => OutputColorEnum ::GREEN ,
96+ StatusEnum::NOTICE => OutputColorEnum ::BLUE ,
97+ StatusEnum::WARNING => OutputColorEnum ::YELLOW ,
98+ default => OutputColorEnum ::RED ,
8899 };
89100
90101 ++$ this ->countFiles ;
@@ -97,25 +108,29 @@ public function messageByProcessResult(LintProcessResult $lintProcessResult): vo
97108 );
98109 $ line02 = sprintf (
99110 '<fg=%s;options=bold>%s</>: <fg=%s>%s</> ' ,
100- $ consoleColorEnum ->getBrightValue (),
111+ $ outputColorEnum ->getBrightValue (),
101112 ucfirst ($ lintProcessResult ->getStatus ()->value ),
102- $ consoleColorEnum ->value ,
113+ $ outputColorEnum ->value ,
103114 $ lintProcessResult ->getResult (),
104115 );
105116
106117 $ this ->symfonyStyle ->writeln ($ line01 );
107118 $ this ->symfonyStyle ->writeln ($ line02 );
108- $ this ->loadCodeSnippet ($ lintProcessResult ->getFilename (), (int ) $ lintProcessResult ->getLine (), $ consoleColorEnum );
119+ $ this ->loadCodeSnippet ($ lintProcessResult ->getFilename (), (int ) $ lintProcessResult ->getLine (), $ outputColorEnum );
109120 $ this ->symfonyStyle ->newLine ();
110121
111122 $ this ->isSuccess = false ;
112123 }
113124
114- private function loadCodeSnippet (string $ filename , int $ line , ConsoleColorEnum $ consoleColorEnum ): void
125+ private function loadCodeSnippet (string $ filename , int $ line , OutputColorEnum $ outputColorEnum ): void
115126 {
116127 $ lineStart = $ line - self ::SNIPPED_LINE ;
117128 $ lineEnd = $ line + (self ::SNIPPED_LINE - 1 );
118129
130+ if (! file_exists ($ filename )) {
131+ return ;
132+ }
133+
119134 $ content = file_get_contents ($ filename );
120135 if ($ content === false ) {
121136 return ;
@@ -126,25 +141,25 @@ private function loadCodeSnippet(string $filename, int $line, ConsoleColorEnum $
126141 $ lineCnt = 0 ;
127142 foreach ($ contentArray as $ contentLine ) {
128143 if ($ lineCnt >= $ lineStart && $ lineCnt < $ lineEnd ) {
129- $ lineNumberPost = $ lineCnt + 1 ;
130- $ tmp = str_pad ((string ) $ lineNumberPost , self ::LINE_LENGTH , '0 ' , STR_PAD_LEFT );
131- $ lineNumberPre = substr ($ tmp , 0 , self ::LINE_LENGTH - strlen ((string ) $ lineNumberPost ));
144+ $ lineNumber = $ lineCnt + 1 ;
145+ $ tmp = str_pad ((string ) $ lineNumber , self ::LINE_LENGTH , '0 ' , STR_PAD_LEFT );
146+ $ lineNumberPrefix = substr ($ tmp , 0 , self ::LINE_LENGTH - strlen ((string ) $ lineNumber ));
132147
133148 if ($ lineCnt + 1 === $ line ) {
134149 $ 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 ,
150+ '<fg=%s>%s</><fg=%s;options=bold >%s</><fg=gray>| </> <fg=%s>%s</> ' ,
151+ $ outputColorEnum ->getBrightValue (),
152+ $ lineNumberPrefix ,
153+ $ outputColorEnum ->value ,
154+ $ lineNumber ,
155+ $ outputColorEnum ->value ,
141156 $ contentLine ,
142157 );
143158 } else {
144159 $ result = sprintf (
145- '<fg=gray;options=bold >%s</><fg=white>%s</><fg=blue;options=bold>: </> <fg=white>%s</> ' ,
146- $ lineNumberPre ,
147- $ lineNumberPost ,
160+ '<fg=gray>%s</><fg=white;options=bold >%s</><fg=gray>| </> <fg=white>%s</> ' ,
161+ $ lineNumberPrefix ,
162+ $ lineNumber ,
148163 $ contentLine ,
149164 );
150165 }
0 commit comments