Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( b393e2...607f68 )
by Cristian
02:55
created

CrudNestedController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 113
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 113
loc 113
rs 10
c 1
b 0
f 0
wmc 8
lcom 1
cbo 5

7 Methods

Rating   Name   Duplication   Size   Complexity  
A ToneCrudNestedController::__construct() 5 5 1
A ToneCrudNestedController::index() 7 7 1
A ToneCrudNestedController::create() 7 7 1
A ToneCrudNestedController::crudStore() 9 9 1
A ToneCrudNestedController::show() 7 7 1
A ToneCrudNestedController::edit() 9 9 1
A ToneCrudNestedController::crudUpdate() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * The Crud Controller.
4
 */
5
namespace Backpack\Crud\Http\Controllers;
6
7
use Backpack\Crud\Crud;
8
use Illuminate\Routing\Controller as BaseController;
9
10
/**
11
 * The controller that handles all the crud actions.
12
 */
13 View Code Duplication
class ToneCrudNestedController extends BaseController
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
    protected $crud;
16
    protected $data;
17
18
    public function __construct()
19
    {
20
        $this->crud = new Crud();
21
        $this->data = [];
22
    }
23
24
    /**
25
     * Display a listing of the resource.
26
     *
27
     * @return \Illuminate\Http\Response
28
     */
29
    public function index($parentId)
0 ignored issues
show
Unused Code introduced by
The parameter $parentId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
    {
31
        // dd($this->crud);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
32
        $this->crud->checkPermission('list');
0 ignored issues
show
Bug introduced by
The method checkPermission() does not seem to exist on object<Backpack\CRUD\Crud>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
34
        return view('crud::layouts.list', $this->data + ['crud' => $this->crud]);
35
    }
36
37
    /**
38
     * Show the form for creating a new resource.
39
     *
40
     * @return \Illuminate\Http\Response
41
     */
42
    public function create($parentId)
0 ignored issues
show
Unused Code introduced by
The parameter $parentId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
    {
44
        // dd($this->crud);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
        $this->crud->checkPermission('add');
0 ignored issues
show
Bug introduced by
The method checkPermission() does not seem to exist on object<Backpack\CRUD\Crud>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
47
        return view('crud::layouts.create', $this->data + ['crud' => $this->crud]);
48
    }
49
50
    /**
51
     * Store a newly created resource in storage.
52
     *
53
     * @param \Illuminate\Http\Request $request
54
     *
55
     * @return \Illuminate\Http\Response
56
     */
57
    public function crudStore(Request $request = null)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
    {
59
        // $this->crud->checkPermission('add');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60
        // dd($request);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
61
        $entity = $this->crud->save(\Request::all());
0 ignored issues
show
Bug introduced by
The method save() does not seem to exist on object<Backpack\CRUD\Crud>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Unused Code introduced by
$entity is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
62
63
        // return \Redirect::to($this->crud->getRoute()."/{$entity->id}/edit")->with('status', trans('crud::crud.form.create_success'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
64
        return \Redirect::to($this->crud->getRoute())->with('status', trans('crud::crud.form.create_success'));
65
    }
66
67
    /**
68
     * Display the specified resource.
69
     *
70
     * @param int $id
71
     *
72
     * @return \Illuminate\Http\Response
73
     */
74
    public function show($parentId, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $parentId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
    {
76
        $this->crud->checkPermission('view');
0 ignored issues
show
Bug introduced by
The method checkPermission() does not seem to exist on object<Backpack\CRUD\Crud>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
77
        $this->crud->item($id);
0 ignored issues
show
Bug introduced by
The method item() does not seem to exist on object<Backpack\CRUD\Crud>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
79
        return view('crud::layouts.show', $this->data + ['crud' => $this->crud]);
80
    }
81
82
    /**
83
     * Show the form for editing the specified resource.
84
     *
85
     * @param int $id
86
     *
87
     * @return \Illuminate\Http\Response
88
     */
89
    public function edit($parentId, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $parentId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
90
    {
91
        $this->crud->checkPermission('edit');
0 ignored issues
show
Bug introduced by
The method checkPermission() does not seem to exist on object<Backpack\CRUD\Crud>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
92
        $this->crud->item($id);
0 ignored issues
show
Bug introduced by
The method item() does not seem to exist on object<Backpack\CRUD\Crud>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
93
94
        // dd($this->crud->item->toArray());
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
95
96
        return view('crud::layouts.edit', $this->data + ['crud' => $this->crud]);
97
    }
98
99
    /**
100
     * Update the specified resource in storage.
101
     *
102
     * @param \Illuminate\Http\Request $request
103
     * @param int                      $id
104
     *
105
     * @return \Illuminate\Http\Response
106
     */
107
    public function crudUpdate($parentId, $id, Request $request = null)
0 ignored issues
show
Unused Code introduced by
The parameter $parentId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
108
    {
109
        $this->crud->checkPermission('edit');
0 ignored issues
show
Bug introduced by
The method checkPermission() does not seem to exist on object<Backpack\CRUD\Crud>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
110
        $this->crud->item($id);
0 ignored issues
show
Bug introduced by
The method item() does not seem to exist on object<Backpack\CRUD\Crud>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
111
112
        $entity = $this->crud->update($id, \Request::all());
0 ignored issues
show
Unused Code introduced by
$entity is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
113
114
        return \Redirect::to($this->crud->getRoute())->with('status', trans('crud::crud.form.save_success'));
115
    }
116
117
    /**
118
     * Remove the specified resource from storage.
119
     *
120
     * @param int $id
121
     *
122
     * @return \Illuminate\Http\Response
123
     */
124
    public function destroy($parentId, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $parentId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
125
    {
126
        $this->crud->checkPermission('delete');
0 ignored issues
show
Bug introduced by
The method checkPermission() does not seem to exist on object<Backpack\CRUD\Crud>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
127
128
        return $this->crud->delete($id);
129
    }
130
}
131