MatchController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 6 1
A store() 0 6 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Match;
6
use Illuminate\Support\Facades\Request;
7
use Illuminate\Support\Facades\Response;
8
9
/**
10
 * Class MatchController
11
 * @package App\Http\Controllers
12
 */
13
class MatchController extends Controller
14
{
15
    /**
16
     * Display a listing of the resource.
17
     *
18
     * @return Response
19
     */
20
    public function index()
21
    {
22
        $matches = Match::with(['homeTournamentTeam.team', 'awayTournamentTeam.team'])->get();
0 ignored issues
show
Bug introduced by
The method get 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...
23
24
        return view('match.index', compact('matches'));
25
    }
26
27
    /**
28
     * Store a newly created resource in storage.
29
     *
30
     * @return Response
31
     */
32
    public function store()
33
    {
34
        Match::create(Request::all());
0 ignored issues
show
Bug introduced by
The method create() does not exist on App\Match. Did you maybe mean created()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
35
36
        return redirect('match');
37
    }
38
}
39