AlertTransformer::__construct()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 23
nc 1
nop 11
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\VehicleTotalRepository;
15
use Ps2alerts\Api\Repository\Metrics\WeaponTotalRepository;
16
use Ps2alerts\Api\Repository\Metrics\XpRepository;
17
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 VehicleTotalRepository  $vehicleRepo
78
     * @param WeaponTotalRepository   $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
        VehicleTotalRepository  $vehicleRepo,
91
        WeaponTotalRepository   $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
            'timeBracket'  => (string) $data['ResultTimeType'],
124
            'isDraw'       => (boolean) $data['ResultDraw'],
125
            'isDomination' => (boolean) $data['ResultDomination'],
126
            'isValid'      => (boolean) $data['Valid'],
127
            'inProgress'   => (boolean) $data['InProgress'],
128
            'archived'     => (boolean) $data['Archived']
129
        ];
130
    }
131
132
    /**
133
     * Gets the Class data and then adds it to the result
134
     *
135
     * @param  array $data
136
     *
137
     * @return \League\Fractal\Resource\Collection
138
     */
139
    public function includeClasses($data)
140
    {
141
        $data = $this->classRepo->readAllById($data['ResultID'], 'result');
142
        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...
143
    }
144
145
    /**
146
     * Gets the Combat History data and then adds it to the result
147
     *
148
     * @param  array $data
149
     *
150
     * @return \League\Fractal\Resource\Collection
151
     */
152
    public function includeCombatHistorys($data)
153
    {
154
        $data = $this->combatHistoryRepo->readAllById($data['ResultID'], 'result');
155
        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...
156
    }
157
158
    /**
159
     * Gets the Combat data and then adds it to the result
160
     *
161
     * @param  array $data
162
     *
163
     * @return \League\Fractal\Resource\Item
164
     */
165
    public function includeCombats($data)
166
    {
167
        $data = $this->combatRepo->readSingleById($data['ResultID'], 'result');
168
        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...
169
    }
170
171
    /**
172
     * Gets the Class data and then adds it to the result
173
     *
174
     * @param  array $data
175
     *
176
     * @return \League\Fractal\Resource\Collection
177
     */
178
    public function includeMapInitials($data)
179
    {
180
        $data = $this->mapInitialRepo->readAllById($data['ResultID'], 'result');
181
        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...
182
    }
183
184
    /**
185
     * Gets the Map data and then adds it to the result
186
     *
187
     * @param  array $data
188
     *
189
     * @return \League\Fractal\Resource\Collection
190
     */
191
    public function includeMaps($data)
192
    {
193
        $data = $this->mapRepo->readAllById($data['ResultID'], 'result');
194
        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...
195
    }
196
197
    /**
198
     * Gets the Outfit data and then adds it to the result
199
     *
200
     * @param  array $data
201
     *
202
     * @return \League\Fractal\Resource\Collection
203
     */
204
    public function includeOutfits($data)
205
    {
206
        $data = $this->outfitRepo->readAllById($data['ResultID'], 'result');
207
        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...
208
    }
209
210
    /**
211
     * Gets the Popualtion data and then adds it to the result
212
     *
213
     * @param  array $data
214
     *
215
     * @return \League\Fractal\Resource\Collection
216
     */
217
    public function includePopulations($data)
218
    {
219
        $data = $this->populationRepo->readAllById($data['ResultID'], 'result');
220
        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...
221
    }
222
223
    /**
224
     * Gets the Player data and then adds it to the result
225
     *
226
     * @param  array $data
227
     *
228
     * @return \League\Fractal\Resource\Collection
229
     */
230
    public function includePlayers($data)
231
    {
232
        $data = $this->playerRepo->readAllById($data['ResultID'], 'result');
233
        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...
234
    }
235
236
    /**
237
     * Gets the Vehicle data and then adds it to the result
238
     *
239
     * @param  array $data
240
     *
241
     * @return \League\Fractal\Resource\Collection
242
     */
243
    public function includeVehicles($data)
244
    {
245
        $data = $this->vehicleRepo->readAllById($data['ResultID'], 'result');
246
        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...
247
    }
248
249
    /**
250
     * Gets the Weapon data and then adds it to the result
251
     *
252
     * @param  array $data
253
     *
254
     * @return \League\Fractal\Resource\Collection
255
     */
256
    public function includeWeapons($data)
257
    {
258
        $map = $this->weaponRepo->readAllById($data['ResultID'], 'result');
259
        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...
260
    }
261
262
    /**
263
     * Gets the XP data and then adds it to the result
264
     *
265
     * @param  array $data
266
     *
267
     * @return \League\Fractal\Resource\Collection
268
     */
269
    public function includeXps($data)
270
    {
271
        // NOTE TO SELF: RATE LIMIT THIS BAD BOY
272
        $map = $this->xpRepo->readAllById($data['ResultID'], 'result');
273
        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...
274
    }
275
}
276