TransitionController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 10 1
A destroy() 0 5 1
1
<?php
2
3
namespace Hechoenlaravel\JarvisFoundation\Http\Controllers\Core;
4
5
use Hechoenlaravel\JarvisFoundation\Flows\Flow;
6
use Hechoenlaravel\JarvisFoundation\Flows\Step;
7
use Hechoenlaravel\JarvisFoundation\Http\Requests;
8
use Hechoenlaravel\JarvisFoundation\Flows\Transition;
9
use Hechoenlaravel\JarvisFoundation\Traits\FlowManager;
10
use Hechoenlaravel\JarvisFoundation\Http\Controllers\Controller;
11
use Hechoenlaravel\JarvisFoundation\Flows\Transformers\TransitionTransformer;
12
13
/**
14
 * Class TransitionController
15
 * @package Hechoenlaravel\JarvisFoundation\Http\Controllers\Core
16
 */
17
class TransitionController extends Controller
18
{
19
    use FlowManager;
20
21
    /**
22
     * @param Requests\TransitionRequest $request
23
     * @return \Illuminate\Http\JsonResponse
24
     */
25
    public function store(Requests\TransitionRequest $request)
26
    {
27
        $transition = $this->createTransition([
28
            'flow' => Flow::find($request->get('flow_id')),
29
            'from' => Step::find($request->get('from')),
30
            'to' => Step::find($request->get('to'))
31
        ]);
32
        $response = fractal()->item($transition, new TransitionTransformer())->toArray();
33
        return response()->json($response);
0 ignored issues
show
Bug introduced by
It seems like $response defined by fractal()->item($transit...ansformer())->toArray() on line 32 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...
34
    }
35
36
    /**
37
     * @param $id
38
     * @return \Illuminate\Http\JsonResponse
39
     */
40
    public function destroy($id)
41
    {
42
        $this->deleteTransition(Transition::findOrFail($id));
43
        return response()->json(null, 204);
44
    }
45
}
46