1 | <?php |
||
17 | class PlayerProfileTransformer extends TransformerAbstract implements HttpClientAwareInterface |
||
18 | { |
||
19 | use HttpClientAwareTrait; |
||
20 | |||
21 | /** |
||
22 | * List of available includes to this resource |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $availableIncludes = [ |
||
27 | 'census', |
||
28 | 'involvement', |
||
29 | 'metrics', |
||
30 | 'outfit', |
||
31 | //'vehicles', |
||
32 | 'weapons' |
||
33 | ]; |
||
34 | |||
35 | protected $outfitTotalRepo; |
||
36 | protected $playerRepo; |
||
37 | protected $vehicleRepo; |
||
38 | protected $weaponRepo; |
||
39 | |||
40 | public function __construct( |
||
41 | OutfitTotalRepository $outfitTotalRepo, |
||
42 | PlayerRepository $playerRepo, |
||
43 | VehicleRepository $vehicleRepo, |
||
44 | WeaponRepository $weaponRepo |
||
45 | ) { |
||
46 | $this->outfitTotalRepo = $outfitTotalRepo; |
||
47 | $this->playerRepo = $playerRepo; |
||
48 | $this->vehicleRepo = $vehicleRepo; |
||
49 | $this->weaponRepo = $weaponRepo; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * The transform method required by Fractal to parse the data and return proper typing and fields. |
||
54 | * |
||
55 | * @param array $data Data to transform |
||
56 | * |
||
57 | * @return array |
||
58 | */ |
||
59 | public function transform($data) |
||
60 | { |
||
61 | return [ |
||
62 | 'id' => (string) $data['playerID'], // Bigint |
||
63 | 'name' => (string) $data['playerName'], |
||
64 | 'outfit' => (string) $data['playerOutfit'], // Bigint |
||
65 | 'faction' => (int) $data['playerFaction'], |
||
66 | 'server' => (int) $data['playerServer'] |
||
67 | ]; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * Grab Census only info |
||
72 | * |
||
73 | * @param array $data |
||
74 | * |
||
75 | * @return \League\Fractal\Resource\Collection |
||
76 | */ |
||
77 | public function includeCensus($data) |
||
129 | |||
130 | /** |
||
131 | * Get Alert involvement & metrics |
||
132 | * |
||
133 | * @param array $data |
||
134 | * |
||
135 | * @return \League\Fractal\Resource\Collection |
||
136 | */ |
||
137 | public function includeInvolvement($data) |
||
138 | { |
||
139 | $data = $this->playerRepo->readAllByIdWithArchive($data['playerID'], 'playerID'); |
||
140 | |||
141 | return $this->collection($data, new PlayerInvolvementTransformer); |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * Gets Metrics for a player |
||
146 | * |
||
147 | * @param array $player |
||
148 | * |
||
149 | * @return array |
||
150 | */ |
||
151 | public function includeMetrics($data) |
||
152 | { |
||
153 | $metrics = [ |
||
154 | 'kills' => 0, |
||
155 | 'deaths' => 0, |
||
156 | 'teamkills' => 0, |
||
157 | 'suicides' => 0, |
||
158 | 'headshots' => 0 |
||
159 | ]; |
||
160 | |||
161 | $alerts = $this->playerRepo->readAllByIdWithArchive($data['playerID'], 'playerID'); |
||
162 | $count = count($alerts); |
||
163 | $metrics['involvement'] = $count; |
||
164 | |||
165 | // Calculate metrics |
||
166 | for ($i = 0; $i < $count; $i++) { |
||
167 | $metrics['kills'] = $metrics['kills'] + $alerts[$i]['playerKills']; |
||
168 | $metrics['deaths'] = $metrics['deaths'] + $alerts[$i]['playerDeaths']; |
||
169 | $metrics['teamkills'] = $metrics['teamkills'] + $alerts[$i]['playerTeamKills']; |
||
170 | $metrics['suicides'] = $metrics['suicides'] + $alerts[$i]['playerSuicides']; |
||
171 | $metrics['headshots'] = $metrics['headshots'] + $alerts[$i]['headshots']; |
||
172 | } |
||
173 | |||
174 | return $this->item($metrics, new PlayerMetricsTransformer); |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * Get Outfit info and metrics |
||
179 | * |
||
180 | * @param array $data |
||
181 | * |
||
182 | * @return \League\Fractal\Resource\Collection |
||
183 | */ |
||
184 | public function includeOutfit($data) |
||
189 | |||
190 | /** |
||
191 | * Get Vehicle info and metrics |
||
192 | * |
||
193 | * @param array $data |
||
194 | * |
||
195 | * @return \League\Fractal\Resource\Collection |
||
196 | */ |
||
197 | public function includeVehicles($data) |
||
230 | |||
231 | /** |
||
232 | * Get Weapon info and metrics |
||
233 | * |
||
234 | * @param array $data |
||
235 | * |
||
236 | * @return \League\Fractal\Resource\Collection |
||
237 | */ |
||
238 | public function includeWeapons($data) |
||
263 | } |
||
264 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: