Conditions | 5 |
Paths | 3 |
Total Lines | 22 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
25 | public function renderInternal() |
||
26 | { |
||
27 | $headerWrap = MailUtility::breakLinesForEmail(trim($this->contentObject->data['header']), LF, Configuration::getPlainTextWith()); |
||
28 | $subHeaderWrap = MailUtility::breakLinesForEmail(trim($this->contentObject->data['subheader']), LF, Configuration::getPlainTextWith()); |
||
29 | |||
30 | // align |
||
31 | $header = array_merge(GeneralUtility::trimExplode(LF, $headerWrap, true), GeneralUtility::trimExplode(LF, $subHeaderWrap, true)); |
||
32 | if ($this->contentObject->data['header_position'] == 'right') { |
||
33 | foreach ($header as $key => $l) { |
||
34 | $l = trim($l); |
||
35 | $header[$key] = str_pad(' ', (Configuration::getPlainTextWith() - strlen($l)), ' ', STR_PAD_LEFT) . $l; |
||
36 | } |
||
37 | } elseif ($this->contentObject->data['header_position'] == 'center') { |
||
38 | foreach ($header as $key => $l) { |
||
39 | $l = trim($l); |
||
40 | $header[$key] = str_pad(' ', floor((Configuration::getPlainTextWith() - strlen($l)) / 2), ' ', STR_PAD_LEFT) . $l; |
||
41 | } |
||
42 | } |
||
43 | $header = implode(LF, $header); |
||
44 | $lines[] = $header; |
||
|
|||
45 | return $lines; |
||
46 | } |
||
47 | } |
||
48 |
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.