Passed
Push — 1.0 ( 3459b6...bea942 )
by Provinsi
02:17
created

LaravelOpd::tree()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 7
Ratio 53.85 %

Importance

Changes 0
Metric Value
dl 7
loc 13
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 1
nop 0
1
<?php 
2
3
namespace Bantenprov\LaravelOpd;
4
5
use Bantenprov\LaravelOpd\Models\LaravelOpdModel;
6
use Illuminate\Http\Request;
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
/**
8
 * The LaravelOpd class.
9
 *
10
 * @package Bantenprov\LaravelOpd
11
 * @author  bantenprov <[email protected]>
12
 */
13
class LaravelOpd
14
{
15
    protected $opd_model;
16
    
17
    public function __construct()
18
    {        
19
        $this->opd_model = new LaravelOpdModel();
20
    }
21
22
    public function welcome()
23
    {
24
        return 'Welcome to Bantenprov\LaravelOpd package';
25
    }
26
27
    public function index()
28
    {
29
        return $opds = LaravelOpdModel::all();                               
0 ignored issues
show
Unused Code introduced by
The assignment to $opds is dead and can be removed.
Loading history...
30
31
        //return view('unit_kerja.index',compact('opds'));
32
        
33
    }
34
35
    public function tree()
36
    {
37
        $nodes = LaravelOpdModel::get()->toTree();
38
        
39 View Code Duplication
        $traverse = function ($categories, $prefix = '-') use (&$traverse) {
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...
40
            foreach ($categories as $category) {
41
                echo $prefix.' '.$category->kunker.' - '.$category->name.'<br>';
42
        
43
                $traverse($category->children, $prefix.'-');
44
            }
45
        };
46
        
47
        return $traverse($nodes); 
48
    }
49
50
    public function createRoot()
51
    {
52
53
        return view('unit_kerja.create-root');
0 ignored issues
show
Bug introduced by
The function view was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        return /** @scrutinizer ignore-call */ view('unit_kerja.create-root');
Loading history...
54
    }
55
56
    public function createChild()
57
    {
58
        return $unit_kerjas = LaravelOpdModel::all();
0 ignored issues
show
Unused Code introduced by
The assignment to $unit_kerjas is dead and can be removed.
Loading history...
59
60
        //return view('unit_kerja.create-child',compact('unit_kerjas'));
61
    }
62
63
    public function addChild($id)
64
    {
65
        return $unit_kerja = LaravelOpdModel::where('id',$id)->first();
0 ignored issues
show
Unused Code introduced by
The assignment to $unit_kerja is dead and can be removed.
Loading history...
66
67
        //return view('unit_kerja.add-child',compact('unit_kerja'));
68
    }
69
    
70 View Code Duplication
    public function storeRoot($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...
71
    {        
72
        $check_root = LaravelOpdModel::where('id',$request->root);
73
        
74
        if($check_root->first()->isEmpty())
75
        {                        
76
77
            $unit_kerja = LaravelOpdModel::create([
0 ignored issues
show
Unused Code introduced by
The assignment to $unit_kerja is dead and can be removed.
Loading history...
78
                'kunker' => $request->kunker,
79
                'kunker_simral' => '',
80
                'name' => $request->name,
81
                'levelunker' => $request->levelunker,
82
            ]);
83
        }
84
        else
85
        {
86
            return redirect()->back();
0 ignored issues
show
Bug introduced by
The function redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

86
            return /** @scrutinizer ignore-call */ redirect()->back();
Loading history...
87
        }
88
89
        
90
91
        return redirect()->back();
92
    }
93
94 View Code Duplication
    public function storeChild($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...
95
    {
96
        $check_root = LaravelOpdModel::where('id',$request->root);
97
                          
98
            $check_root->first()->children()->create([
99
                'kunker' => $request->c_kunker,
100
                'kunker_simral' => '',
101
                'name' => $request->c_name,
102
                'levelunker' => $request->c_levelunker,
103
            ]);        
104
105
        return redirect()->back();
0 ignored issues
show
Bug introduced by
The function redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
        return /** @scrutinizer ignore-call */ redirect()->back();
Loading history...
106
    }
107
}
108