Passed
Branch 1.0 (908540)
by Provinsi
03:23
created

LaravelOpdController::storeRoot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 10

Duplication

Lines 22
Ratio 100 %

Importance

Changes 0
Metric Value
dl 22
loc 22
rs 9.2
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 1
1
<?php namespace Bantenprov\LaravelOpd\Http\Controllers;
2
3
use App\Http\Controllers\Controller;
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Controller 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...
4
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...
5
use Bantenprov\LaravelOpd\Facades\LaravelOpd;
6
use Bantenprov\LaravelOpd\Models\LaravelOpdModel;
7
8
/**
9
 * The LaravelOpdController class.
10
 *
11
 * @package Bantenprov\LaravelOpd
12
 * @author  bantenprov <[email protected]>
13
 */
14
class LaravelOpdController extends Controller
15
{
16
    public function demo()
17
    {
18
        return LaravelOpd::welcome();
0 ignored issues
show
Bug introduced by
The method welcome() does not exist on Bantenprov\LaravelOpd\Facades\LaravelOpd. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

18
        return LaravelOpd::/** @scrutinizer ignore-call */ welcome();
Loading history...
19
    }
20
21
    public function index()
22
    {
23
        $opds = LaravelOpdModel::all();                
24
25
        $nodes = LaravelOpdModel::get()->toTree();
26
        
27 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...
28
            foreach ($categories as $category) {
29
                echo $prefix.' '.$category->kunker.' - '.$category->name.'<br>';
30
        
31
                $traverse($category->children, $prefix.'-');
32
            }
33
        };
34
        
35
        $traverse($nodes);        
36
37
        return view('laravel-opd::unit_kerja.index',compact('opds'));
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

37
        return /** @scrutinizer ignore-call */ view('laravel-opd::unit_kerja.index',compact('opds'));
Loading history...
38
        
39
    }
40
41
    public function createRoot()
42
    {
43
44
        return view('laravel-opd::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

44
        return /** @scrutinizer ignore-call */ view('laravel-opd::unit_kerja.create-root');
Loading history...
45
    }
46
47
    public function createChild()
48
    {
49
        $unit_kerjas = LaravelOpdModel::all();
50
51
        return view('laravel-opd::unit_kerja.create-child',compact('unit_kerjas'));
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

51
        return /** @scrutinizer ignore-call */ view('laravel-opd::unit_kerja.create-child',compact('unit_kerjas'));
Loading history...
52
    }
53
54
    public function addChild($id)
55
    {
56
        $unit_kerja = LaravelOpdModel::where('id',$id)->first();
57
58
        return view('laravel-opd::unit_kerja.add-child',compact('unit_kerja'));
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

58
        return /** @scrutinizer ignore-call */ view('laravel-opd::unit_kerja.add-child',compact('unit_kerja'));
Loading history...
59
    }
60
    
61 View Code Duplication
    public function storeRoot(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...
62
    {        
63
        $check_root = LaravelOpdModel::where('id',$request->root);
64
        
65
        if($check_root->get()->isEmpty())
66
        {                        
67
68
            $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...
69
                'kunker' => $request->kunker,
70
                'kunker_simral' => '',
71
                'name' => $request->name,
72
                'levelunker' => $request->levelunker,
73
            ]);
74
        }
75
        else
76
        {
77
            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

77
            return /** @scrutinizer ignore-call */ redirect()->back();
Loading history...
78
        }
79
80
        
81
82
        return redirect()->back();
83
    }
84
85 View Code Duplication
    public function storeChild(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...
86
    {
87
        $check_root = LaravelOpdModel::where('id',$request->root);
88
                          
89
            $check_root->first()->children()->create([
90
                'kunker' => $request->c_kunker,
91
                'kunker_simral' => '',
92
                'name' => $request->c_name,
93
                'levelunker' => $request->c_levelunker,
94
            ]);        
95
96
        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

96
        return /** @scrutinizer ignore-call */ redirect()->back();
Loading history...
97
    }
98
}
99