Completed
Branch master (a6481d)
by Fèvre
02:09
created

UserController::show()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 2
eloc 15
nc 2
nop 3
1
<?php
2
namespace Xetaravel\Http\Controllers;
3
4
use Xetaravel\Models\User;
5
use Illuminate\Http\Request;
6
use Illuminate\View\View;
7
8
class UserController extends Controller
9
{
10
    public function __construct()
11
    {
12
        parent::__construct();
13
14
        $this->breadcrumbs->addCrumb('Users', route('users_user_index'));
0 ignored issues
show
Bug introduced by
The property breadcrumbs does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
15
    }
16
17
    /**
18
     * Show the account update form.
19
     *
20
     * @return \Illuminate\View\View
21
     */
22
    public function index(): View
23
    {
24
        return view('user.index');
25
    }
26
27
    /**
28
     * Show the user profile page.
29
     *
30
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Redirec...\Contracts\View\Factory?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
31
     */
32
    public function show(Request $request, $slug, $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...
Unused Code introduced by
The parameter $slug 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...
33
    {
34
        $user = User::with('articles', 'comments')
0 ignored issues
show
Bug introduced by
The method where does only exist in Illuminate\Database\Eloquent\Builder, but not in Illuminate\Database\Eloquent\Model.

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...
35
            ->where('id', $id)
36
            ->first();
37
38
        if (is_null($user)) {
39
            return redirect()
40
                ->route('page_index')
41
                ->with('danger', 'This user doesn\'t exist or has been deleted !');
42
        }
43
44
        $this->breadcrumbs->addCrumb(
45
            e($user->username),
46
            route(
47
                'users_user_show',
48
                ['slug' => $user->slug, 'id' => $user->id]
49
            )
50
        );
51
        $this->breadcrumbs->setCssClasses('breadcrumb');
52
53
        return view('user.show', ['user' => $user, 'breadcrumbs' => $this->breadcrumbs]);
54
    }
55
}
56