IssueTypeController::index()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 4
nop 2
1
<?php
2
/**
3
 * GitScrum v0.1.
4
 *
5
 * @author  Renato Marinho <[email protected]>
6
 * @license http://opensource.org/licenses/GPL-3.0 GPLv3
7
 */
8
9
namespace GitScrum\Http\Controllers;
10
11
use GitScrum\Models\Issue;
12
13
class IssueTypeController extends Controller
14
{
15
    /**
16
     * Display a listing of the resource.
17
     *
18
     * @return \Illuminate\Http\Response
19
     */
20
    public function index($slug_sprint, $slug_type = null)
21
    {
22
        $issues = Issue::join('sprints', 'issues.sprint_id', 'sprints.id')
23
            ->join('issue_types', 'issues.issue_type_id', 'issue_types.id');
24
25
        if (!is_null($slug_sprint) && !empty($slug_sprint)) {
26
            $issues->where('sprints.slug', $slug_sprint);
27
        }
28
29
        if (!is_null($slug_type)) {
30
            $issues->where('issue_types.slug', $slug_type);
31
        }
32
33
        $issues = $issues->orderby('issues.position', 'ASC')
34
            ->select('issues.*')->paginate(env('APP_PAGINATE'));
35
36
        return view('issue_types.index')
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...
37
            ->with('issues', $issues);
38
    }
39
}
40