FlowController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 6
dl 0
loc 38
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A destroy() 0 5 1
A store() 0 6 1
A update() 0 6 1
1
<?php
2
3
namespace Hechoenlaravel\JarvisFoundation\Http\Controllers\Core;
4
5
use Hechoenlaravel\JarvisFoundation\Flows\Flow;
6
use Hechoenlaravel\JarvisFoundation\Http\Requests;
7
use Hechoenlaravel\JarvisFoundation\Traits\FlowManager;
8
use Hechoenlaravel\JarvisFoundation\Http\Controllers\Controller;
9
use Hechoenlaravel\JarvisFoundation\Flows\Transformers\FlowTransformer;
10
11
/**
12
 * Class FlowController
13
 * @package Hechoenlaravel\JarvisFoundation\Http\Controllers\Core
14
 */
15
class FlowController extends Controller
16
{
17
    use FlowManager;
18
19
20
    /**
21
     * @param Requests\FlowRequest $request
22
     * @return mixed
23
     */
24
    public function store(Requests\FlowRequest $request)
25
    {
26
        $flow = $this->createFlow($request->all());
27
        $response = fractal()->item($flow, new FlowTransformer)->toArray();
28
        return response()->json($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by fractal()->item($flow, n...ansformer())->toArray() on line 27 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...
29
    }
30
31
    /**
32
     * @param Requests\FlowRequest $request
33
     * @param $id
34
     * @return mixed
35
     */
36
    public function update(Requests\FlowRequest $request, $id)
37
    {
38
        $flow = $this->updateFlow(Flow::findOrFail($id), $request->all());
39
        $response = fractal()->item($flow, new FlowTransformer)->toArray();
40
        return response()->json($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by fractal()->item($flow, n...ansformer())->toArray() on line 39 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...
41
    }
42
43
    /**
44
     * @param $id
45
     * @return mixed
46
     */
47
    public function destroy($id)
48
    {
49
        $this->deleteFlow(Flow::findOrFail($id));
50
        return response()->json(null, 204);
51
    }
52
}
53