Conditions | 4 |
Paths | 4 |
Total Lines | 28 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
28 | public function getList() |
||
29 | { |
||
30 | if (empty($this->themes)) { |
||
31 | return false; |
||
32 | } |
||
33 | |||
34 | $i = 1; |
||
35 | foreach ($this->themes as $key => $value) { |
||
36 | $path = THEMES_ROOT.'/front/'.$value.'/theme.php'; |
||
37 | |||
38 | if (file_exists($path)) { |
||
39 | include_once $path; |
||
40 | } |
||
41 | |||
42 | $array[] = [ |
||
|
|||
43 | 'id' => $i++, |
||
44 | 'path' => str_replace(['/theme.php', 'public/'], '', $path), |
||
45 | 'name' => $value, |
||
46 | 'description' => $value::DESCRIPTION, |
||
47 | 'full-name' => $value::NAME, |
||
48 | 'author' => $value::AUTHOR, |
||
49 | 'version' => $value::VERSION, |
||
50 | 'active' => FRONT_THEME == $value, |
||
51 | ]; |
||
52 | } |
||
53 | |||
54 | return $array; |
||
55 | } |
||
56 | } |
||
57 |
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.