FlowTransformer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 0 11 1
A includeSteps() 0 7 2
1
<?php
2
3
namespace Hechoenlaravel\JarvisFoundation\Flows\Transformers;
4
5
use Hechoenlaravel\JarvisFoundation\Flows\Flow;
6
use League\Fractal\TransformerAbstract;
7
8
/**
9
 * Class FlowTransformer
10
 * @package Hechoenlaravel\JarvisFoundation\Flows\Transformers
11
 */
12
class FlowTransformer extends TransformerAbstract
13
{
14
    /**
15
     * @var array
16
     */
17
    protected $availableIncludes = ['steps'];
18
19
    /**
20
     * @param Flow $flow
21
     * @return array
22
     */
23
    public function transform(Flow $flow)
24
    {
25
        return [
26
            'id' => (int) $flow->id,
27
            'name' => $flow->name,
28
            'description' => $flow->description,
29
            'created' => $flow->created_at,
30
            'updated' => $flow->updated_at,
31
            'active' => $flow->active
32
        ];
33
    }
34
35
    /**
36
     * @param Flow $flow
37
     * @return \League\Fractal\Resource\Collection|null
38
     */
39
    public function includeSteps(Flow $flow)
40
    {
41
        if ($flow->steps->count() > 0) {
42
            return $this->collection($flow->steps, new StepTransformer());
0 ignored issues
show
Documentation introduced by
new \Hechoenlaravel\Jarv...rmers\StepTransformer() is of type object<Hechoenlaravel\Ja...ormers\StepTransformer>, 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...
43
        }
44
        return null;
45
    }
46
}
47