WorkflowStateController::update()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 16
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 2
dl 16
loc 16
rs 9.4285
1
<?php
2
3
namespace Bantenprov\Workflow\Http\Controllers;
4
5
use App\Http\Controllers\Controller;
6
use Illuminate\Http\Request;
7
use Bantenprov\Workflow\Facades\Workflow;
8
use Bantenprov\Workflow\Models\WorkflowTransition;
9
use Bantenprov\Workflow\Models\WorkflowState;
10
use That0n3guy\Transliteration;
11
12
class WorkflowStateController extends Controller
13
{
14
    
15
    public function index()
16
    {
17
        $states = WorkflowState::paginate(10);
18
                        
19
        return view('workflow.state.index',compact('states'));
20
    }
21
    
22
    public function create()
23
    {
24
        return view('workflow.state.create');
25
    }
26
    
27 View Code Duplication
    public function store(Request $request)
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...
28
    {
29
        $name = \Transliteration::clean_filename(strtolower($request->label));
30
        $label = $request->label;
31
32
        try
33
        {
34
            WorkflowState::create([
35
                            'name' => $name,
36
                            'label' => $label,
37
                ]);
38
        }
39
        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...
40
            // do what you want here with $e->getMessage();
41
            return redirect()->route('state')->with('message', 'Error');
42
        }
43
44
        return redirect()->route('state')->with('message', 'Add data success');
45
    }
46
    
47
    public function show($id)
48
    {
49
        //
50
    }
51
    
52
    public function edit($id)
53
    {
54
        $state = WorkflowState::where('id',$id)->first();
55
        
56
        return view('workflow.state.edit',['state' => $state]);
57
    }
58
    
59 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...
60
    {
61
        $name = \Transliteration::clean_filename(strtolower($request->label));
62
        $label = $request->label;
63
64
        try
65
        {
66
          WorkflowState::where('id',$id)->update(['label' => $label, 'name' => $name]);
67
        }
68
        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...
69
            // do what you want here with $e->getMessage();
70
            return redirect()->route('state')->with('message', 'Error');
71
        }
72
73
        return redirect()->route('state')->with('message', 'Update data success');
74
    }
75
76
    public function Active($id){
77
        WorkflowState::where('id',$id)->update(['status' => 1]);
78
79
        return redirect()->back();
80
    }
81
82
    public function DeActive($id){
83
        WorkflowState::where('id',$id)->update(['status' => 0]);
84
85
        return redirect()->back();
86
    }
87
    
88
    public function destroy($id)
89
    {
90
        //
91
    }
92
}
93