FlowTransformer::includeSteps()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
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