3030either expressed or implied, of the FreeBSD Project.
3131 */
3232
33+ use Colors \Color ;
3334use JakubOnderka \PhpConsoleHighlighter \Highlighter ;
3435
3536class Error
@@ -104,6 +105,7 @@ protected function getCodeSnippet($lineNumber, $linesBefore = 2, $linesAfter = 2
104105 $ lines = file ($ this ->filePath );
105106
106107 $ offset = $ lineNumber - $ linesBefore - 1 ;
108+ $ offset = max ($ offset , 0 );
107109 $ length = $ linesAfter + $ linesBefore + 1 ;
108110 $ lines = array_slice ($ lines , $ offset , $ length , $ preserveKeys = true );
109111
@@ -210,17 +212,10 @@ protected function getCodeSnippet($lineNumber, $linesBefore = 2, $linesAfter = 2
210212 return parent ::getCodeSnippet ($ lineNumber , $ linesBefore , $ linesAfter );
211213 }
212214
213- $ colors = new \Colors \Color ();
214- $ colors ->setTheme (array (
215- Highlighter::TOKEN_STRING => 'red ' ,
216- Highlighter::TOKEN_COMMENT => 'yellow ' ,
217- Highlighter::TOKEN_KEYWORD => 'green ' ,
218- Highlighter::TOKEN_DEFAULT => 'white ' ,
219- Highlighter::TOKEN_HTML => 'cyan '
220- ));
221- $ highliger = new Highlighter ($ colors );
215+ $ colors = new Color ();
216+ $ highlighter = new Highlighter ($ colors );
222217
223218 $ fileContent = file_get_contents ($ this ->filePath );
224- return $ highliger ->getCodeSnippet ($ fileContent , $ lineNumber , $ linesBefore , $ linesAfter );
219+ return $ highlighter ->getCodeSnippet ($ fileContent , $ lineNumber , $ linesBefore , $ linesAfter );
225220 }
226221}
0 commit comments