WorkflowStateTrait::stateIndex()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Jawaraegov\Workflows\Traits;
4
5
use Illuminate\Database\Eloquent\Model;
6
use App\Http\Controllers\Controller;
7
use Illuminate\Http\Request;
8
use Jawaraegov\Workflows\Facades\Workflow;
9
use Jawaraegov\Workflows\Models\WorkflowTransition;
10
use Jawaraegov\Workflows\Models\WorkflowState;
11
use That0n3guy\Transliteration;
12
13
trait WorkflowStateTrait
14
{
15
    public static function stateIndex($page = 10)
16
    {
17
        $states = WorkflowState::paginate($page);
18
                        
19
        return view('workflow::workflow.state.index',compact('states'));
20
    }
21
    
22
    public static function stateCreate()
23
    {
24
        return view('workflow::workflow.state.create');
25
    }
26
    
27 View Code Duplication
    public static function stateStore($request  = array())
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 static function stateEdit($id)
48
    {
49
        $state = WorkflowState::where('id',$id)->first();
50
        
51
        return view('workflow::workflow.state.edit',['state' => $state]);
52
    }
53
    
54 View Code Duplication
    public static function stateUpdate($request  = array(), $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...
55
    {
56
        $name = \Transliteration::clean_filename(strtolower($request->label));
57
        $label = $request->label;
58
59
        try
60
        {
61
          WorkflowState::where('id',$id)->update(['label' => $label, 'name' => $name]);
62
        }
63
        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...
64
            // do what you want here with $e->getMessage();
65
            return redirect()->route('state')->with('message', 'Error');
66
        }
67
68
        return redirect()->route('state')->with('message', 'Update data success');
69
    }
70
71
    public static function stateActive($id){
72
        WorkflowState::where('id',$id)->update(['status' => 1]);
73
74
        return redirect()->back();
75
    }
76
77
    public static function stateDeActive($id){
78
        WorkflowState::where('id',$id)->update(['status' => 0]);
79
80
        return redirect()->back();
81
    }        
82
}
83