GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

MenusController::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Afrittella\BackProject\Http\Controllers;
3
4
use Afrittella\BackProject\Http\Requests\MenuAdd;
5
use Afrittella\BackProject\Http\Requests\MenuEdit;
6
use Afrittella\BackProject\Repositories\Menus;
7
use Afrittella\BackProject\Repositories\Permissions;
8
use Illuminate\Http\Request;
9
use Prologue\Alerts\Facades\Alert;
10
11
class MenusController extends Controller
12
{
13
    public function __construct()
14
    {
15
        $this->middleware('admin');
16
    }
17
18
    public function index(Menus $menus)
19
    {
20
        return view('back-project::menus.index')->with('menus', $menus->transform($menus->all()));
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
21
    }
22
23
    public function edit(Request $request, Menus $menus, Permissions $permissions, $id)
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...
24
    {
25
        return view('back-project::menus.edit')
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
26
                    ->with([
27
                        'menu' => $menus->find($id),
28
                        'children' => $menus->children($id),
29
                        'permissions' =>  $permissions->all()
30
                    ]);
31
    }
32
33
    public function create(Permissions $permissions)
34
    {
35
        return view('back-project::menus.create')
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
36
            ->with([
37
                'permissions' =>  $permissions->all()
38
            ]);
39
    }
40
41
    public function delete(Menus $menus, $id)
42
    {
43
        $menus->delete($id);
44
45
        Alert::add('success', trans('back-project::crud.model_deleted', ['model' => trans('back-project::menus.menu')]))->flash();
46
47
        return back();
48
    }
49
50
    public function up(Request $request, Menus $menus, $id)
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...
51
    {
52
        $menus->moveUp($id);
53
        return back();
54
    }
55
56
    public function down(Request $request, Menus $menus, $id)
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...
57
    {
58
        $menus->moveDown($id);
59
        return back();
60
    }
61
62
    public function store(MenuAdd $request, Menus $menus, Permissions $permissions)
63
    {
64
        $menu = $menus->create($request->all());
0 ignored issues
show
Unused Code introduced by
$menu 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...
65
        $permission = $request->input('permission');
66
67
        if (!empty($permission))
68
        {
69
            $permissions->firstOrCreate($permission);
70
        }
71
72
        Alert::add('success', trans('back-project::crud.model_created', ['model' => trans('back-project::menus.menu')]))->flash();
73
74
        if ($request->ajax() || $request->wantsJson()) {
75
            return response()->json();
76
        } else {
77
            return redirect(route('bp.menus.index'));
78
        }
79
    }
80
81
    public function update(MenuEdit $request, Menus $menus, $id)
82
    {
83
        $menu = $menus->update($request->all(), $id);
0 ignored issues
show
Unused Code introduced by
$menu 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...
84
85
        Alert::add('success', trans('back-project::crud.model_updated', ['model' => trans('back-project::menus.menu')]))->flash();
86
87
        return back();
88
    }
89
}