1 | <?php |
||
27 | class SyntaxHighlight extends FilterAbstract |
||
28 | { |
||
29 | /** |
||
30 | * @var array default configuration values |
||
31 | */ |
||
32 | protected static $defaultConfiguration = [ |
||
33 | 'enabled' => false, |
||
34 | 'highlighter' => 'php', // Source code highlight: '' - disable; 'php' - php highlight; 'geshi' - geshi highlight |
||
35 | 'language' => 'PHP' |
||
36 | ]; |
||
37 | |||
38 | /** |
||
39 | * apply syntax highlighting to a text string |
||
40 | * |
||
41 | * @param string $source source code text to highlight |
||
42 | * @param string $language of source code |
||
43 | * |
||
44 | * @return bool|mixed|string |
||
45 | */ |
||
46 | 2 | public function applyFilter($source, $language = 'php') |
|
65 | |||
66 | /** |
||
67 | * apply PHP highlight_string |
||
68 | * |
||
69 | * @param string $text source string |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | 2 | public function php($text) |
|
74 | { |
||
75 | 2 | $text = trim($text); |
|
76 | 2 | $addedOpenTag = false; |
|
77 | 2 | if (!strpos($text, "<?php") && (substr($text, 0, 5) !== "<?php")) { |
|
78 | 2 | $text = "<?php " . $text; |
|
79 | 2 | $addedOpenTag = true; |
|
80 | } |
||
81 | |||
82 | 2 | $oldlevel = error_reporting(0); |
|
83 | |||
84 | //There is a bug in the highlight function(php < 5.3) that it doesn't render |
||
85 | //backslashes properly like in \s. So here we replace any backslashes |
||
86 | 2 | $text = str_replace("\\", "XxxX", $text); |
|
87 | |||
88 | 2 | $buffer = highlight_string($text, true); // Require PHP 4.20+ |
|
89 | |||
90 | //Placing backspaces back again |
||
91 | 2 | $buffer = str_replace("XxxX", "\\", $buffer); |
|
92 | |||
93 | 2 | error_reporting($oldlevel); |
|
94 | 2 | $pos_open = $pos_close = 0; |
|
|
|||
95 | 2 | if ($addedOpenTag) { |
|
96 | 2 | $pos_open = strpos($buffer, '<?php '); |
|
97 | } |
||
98 | |||
99 | 2 | $str_open = ($addedOpenTag) ? substr($buffer, 0, $pos_open) : ""; |
|
100 | |||
101 | 2 | $length_open = ($addedOpenTag) ? $pos_open + 14 : 0; |
|
102 | 2 | $str_internal = substr($buffer, $length_open); |
|
103 | |||
104 | 2 | $buffer = $str_open . $str_internal; |
|
105 | 2 | return $buffer; |
|
106 | } |
||
107 | |||
108 | /** |
||
109 | * apply geshi highlighting |
||
110 | * |
||
111 | * @param string $source source code text to highlight |
||
112 | * @param string $language of source code |
||
113 | * |
||
114 | * @return bool |
||
115 | */ |
||
116 | public function geshi($source, $language) |
||
139 | } |
||
140 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.