1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @file |
4
|
|
|
* Contains \TheSportsDb\Entity\Proxy\LeagueProxy. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace TheSportsDb\Entity\Proxy; |
8
|
|
|
|
9
|
|
|
use TheSportsDb\Entity\LeagueInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* A league object that is not yet fully loaded. |
13
|
|
|
* |
14
|
|
|
* @author Jelle Sebreghts |
15
|
|
|
*/ |
16
|
|
|
class LeagueProxy extends Proxy implements LeagueInterface { |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
public function load() { |
|
|
|
|
22
|
|
|
$leagueData = $this->sportsDbClient->doRequest('lookupleague.php', array('id' => $this->properties->id)); |
23
|
|
|
if (isset($leagueData->leagues)) { |
24
|
|
|
$this->update($this->entityManager->mapProperties(reset($leagueData->leagues), $this->getEntityType())); |
25
|
|
|
return; |
26
|
|
|
} |
27
|
|
|
throw new \Exception('Could not fully load league with id ' . $this->properties->id . '.'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Lazy loads the seasons for this league. |
32
|
|
|
* |
33
|
|
|
* @throws \Exception |
34
|
|
|
* When the seasons cannot be loaded. |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
|
|
protected function loadSeasons() { |
39
|
|
|
$leagueData = $this->sportsDbClient->doRequest('lookupleague.php', array('id' => $this->properties->id, 's' => 'all')); |
40
|
|
|
if (isset($leagueData->leagues)) { |
41
|
|
|
$leagues = $leagueData->leagues; |
42
|
|
|
foreach ($leagues as &$league) { |
43
|
|
|
if (!isset($league->idLeague)) { |
44
|
|
|
$league->idLeague = $this->properties->id; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
$this->update($this->entityManager->mapProperties((object) array('seasons' => $leagues), $this->getEntityType())); |
48
|
|
|
return; |
49
|
|
|
} |
50
|
|
|
throw new \Exception('Could not fully load league with id ' . $this->properties->id . '.'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
1 |
|
public function getAlternateName() { |
57
|
1 |
|
return $this->get('alternateName'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritdoc} |
62
|
|
|
*/ |
63
|
1 |
|
public function getBadge() { |
64
|
1 |
|
return $this->get('badge'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
1 |
|
public function getBanner() { |
71
|
1 |
|
return $this->get('banner'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
1 |
|
public function getCountry() { |
78
|
1 |
|
return $this->get('country'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
1 |
|
public function getDateFirstEvent() { |
85
|
1 |
|
return $this->get('dateFirstEvent'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
1 |
|
public function getDescription() { |
92
|
1 |
|
return $this->get('description'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* {@inheritdoc} |
97
|
|
|
*/ |
98
|
1 |
|
public function getFacebook() { |
99
|
1 |
|
return $this->get('facebook'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritdoc} |
104
|
|
|
*/ |
105
|
1 |
|
public function getFormedYear() { |
106
|
1 |
|
return $this->get('formedYear'); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* {@inheritdoc} |
111
|
|
|
*/ |
112
|
1 |
|
public function getGender() { |
113
|
1 |
|
return $this->get('gender'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* {@inheritdoc} |
118
|
|
|
*/ |
119
|
1 |
|
public function getId() { |
120
|
1 |
|
return $this->get('id'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* {@inheritdoc} |
125
|
|
|
*/ |
126
|
1 |
|
public function getLocked() { |
127
|
1 |
|
return $this->get('locked'); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* {@inheritdoc} |
132
|
|
|
*/ |
133
|
1 |
|
public function getLogo() { |
134
|
1 |
|
return $this->get('logo'); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* {@inheritdoc} |
139
|
|
|
*/ |
140
|
1 |
|
public function getName() { |
141
|
1 |
|
return $this->get('name'); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* {@inheritdoc} |
146
|
|
|
*/ |
147
|
1 |
|
public function getNaming() { |
148
|
1 |
|
return $this->get('naming'); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* {@inheritdoc} |
153
|
|
|
*/ |
154
|
1 |
|
public function getPoster() { |
155
|
1 |
|
return $this->get('poster'); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* {@inheritdoc} |
160
|
|
|
*/ |
161
|
1 |
|
public function getRss() { |
162
|
1 |
|
return $this->get('rss'); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* {@inheritdoc} |
167
|
|
|
*/ |
168
|
1 |
|
public function getTrophy() { |
169
|
1 |
|
return $this->get('trophy'); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* {@inheritdoc} |
174
|
|
|
*/ |
175
|
1 |
|
public function getTwitter() { |
176
|
1 |
|
return $this->get('twitter'); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* {@inheritdoc} |
181
|
|
|
*/ |
182
|
1 |
|
public function getWebsite() { |
183
|
1 |
|
return $this->get('website'); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* {@inheritdoc} |
188
|
|
|
*/ |
189
|
1 |
|
public function getYoutube() { |
190
|
1 |
|
return $this->get('youtube'); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* {@inheritdoc} |
195
|
|
|
*/ |
196
|
1 |
|
public function getSeasons() { |
197
|
1 |
|
return $this->get('seasons'); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* {@inheritdoc} |
202
|
|
|
*/ |
203
|
1 |
|
public function getSport() { |
204
|
1 |
|
return $this->get('sport'); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
} |
208
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.