1 | <?php |
||
18 | abstract class AbstractSeries extends AbstractHelper |
||
19 | { |
||
20 | /** |
||
21 | * |
||
22 | * The array of all elements in the series, by position. |
||
23 | * |
||
24 | * @var array |
||
25 | * |
||
26 | */ |
||
27 | protected $elements = array(); |
||
28 | |||
29 | /** |
||
30 | * |
||
31 | * Returns the helper so you can call methods on it. |
||
32 | * |
||
33 | * If you pass arguments to __invoke(), it will call `$this->add()` with |
||
34 | * those arguments. |
||
35 | * |
||
36 | * @return self |
||
37 | * |
||
38 | */ |
||
39 | public function __invoke() |
||
40 | { |
||
41 | $args = func_get_args(); |
||
42 | if ($args) { |
||
|
|||
43 | call_user_func_array(array($this, 'add'), $args); |
||
44 | } |
||
45 | return $this; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * |
||
50 | * Returns the elements in order as a single string and resets the elements. |
||
51 | * |
||
52 | * @return string The elements as a string. |
||
53 | * |
||
54 | */ |
||
55 | 14 | public function __toString() |
|
56 | { |
||
57 | 14 | $html = ''; |
|
58 | ksort($this->elements); |
||
59 | 14 | foreach ($this->elements as $pos => $elements) { |
|
60 | foreach ($elements as $element) { |
||
61 | 4 | $html .= $this->indent . $element . PHP_EOL; |
|
62 | } |
||
63 | } |
||
64 | 14 | $this->elements = array(); |
|
65 | 14 | return $html; |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * |
||
70 | * Adds an element at a certain position. |
||
71 | * |
||
72 | * @param int $pos The element position. |
||
73 | * |
||
74 | * @param string $element The element itself. |
||
75 | * |
||
76 | * @return null |
||
77 | * |
||
78 | */ |
||
79 | 4 | protected function addElement($pos, $element) |
|
83 | } |
||
84 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.