1 | <?php |
||
20 | class EventAttendeesBlockRenderer extends BlockRenderer |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * @var EEM_Attendee |
||
25 | */ |
||
26 | private $attendee_model; |
||
27 | |||
28 | public function __construct(DomainInterface $domain, EEM_Attendee $attendee_model) |
||
33 | |||
34 | |||
35 | /** |
||
36 | * Renders the block. |
||
37 | * |
||
38 | * @param array $attributes Expect already validated and sanitized array of attributes for use in generating the |
||
39 | * query and the template output. |
||
40 | * @return string |
||
41 | * @throws DomainException |
||
42 | * @throws EE_Error |
||
43 | */ |
||
44 | public function render(array $attributes) |
||
54 | |||
55 | |||
56 | /** |
||
57 | * Get query parameters for model query. |
||
58 | * |
||
59 | * @param array $attributes |
||
60 | * @return array |
||
61 | */ |
||
62 | private function getQueryParams(array $attributes) |
||
72 | |||
73 | |||
74 | /** |
||
75 | * Get where query part for query parameters for model query. |
||
76 | * |
||
77 | * @param array $attributes |
||
78 | * @return array |
||
79 | */ |
||
80 | private function getWhereQueryPart(array $attributes) |
||
93 | |||
94 | |||
95 | /** |
||
96 | * Get order by query part for query parameters for model query. |
||
97 | * |
||
98 | * @param array $attributes |
||
99 | * @return array |
||
100 | */ |
||
101 | private function getOrderByQueryPart(array $attributes) |
||
123 | } |
||
124 |
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.