StepTransformer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 0 9 1
A includeTransitions() 0 8 2
1
<?php
2
3
namespace Hechoenlaravel\JarvisFoundation\Flows\Transformers;
4
5
use League\Fractal\TransformerAbstract;
6
use Hechoenlaravel\JarvisFoundation\Flows\Step;
7
8
/**
9
 * Class StepTransformer
10
 * @package Hechoenlaravel\JarvisFoundation\Flows\Transformers
11
 */
12
class StepTransformer extends TransformerAbstract
13
{
14
    protected $availableIncludes = ['transitions'];
15
16
    /**
17
     * @param Step $step
18
     * @return array
19
     */
20
    public function transform(Step $step)
21
    {
22
        return [
23
            'id' => (int) $step->id,
24
            'name' => $step->name,
25
            'description' => $step->description,
26
            'total_transitions' => $step->transitions->count()
27
        ];
28
    }
29
30
    public function includeTransitions(Step $step)
31
    {
32
        if ($step->transitions()->count() === 0) {
33
            return null;
34
        }
35
        $collection = $this->collection($step->transitions, new TransitionTransformer);
0 ignored issues
show
Documentation introduced by
new \Hechoenlaravel\Jarv...TransitionTransformer() is of type object<Hechoenlaravel\Ja...\TransitionTransformer>, 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...
36
        return $collection;
37
    }
38
}
39