PortTransformer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 0 12 1
A includeDevice() 0 5 1
1
<?php
2
namespace App\Api\Transformers;
3
4
use App\Models\Port;
5
use League\Fractal;
6
7
class PortTransformer extends Fractal\TransformerAbstract
8
{
9
10
    /**
11
     * List of resources possible to include
12
     *
13
     * @var array
14
     */
15
    protected $availableIncludes = ['device'];
16
17
    /**
18
     * Turn this item object into a generic array
19
     *
20
     * @return array
21
     */
22
    public function transform(Port $port)
23
    {
24
        return [
25
            'id'                        => (int) $port->port_id,
26
            'alias'                     => $port->ifAlias,
27
            'speed'                     => (int) $port->ifSpeed,
28
            'out_unicast_pkts_delta'    => (int) $port->ifOutUcastPkts_delta,
29
            'in_unicast_pkts_delta'     => (int) $port->ifInUcastPkts_delta,
30
            'type'                      => $port->ifType,
31
            'description'               => $port->ifDescr,
32
        ];
33
    }
34
35
    /**
36
     * Include Device
37
     *
38
     * @return Fractal\Resource\Item
39
     */
40
    public function includeDevice(Port $port)
41
    {
42
        $device = $port->device;
43
        return $this->item($device, new DeviceTransformer);
0 ignored issues
show
Documentation introduced by
new \App\Api\Transformers\DeviceTransformer() is of type object<App\Api\Transformers\DeviceTransformer>, 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...
44
    }
45
}
46