|
1 | 1 | <?php
|
2 | 2 | namespace JakubOnderka\PhpParallelLint;
|
3 | 3 |
|
4 |
| -use JakubOnderka\PhpConsoleColor\ConsoleColor; |
5 |
| -use JakubOnderka\PhpConsoleHighlighter\Highlighter; |
| 4 | +use JakubOnderka\PhpConsoleColor\ConsoleColor as OldConsoleColor; |
| 5 | +use JakubOnderka\PhpConsoleHighlighter\Highlighter as OldHighlighter; |
| 6 | +use PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor; |
| 7 | +use PHP_Parallel_Lint\PhpConsoleHighlighter\Highlighter; |
6 | 8 |
|
7 | 9 | class ErrorFormatter
|
8 | 10 | {
|
@@ -111,15 +113,26 @@ protected function getCodeSnippet($filePath, $lineNumber, $linesBefore = 2, $lin
|
111 | 113 | protected function getColoredCodeSnippet($filePath, $lineNumber, $linesBefore = 2, $linesAfter = 2)
|
112 | 114 | {
|
113 | 115 | if (
|
114 |
| - !class_exists('\JakubOnderka\PhpConsoleHighlighter\Highlighter') || |
115 |
| - !class_exists('\JakubOnderka\PhpConsoleColor\ConsoleColor') |
| 116 | + class_exists('\PHP_Parallel_Lint\PhpConsoleHighlighter\Highlighter') |
| 117 | + && class_exists('\PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor') |
116 | 118 | ) {
|
117 |
| - return $this->getCodeSnippet($filePath, $lineNumber, $linesBefore, $linesAfter); |
| 119 | + // Highlighter and ConsoleColor 1.0+. |
| 120 | + $colors = new ConsoleColor(); |
| 121 | + $colors->setForceStyle($this->forceColors); |
| 122 | + $highlighter = new Highlighter($colors); |
| 123 | + } else if ( |
| 124 | + class_exists('\JakubOnderka\PhpConsoleHighlighter\Highlighter') |
| 125 | + && class_exists('\JakubOnderka\PhpConsoleColor\ConsoleColor') |
| 126 | + ) { |
| 127 | + // Highlighter and ConsoleColor < 1.0. |
| 128 | + $colors = new OldConsoleColor(); |
| 129 | + $colors->setForceStyle($this->forceColors); |
| 130 | + $highlighter = new OldHighlighter($colors); |
118 | 131 | }
|
119 | 132 |
|
120 |
| - $colors = new ConsoleColor(); |
121 |
| - $colors->setForceStyle($this->forceColors); |
122 |
| - $highlighter = new Highlighter($colors); |
| 133 | + if (isset($colors, $highlighter) === false) { |
| 134 | + return $this->getCodeSnippet($filePath, $lineNumber, $linesBefore, $linesAfter); |
| 135 | + } |
123 | 136 |
|
124 | 137 | $fileContent = file_get_contents($filePath);
|
125 | 138 | return $highlighter->getCodeSnippet($fileContent, $lineNumber, $linesBefore, $linesAfter);
|
|
0 commit comments