WorkflowTransitionController::store()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
1
<?php
2
3
namespace Jawaraegov\Workflows\Http\Controllers;
4
5
use App\Http\Controllers\Controller;
6
use Illuminate\Http\Request;
7
use Jawaraegov\Workflows\Facades\Workflow;
8
use Jawaraegov\Workflows\Models\WorkflowTransition;
9
use Jawaraegov\Workflows\Models\WorkflowState;
10
use That0n3guy\Transliteration;
11
12
class WorkflowTransitionController extends Controller
13
{
14
    
15
    public function index()
16
    {
17
18
        $transitions = WorkflowTransition::paginate(10);
19
        $state = array();
0 ignored issues
show
Unused Code introduced by
$state is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
20
  
21
        return view('workflow.transition.index',compact('transitions'));
22
    }
23
    
24
    public function create()
25
    {
26
        $states = WorkflowState::all();
27
        
28
        return view('workflow.transition.create',compact('states'));
29
    }
30
31
    public function store(Request $request)
32
    {
33
        $name = str_replace('_','-',\Transliteration::clean_filename(strtolower($request->label)));
34
        $label = $request->label;
35
        $from = $request->from;
36
        $to = $request->to;
37
        $message = $request->message;
38
39
        try
40
        {
41
            WorkflowTransition::create([
42
                            'name' => $name,
43
                            'label' => $label,
44
                    'from' => $from,
45
                    'to' => $to,
46
                    'message' => $message
47
                ]);
48
        }
49
        catch(\Illuminate\Database\QueryException $e){
0 ignored issues
show
Bug introduced by
The class Illuminate\Database\QueryException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
50
            // do what you want here with $e->getMessage();
51
            return redirect()->route('transition')->with('message', 'Error');
52
        }
53
54
    	return redirect()->route('transition')->with('message', 'Add data success');
55
    }
56
57
    public function show($id)
58
    {
59
        //
60
    }
61
62 View Code Duplication
    public function edit($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64
        $transition = WorkflowTransition::where('id',$id)->first();
65
        $states = WorkflowState::all();
66
67
        return view('workflow.transitionedit',['transition' => $transition, 'states' => $states]);
68
    }
69
70 View Code Duplication
    public function update(Request $request, $id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
    {
72
        $name = str_replace('_','-',\Transliteration::clean_filename(strtolower($request->label)));
73
        $label = $request->label;
74
        $from = $request->from;
75
        $to = $request->to;
76
77
        try
78
        {
79
          WorkflowTransition::where('id',$id)->update([
80
                                                      'label' => $label,
81
                                                      'name' => $name,
82
                                                      'from' => $from,
83
                                                      'to' => $to
84
                                                    ]);
85
        }
86
        catch(\Illuminate\Database\QueryException $e){
0 ignored issues
show
Bug introduced by
The class Illuminate\Database\QueryException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
87
            // do what you want here with $e->getMessage();
88
            return redirect()->route('transition')->with('message', 'Error');
89
        }
90
91
92
93
        return redirect()->route('transition')->with('message', 'Update data success');
94
    }
95
96
    public function Active($id){
97
        WorkflowTransition::where('id',$id)->update(['status' => 1]);
98
99
        return redirect()->back();
100
    }
101
102
    public function DeActive($id){
103
        WorkflowTransition::where('id',$id)->update(['status' => 0]);
104
105
        return redirect()->back();
106
    }
107
108
    public function destroy($id)
109
    {
110
        //
111
    }
112
}
113