1 | <?php |
||
5 | class Match |
||
6 | { |
||
7 | const PLAYERS = [ |
||
8 | 'HomeLineupGoalkeeper', |
||
9 | 'HomeLineupDefense', |
||
10 | 'HomeLineupMidfield', |
||
11 | 'HomeLineupForward', |
||
12 | 'HomeLineupSubstitutes', |
||
13 | 'AwayLineupGoalkeeper', |
||
14 | 'AwayLineupDefense', |
||
15 | 'AwayLineupMidfield', |
||
16 | 'AwayLineupForward', |
||
17 | 'AwayLineupSubstitutes' |
||
18 | ]; |
||
19 | |||
20 | const GOAL_DETAILS = [ |
||
21 | 'HomeGoalDetails', |
||
22 | 'AwayGoalDetails' |
||
23 | ]; |
||
24 | |||
25 | const CARDS = [ |
||
26 | 'HomeTeamYellowCardDetails', |
||
27 | 'HomeTeamRedCardDetails', |
||
28 | 'AwayTeamYellowCardDetails', |
||
29 | 'AwayTeamRedCardDetails' |
||
30 | ]; |
||
31 | |||
32 | const SUBSTITUTIONS = [ |
||
33 | 'HomeSubDetails', |
||
34 | 'AwaySubDetails' |
||
35 | ]; |
||
36 | |||
37 | const NUMERIC = [ |
||
38 | 'Id', |
||
39 | 'FixtureMatch_Id', |
||
40 | 'Round', |
||
41 | 'Spectators', |
||
42 | 'HomeTeam_Id', |
||
43 | 'HomeGoals', |
||
44 | 'HalfTimeHomeGoals', |
||
45 | 'HomeShots', |
||
46 | 'HomeShotsOnTarget', |
||
47 | 'HomeFouls', |
||
48 | 'HomeYellowCards', |
||
49 | 'HomeRedCards', |
||
50 | 'AwayTeam_Id', |
||
51 | 'AwayGoals', |
||
52 | 'HalfTimeAwayGoals', |
||
53 | 'AwayShots', |
||
54 | 'AwayShotsOnTarget', |
||
55 | 'AwayFouls', |
||
56 | 'AwayYellowCards', |
||
57 | 'AwayRedCards' |
||
58 | ]; |
||
59 | |||
60 | public function handle($match) |
||
71 | |||
72 | protected function processAtrribute($name, $data) |
||
99 | |||
100 | protected function players($data) |
||
104 | |||
105 | protected function goals($goal) |
||
122 | |||
123 | protected function cards($card) |
||
128 | |||
129 | protected function substitutions($substitution) |
||
138 | |||
139 | protected function toArray($data) |
||
145 | |||
146 | /** |
||
147 | * Very occasionally the data has spurious hard spaces that need to be removed |
||
148 | */ |
||
149 | protected function cleanse($data) |
||
153 | } |
||
154 |
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.