Conditions | 2 |
Paths | 2 |
Total Lines | 20 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 6 |
Changes | 0 |
1 | <?php |
||
11 | function renderHtml() |
||
12 | { |
||
13 | if ($this->query('language') == 'da') { |
||
14 | $text[0] = 'Intraface Betaling'; |
||
|
|||
15 | $text[1] = 'Du er nu ved at betale for ordre nummer'; |
||
16 | $text[2] = 'I alt hæves %s på fra dit kort'; |
||
17 | $text[3] = 'Betalingen foretages over Quickpay\'s sikker betalingsserver.'; |
||
18 | } else { |
||
19 | $text[0] = 'Intraface Payment'; |
||
20 | $text[1] = 'You are now about to pay for order number'; |
||
21 | $text[2] = '%s is withdrawed from your card'; |
||
22 | $text[3] = 'The payment is carried out via Quickpay\'s secure server.'; |
||
23 | } |
||
24 | |||
25 | $this->document->setTitle('Payment'); |
||
26 | |||
27 | $tpl = $this->template->create(dirname(__FILE__) . '/templates/payment'); |
||
28 | $content = $tpl-render($this, array('text' => $text)); |
||
29 | return new k_HtmlResponse($content); |
||
30 | } |
||
31 | } |
||
32 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.