WorkflowController::demo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php namespace Jawaraegov\Workflows\Http\Controllers;
2
3
use App\Http\Controllers\Controller;
4
use Illuminate\Http\Request;
5
use Jawaraegov\Workflows\Facades\Workflow;
6
use Jawaraegov\Workflows\Models\WorkflowModel;
7
use Jawaraegov\Workflows\Models\WorkflowTransition;
8
use Jawaraegov\Workflows\Models\WorkflowState;
9
use That0n3guy\Transliteration;
10
11
/**
12
 * The WorkflowController class.
13
 *
14
 * @package Jawaraegov\Workflows
15
 * @author  Jawaraegov <[email protected]>
16
 */
17
class WorkflowController extends Controller
18
{
19
    public function demo()
20
    {
21
        return Workflow::welcome();
22
    }
23
24
    public function index()
25
    {
26
        $workflows = WorkflowModel::paginate(10);
27
        return view('workflow.workflow.index',compact('workflows'));
28
    }
29
30
    public function create()
31
    {
32
      $dir = base_path('/app');
33
      $files = scandir($dir);
34
35
      $models = array();
36
      $namespace = 'App\\';
37 View Code Duplication
      foreach($files as $file) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
38
        // skip current and parent folder entries and non-php files
39
        if (preg_match("/.php/",$file)){
40
      		$models[] = $namespace . preg_replace("/.php/", "", $file);
41
      	}
42
      }
43
      return view('workflow.workflow.create',compact('models'));
44
    }
45
46
    public function store(Request $request)
47
    {
48
        $name = \Transliteration::clean_filename(strtolower($request->label));
49
        $label = $request->label;
50
        $content_type = $request->content_type;
0 ignored issues
show
Bug introduced by
The property content_type does not seem to exist. Did you mean content?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
51
52
        try
53
        {
54
            WorkflowModel::create([
55
                            'name' => $name,
56
                            'label' => $label,
57
                            'content_type' => $content_type
58
                ]);
59
        }
60
        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...
61
            // do what you want here with $e->getMessage();
62
            return redirect()->route('workflow')->with('message', 'Error');
63
        }
64
65
        return redirect()->route('workflow')->with('message', 'Add data success');
66
    }
67
68
    public function show($id)
69
    {
70
        //
71
    }
72
73
    public function edit($id)
74
    {
75
        $dir = base_path('/app');
76
        $files = scandir($dir);
77
78
        $models = array();
79
        $namespace = 'App\\';
80 View Code Duplication
        foreach($files as $file) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
81
          // skip current and parent folder entries and non-php files
82
          if (preg_match("/.php/",$file)){
83
        		$models[] = $namespace . preg_replace("/.php/", "", $file);
84
        	}
85
        }
86
        $workflow = WorkflowModel::where('id',$id)->first();
87
88
        return view('workflow.workflow.edit',compact('workflow','models'));
89
    }
90
91
    public function update(Request $request, $id)
92
    {
93
        $name = \Transliteration::clean_filename(strtolower($request->label));
94
        $label = $request->label;
95
        $content_type = $request->content_type;
0 ignored issues
show
Bug introduced by
The property content_type does not seem to exist. Did you mean content?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
96
97
        try
98
        {
99
          WorkflowModel::where('id',$id)->update(['label' => $label, 'name' => $name, 'content_type' => $content_type]);
100
        }
101
        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...
102
            // do what you want here with $e->getMessage();
103
            return redirect()->route('workflow')->with('message', 'Error');
104
        }
105
106
        return redirect()->route('workflow')->with('message', 'Update data success');
107
    }
108
}
109