1 | <?php |
||
13 | class Text_Diff_Renderer |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * Number of leading context "lines" to preserve. |
||
18 | * |
||
19 | * This should be left at zero for this class, but subclasses may want to |
||
20 | * set this to other values. |
||
21 | */ |
||
22 | public $_leading_context_lines = 0; |
||
23 | |||
24 | /** |
||
25 | * Number of trailing context "lines" to preserve. |
||
26 | * |
||
27 | * This should be left at zero for this class, but subclasses may want to |
||
28 | * set this to other values. |
||
29 | */ |
||
30 | public $_trailing_context_lines = 0; |
||
31 | |||
32 | /** |
||
33 | * Constructor. |
||
34 | * @param array $params |
||
35 | */ |
||
36 | public function __construct($params = array()) |
||
45 | |||
46 | /** |
||
47 | * Get any renderer parameters. |
||
48 | * |
||
49 | * @return array All parameters of this renderer object. |
||
50 | */ |
||
51 | public function getParams() |
||
62 | |||
63 | /** |
||
64 | * Renders a diff. |
||
65 | * |
||
66 | * @param Text_Diff $diff A Text_Diff object. |
||
67 | * |
||
68 | * @return string The formatted output. |
||
69 | */ |
||
70 | public function render($diff) |
||
123 | |||
124 | /** |
||
125 | * @param $xbeg |
||
126 | * @param $xlen |
||
127 | * @param $ybeg |
||
128 | * @param $ylen |
||
129 | * @param $edits |
||
130 | * @return string |
||
131 | */ |
||
132 | public function _block($xbeg, $xlen, $ybeg, $ylen, &$edits) |
||
158 | |||
159 | /** |
||
160 | * @return string |
||
161 | */ |
||
162 | public function _startDiff() |
||
166 | |||
167 | /** |
||
168 | * @return string |
||
169 | */ |
||
170 | public function _endDiff() |
||
174 | |||
175 | /** |
||
176 | * @param $xbeg |
||
177 | * @param $xlen |
||
178 | * @param $ybeg |
||
179 | * @param $ylen |
||
180 | * @return string |
||
181 | */ |
||
182 | public function _blockHeader($xbeg, $xlen, $ybeg, $ylen) |
||
193 | |||
194 | /** |
||
195 | * @param $header |
||
196 | * @return string |
||
197 | */ |
||
198 | public function _startBlock($header) |
||
202 | |||
203 | /** |
||
204 | * @return string |
||
205 | */ |
||
206 | public function _endBlock() |
||
210 | |||
211 | /** |
||
212 | * @param $lines |
||
213 | * @param string $prefix |
||
214 | * @return string |
||
215 | */ |
||
216 | public function _lines($lines, $prefix = ' ') |
||
220 | |||
221 | /** |
||
222 | * @param $lines |
||
223 | * @return string |
||
224 | */ |
||
225 | public function _context($lines) |
||
229 | |||
230 | /** |
||
231 | * @param $lines |
||
232 | * @return string |
||
233 | */ |
||
234 | public function _added($lines) |
||
238 | |||
239 | /** |
||
240 | * @param $lines |
||
241 | * @return string |
||
242 | */ |
||
243 | public function _deleted($lines) |
||
247 | |||
248 | /** |
||
249 | * @param $orig |
||
250 | * @param $final |
||
251 | * @return string |
||
252 | */ |
||
253 | public function _changed($orig, $final) |
||
257 | } |
||
258 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: