Test Setup Failed
Branch vuejs (6d2eff)
by Julien
25:27 queued 19:55
created

DashboardController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Tournament;
6
use Carbon\Carbon;
7
use Illuminate\Support\Facades\Auth;
8
use Illuminate\Support\Facades\View;
9
10
class DashboardController extends Controller
11
{
12
    /**
13
     * Display a listing of the resource.
14
     *
15
     * @return View
16
     */
17
    public function index()
18
    {
19
        $openTournaments = Tournament::with('owner')
0 ignored issues
show
Bug introduced by
The method whereHas 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...
20
            ->whereHas('owner', function ($query) {
21
                $query->where('country_id', Auth::user()->country_id);
0 ignored issues
show
Bug introduced by
Accessing country_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
22
            })
23
            ->where('type', config('constants.OPEN_TOURNAMENT'))
24
            ->where('dateFin', '>', Carbon::today()->toDateString())
25
            ->get();
26
        return view('/dashboard', compact('openTournaments'));
27
28
    }
29
30
}
31