1 | <?php |
||
7 | class Itunes extends AbstractVendor implements VendorInterface |
||
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | const SEARCH_URL = "https://itunes.apple.com/search"; |
||
13 | |||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | const LOOKUP_URL = "https://itunes.apple.com/lookup"; |
||
18 | |||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | const ENTITY = "podcast"; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | const MEDIA = "podcast"; |
||
28 | |||
29 | /** |
||
30 | * @var int |
||
31 | */ |
||
32 | private $limit = 15; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | private $defaultQuery = null; |
||
38 | |||
39 | /** |
||
40 | * Itunes constructor. |
||
41 | */ |
||
42 | public function __construct() |
||
46 | |||
47 | /** |
||
48 | * @return int |
||
49 | */ |
||
50 | public function getLimit() |
||
54 | |||
55 | /** |
||
56 | * @param int $limit |
||
57 | */ |
||
58 | public function setLimit($limit) |
||
62 | |||
63 | /** |
||
64 | * @return void |
||
65 | */ |
||
66 | public function setDefaultQuery() |
||
74 | |||
75 | /** |
||
76 | * @param string $value |
||
77 | * @return string |
||
78 | */ |
||
79 | public function generateUrl($value) |
||
86 | |||
87 | /** |
||
88 | * @param array $response |
||
89 | * @return array |
||
90 | */ |
||
91 | public function build(array $response) |
||
111 | } |
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.