Test Failed
Push — 1.1 ( 3ddbea...e6402b )
by
unknown
02:29 queued 23s
created

LaravelOpdController::storeRoot()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 14

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 23
loc 23
rs 9.0856
cc 2
eloc 14
nc 2
nop 1
1
<?php
2
namespace Bantenprov\LaravelOpd\Http\Controllers;
3
4
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...
5
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...
6
use Bantenprov\LaravelOpd\Facades\LaravelOpd;
7
use Bantenprov\LaravelOpd\Models\LaravelOpdModel;
8
9
/**
10
 * The LaravelOpdController class.
11
 *
12
 * @package Bantenprov\LaravelOpd
13
 * @author  bantenprov <[email protected]>
14
 */
15
class LaravelOpdController extends Controller
16
{
17
    public function demo()
18
    {
19
        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

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

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

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

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

61
        return /** @scrutinizer ignore-call */ view('laravel-opd::unit_kerja.add-child',compact('unit_kerja'));
Loading history...
62
    }
63
64 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...
65
    {
66
        $check_root = LaravelOpdModel::where('id',$request->root);
67
68
        if($check_root->get()->isEmpty())
69
        {
70
            $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...
71
                'kunker' => $request->kunker,
72
                'kunker_sinjab' => '',
73
                'kunker_simral' => '',
74
                'kunker_sinjab' => '',
75
                'name' => $request->name,
76
                'levelunker' => $request->levelunker,
77
                'njab' => $request->njab,
78
                'npej' => $request->npej
79
            ]);
80
        }
81
        else
82
        {
83
            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

83
            return /** @scrutinizer ignore-call */ redirect()->back();
Loading history...
84
        }
85
86
        return redirect()->back();
87
    }
88
89
    public function storeChild(Request $request)
90
    {
91
        $check_root = LaravelOpdModel::where('id',$request->root);
92
93
            $check_root->first()->children()->create([
94
                'kunker' => $request->c_kunker,
95
                'kunker_simral' => '',
96
                'kunker_sinjab' => '',
97
                'name' => $request->c_name,
98
                'levelunker' => $request->c_levelunker,
99
                'njab' => $request->c_njab,
100
                'npej' => $request->c_npej
101
            ]);
102
103
        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

103
        return /** @scrutinizer ignore-call */ redirect()->back();
Loading history...
104
    }
105
}