StepController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 8
dl 0
loc 53
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 9 2
A store() 0 8 1
A update() 0 6 1
A destroy() 0 5 1
1
<?php
2
3
namespace Hechoenlaravel\JarvisFoundation\Http\Controllers\Core;
4
5
use Illuminate\Http\Request;
6
use Hechoenlaravel\JarvisFoundation\Flows\Flow;
7
use Hechoenlaravel\JarvisFoundation\Flows\Step;
8
use Hechoenlaravel\JarvisFoundation\Http\Requests;
9
use Hechoenlaravel\JarvisFoundation\Traits\FlowManager;
10
use Hechoenlaravel\JarvisFoundation\Http\Controllers\Controller;
11
use Hechoenlaravel\JarvisFoundation\Flows\Transformers\StepTransformer;
12
13
/**
14
 * Class StepController
15
 * @package Hechoenlaravel\JarvisFoundation\Http\Controllers\Core
16
 */
17
class StepController extends Controller
18
{
19
    use FlowManager;
20
21
    /**
22
     * @param Request $request
23
     * @return \Illuminate\Http\JsonResponse
24
     */
25
    public function index(Request $request)
26
    {
27
        $step = Step::with('transitions')->orderBy('order', 'asc');
28
        if ($request->has('flow_id')) {
29
            $step->where('flow_id', $request->get('flow_id'));
30
        }
31
        $response = fractal()->collection($step->get(), new StepTransformer())->toArray();
32
        return response()->json($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by fractal()->collection($s...ansformer())->toArray() on line 31 can also be of type null; however, Illuminate\Contracts\Rou...ResponseFactory::json() does only seem to accept string|array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
33
    }
34
35
    /**
36
     * @param Requests\StepRequest $request
37
     * @return \Illuminate\Http\JsonResponse
38
     */
39
    public function store(Requests\StepRequest $request)
40
    {
41
        $input = $request->only(['flow_id', 'name', 'description']);
42
        $input['flow'] = Flow::find($input['flow_id']);
43
        $step = $this->createStep($input);
44
        $response = fractal()->item($step, new StepTransformer())->toArray();
45
        return response()->json($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by fractal()->item($step, n...ansformer())->toArray() on line 44 can also be of type null; however, Illuminate\Contracts\Rou...ResponseFactory::json() does only seem to accept string|array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
46
    }
47
48
    /**
49
     * @param Requests\StepRequest $request
50
     * @param $id
51
     * @return \Illuminate\Http\JsonResponse
52
     */
53
    public function update(Requests\StepRequest $request, $id)
54
    {
55
        $step = $this->updateStep(Step::findOrFail($id), $request->all());
56
        $response = fractal()->item($step, new StepTransformer())->toArray();
57
        return response()->json($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by fractal()->item($step, n...ansformer())->toArray() on line 56 can also be of type null; however, Illuminate\Contracts\Rou...ResponseFactory::json() does only seem to accept string|array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
58
    }
59
60
    /**
61
     * @param $id
62
     * @return \Illuminate\Http\JsonResponse
63
     */
64
    public function destroy($id)
65
    {
66
        $this->deleteStep(Step::findOrFail($id));
67
        return response()->json(null, 204);
68
    }
69
}
70