30
30
either expressed or implied, of the FreeBSD Project.
31
31
*/
32
32
33
+ use Colors \Color ;
33
34
use JakubOnderka \PhpConsoleHighlighter \Highlighter ;
34
35
35
36
class Error
@@ -104,6 +105,7 @@ protected function getCodeSnippet($lineNumber, $linesBefore = 2, $linesAfter = 2
104
105
$ lines = file ($ this ->filePath );
105
106
106
107
$ offset = $ lineNumber - $ linesBefore - 1 ;
108
+ $ offset = max ($ offset , 0 );
107
109
$ length = $ linesAfter + $ linesBefore + 1 ;
108
110
$ lines = array_slice ($ lines , $ offset , $ length , $ preserveKeys = true );
109
111
@@ -210,17 +212,10 @@ protected function getCodeSnippet($lineNumber, $linesBefore = 2, $linesAfter = 2
210
212
return parent ::getCodeSnippet ($ lineNumber , $ linesBefore , $ linesAfter );
211
213
}
212
214
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 );
222
217
223
218
$ fileContent = file_get_contents ($ this ->filePath );
224
- return $ highliger ->getCodeSnippet ($ fileContent , $ lineNumber , $ linesBefore , $ linesAfter );
219
+ return $ highlighter ->getCodeSnippet ($ fileContent , $ lineNumber , $ linesBefore , $ linesAfter );
225
220
}
226
221
}
0 commit comments