Completed
Push — master ( 7860e0...d3b4dd )
by Matthew
02:30 queued 24s
created

AlertTransformer::includeVehicles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Ps2alerts\Api\Transformer;
4
5
use League\Fractal\TransformerAbstract;
6
use Ps2alerts\Api\Repository\Metrics\ClassRepository;
7
use Ps2alerts\Api\Repository\Metrics\CombatHistoryRepository;
8
use Ps2alerts\Api\Repository\Metrics\CombatRepository;
9
use Ps2alerts\Api\Repository\Metrics\MapInitialRepository;
10
use Ps2alerts\Api\Repository\Metrics\MapRepository;
11
use Ps2alerts\Api\Repository\Metrics\OutfitRepository;
12
use Ps2alerts\Api\Repository\Metrics\PlayerRepository;
13
use Ps2alerts\Api\Repository\Metrics\PopulationRepository;
14
use Ps2alerts\Api\Repository\Metrics\VehicleRepository;
15
use Ps2alerts\Api\Repository\Metrics\WeaponRepository;
16
use Ps2alerts\Api\Repository\Metrics\XpRepository;
17
use Ps2alerts\Api\Transformer\AlertTransformer;
18
use Ps2alerts\Api\Transformer\Metrics\ClassTransformer;
19
use Ps2alerts\Api\Transformer\Metrics\CombatHistoryTransformer;
20
use Ps2alerts\Api\Transformer\Metrics\CombatTransformer;
21
use Ps2alerts\Api\Transformer\Metrics\MapInitialTransformer;
22
use Ps2alerts\Api\Transformer\Metrics\MapTransformer;
23
use Ps2alerts\Api\Transformer\Metrics\OutfitTransformer;
24
use Ps2alerts\Api\Transformer\Metrics\PlayerTransformer;
25
use Ps2alerts\Api\Transformer\Metrics\PopulationTransformer;
26
use Ps2alerts\Api\Transformer\Metrics\VehicleTransformer;
27
use Ps2alerts\Api\Transformer\Metrics\WeaponTransformer;
28
use Ps2alerts\Api\Transformer\Metrics\XpTransformer;
29
30
class AlertTransformer extends TransformerAbstract
31
{
32
    /**
33
     * List of available includes to this resource
34
     *
35
     * @var array
36
     */
37
    protected $availableIncludes = [
38
        'classes',
39
        'combatHistorys',
40
        'combats',
41
        'mapInitials',
42
        'maps',
43
        'outfits',
44
        'players',
45
        'populations',
46
        'vehicles',
47
        'weapons',
48
        'xps'
49
    ];
50
51
    /**
52
     * Repositories
53
     */
54
    protected $classRepo;
55
    protected $combatHistoryRepo;
56
    protected $combatRepo;
57
    protected $mapInitialRepo;
58
    protected $mapRepo;
59
    protected $outfitRepo;
60
    protected $playerRepo;
61
    protected $populationRepo;
62
    protected $vehicleRepo;
63
    protected $weaponRepo;
64
    protected $xpRepo;
65
66
    /**
67
     * Constructor
68
     *
69
     * @param ClassRepository         $classRepo
70
     * @param CombatHistoryRepository $combatHistoryRepo
71
     * @param CombatRepository        $combatRepo
72
     * @param MapInitialRepository    $mapInitialRepo
73
     * @param MapRepository           $mapRepo
74
     * @param OutfitRepository        $outfitRepo
75
     * @param PlayerRepository        $playerRepo
76
     * @param PopulationRepository    $populationRepo
77
     * @param VehicleRepository       $vehicleRepo
78
     * @param WeaponRepository        $weaponRepo
79
     * @param XpRepository            $xpRepo
80
     */
81
    public function __construct(
82
        ClassRepository         $classRepo,
83
        CombatHistoryRepository $combatHistoryRepo,
84
        CombatRepository        $combatRepo,
85
        MapInitialRepository    $mapInitialRepo,
86
        MapRepository           $mapRepo,
87
        OutfitRepository        $outfitRepo,
88
        PlayerRepository        $playerRepo,
89
        PopulationRepository    $populationRepo,
90
        VehicleRepository       $vehicleRepo,
91
        WeaponRepository        $weaponRepo,
92
        XpRepository            $xpRepo
93
    ) {
94
        $this->classRepo         = $classRepo;
95
        $this->combatHistoryRepo = $combatHistoryRepo;
96
        $this->combatRepo        = $combatRepo;
97
        $this->mapInitialRepo    = $mapInitialRepo;
98
        $this->mapRepo           = $mapRepo;
99
        $this->outfitRepo        = $outfitRepo;
100
        $this->playerRepo        = $playerRepo;
101
        $this->populationRepo    = $populationRepo;
102
        $this->vehicleRepo       = $vehicleRepo;
103
        $this->weaponRepo        = $weaponRepo;
104
        $this->xpRepo            = $xpRepo;
105
    }
106
107
    /**
108
     * The tranform method required by Fractal to parse the data and return proper typing and fields.
109
     *
110
     * @param  array $data Data to transform
111
     *
112
     * @return array
113
     */
114
    public function transform($data)
115
    {
116
        return [
117
            'id'           => (int) $data['ResultID'],
118
            'started'      => (int) $data['ResultStartTime'],
119
            'ended'        => (int) $data['ResultEndTime'],
120
            'server'       => (int) $data['ResultServer'],
121
            'zone'         => (int) $data['ResultAlertCont'],
122
            'winner'       => (string) $data['ResultWinner'],
123
            'isDraw'       => (boolean) $data['ResultDraw'],
124
            'isDomination' => (boolean) $data['ResultDomination'],
125
            'isValid'      => (boolean) $data['Valid'],
126
            'inProgress'   => (boolean) $data['InProgress']
127
        ];
128
    }
129
130
    /**
131
     * Gets the Class data and then adds it to the result
132
     *
133
     * @param  array $data
134
     *
135
     * @return \League\Fractal\Resource\Collection
136
     */
137
    public function includeClasses($data)
138
    {
139
        $data = $this->classRepo->readAllById($data['ResultID'], 'result');
140
        return $this->collection($data, new ClassTransformer);
0 ignored issues
show
Documentation introduced by
new \Ps2alerts\Api\Trans...rics\ClassTransformer() is of type object<Ps2alerts\Api\Tra...trics\ClassTransformer>, but the function expects a callable.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
141
    }
142
143
    /**
144
     * Gets the Combat History data and then adds it to the result
145
     *
146
     * @param  array $data
147
     *
148
     * @return \League\Fractal\Resource\Collection
149
     */
150
    public function includeCombatHistorys($data)
151
    {
152
        $data = $this->combatHistoryRepo->readAllById($data['ResultID'], 'result');
153
        return $this->collection($data, new CombatHistoryTransformer);
0 ignored issues
show
Documentation introduced by
new \Ps2alerts\Api\Trans...batHistoryTransformer() is of type object<Ps2alerts\Api\Tra...mbatHistoryTransformer>, but the function expects a callable.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
154
    }
155
156
    /**
157
     * Gets the Combat data and then adds it to the result
158
     *
159
     * @param  array $data
160
     *
161
     * @return \League\Fractal\Resource\Item
162
     */
163
    public function includeCombats($data)
164
    {
165
        $data = $this->combatRepo->readSingleById($data['ResultID'], 'result');
166
        return $this->item($data, new CombatTransformer);
0 ignored issues
show
Documentation introduced by
new \Ps2alerts\Api\Trans...ics\CombatTransformer() is of type object<Ps2alerts\Api\Tra...rics\CombatTransformer>, but the function expects a callable.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
167
    }
168
169
    /**
170
     * Gets the Class data and then adds it to the result
171
     *
172
     * @param  array $data
173
     *
174
     * @return \League\Fractal\Resource\Collection
175
     */
176
    public function includeMapInitials($data)
177
    {
178
        $data = $this->mapInitialRepo->readAllById($data['ResultID'], 'result');
179
        return $this->collection($data, new MapInitialTransformer);
0 ignored issues
show
Documentation introduced by
new \Ps2alerts\Api\Trans...MapInitialTransformer() is of type object<Ps2alerts\Api\Tra...\MapInitialTransformer>, but the function expects a callable.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
180
    }
181
182
    /**
183
     * Gets the Map data and then adds it to the result
184
     *
185
     * @param  array $data
186
     *
187
     * @return \League\Fractal\Resource\Collection
188
     */
189
    public function includeMaps($data)
190
    {
191
        $data = $this->mapRepo->readAllById($data['ResultID'], 'result');
192
        return $this->collection($data, new MapTransformer);
0 ignored issues
show
Documentation introduced by
new \Ps2alerts\Api\Trans...etrics\MapTransformer() is of type object<Ps2alerts\Api\Tra...Metrics\MapTransformer>, but the function expects a callable.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
193
    }
194
195
    /**
196
     * Gets the Outfit data and then adds it to the result
197
     *
198
     * @param  array $data
199
     *
200
     * @return \League\Fractal\Resource\Collection
201
     */
202
    public function includeOutfits($data)
203
    {
204
        $data = $this->outfitRepo->readAllById($data['ResultID'], 'result');
205
        return $this->collection($data, new OutfitTransformer);
0 ignored issues
show
Documentation introduced by
new \Ps2alerts\Api\Trans...ics\OutfitTransformer() is of type object<Ps2alerts\Api\Tra...rics\OutfitTransformer>, but the function expects a callable.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
206
    }
207
208
    /**
209
     * Gets the Popualtion data and then adds it to the result
210
     *
211
     * @param  array $data
212
     *
213
     * @return \League\Fractal\Resource\Collection
214
     */
215
    public function includePopulations($data)
216
    {
217
        $data = $this->populationRepo->readAllById($data['ResultID'], 'result');
218
        return $this->collection($data, new PopulationTransformer);
0 ignored issues
show
Documentation introduced by
new \Ps2alerts\Api\Trans...PopulationTransformer() is of type object<Ps2alerts\Api\Tra...\PopulationTransformer>, but the function expects a callable.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
219
    }
220
221
    /**
222
     * Gets the Player data and then adds it to the result
223
     *
224
     * @param  array $data
225
     *
226
     * @return \League\Fractal\Resource\Collection
227
     */
228
    public function includePlayers($data)
229
    {
230
        $data = $this->playerRepo->readAllById($data['ResultID'], 'result');
231
        return $this->collection($data, new PlayerTransformer);
0 ignored issues
show
Documentation introduced by
new \Ps2alerts\Api\Trans...ics\PlayerTransformer() is of type object<Ps2alerts\Api\Tra...rics\PlayerTransformer>, but the function expects a callable.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
232
    }
233
234
    /**
235
     * Gets the Vehicle data and then adds it to the result
236
     *
237
     * @param  array $data
238
     *
239
     * @return \League\Fractal\Resource\Collection
240
     */
241
    public function includeVehicles($data)
242
    {
243
        $data = $this->vehicleRepo->readAllById($data['ResultID'], 'result');
244
        return $this->collection($data, new VehicleTransformer);
0 ignored issues
show
Documentation introduced by
new \Ps2alerts\Api\Trans...cs\VehicleTransformer() is of type object<Ps2alerts\Api\Tra...ics\VehicleTransformer>, but the function expects a callable.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
245
    }
246
247
    /**
248
     * Gets the Weapon data and then adds it to the result
249
     *
250
     * @param  array $data
251
     *
252
     * @return \League\Fractal\Resource\Collection
253
     */
254
    public function includeWeapons($data)
255
    {
256
        $map = $this->weaponRepo->readAllById($data['ResultID'], 'result');
257
        return $this->collection($map, new WeaponTransformer);
0 ignored issues
show
Documentation introduced by
new \Ps2alerts\Api\Trans...ics\WeaponTransformer() is of type object<Ps2alerts\Api\Tra...rics\WeaponTransformer>, but the function expects a callable.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
258
    }
259
260
    /**
261
     * Gets the XP data and then adds it to the result
262
     *
263
     * @param  array $data
264
     *
265
     * @return \League\Fractal\Resource\Collection
266
     */
267
    public function includeXps($data)
268
    {
269
        // NOTE TO SELF: RATE LIMIT THIS BAD BOY
270
        $map = $this->xpRepo->readAllById($data['ResultID'], 'result');
271
        return $this->collection($map, new XpTransformer);
0 ignored issues
show
Documentation introduced by
new \Ps2alerts\Api\Trans...Metrics\XpTransformer() is of type object<Ps2alerts\Api\Tra...\Metrics\XpTransformer>, but the function expects a callable.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
272
    }
273
}
274