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.

ModuleAdmin::getView()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.2888
c 0
b 0
f 0
cc 5
nc 5
nop 0
1
<?php
2
3
namespace LaravelFlare\Flare\Admin\Modules;
4
5
use LaravelFlare\Flare\Admin\Admin;
6
7
abstract class ModuleAdmin extends Admin
8
{
9
    /**
10
     * The Controller to be used by the Module Admin.
11
     *
12
     * This defaults to parent::getController()
13
     * if it has been left undefined. 
14
     * 
15
     * @var string
16
     */
17
    protected $controller = '\LaravelFlare\Flare\Admin\Modules\ModuleAdminController';
18
19
    /**
20
     * The Module Admin Default View.
21
     *
22
     * @var string
23
     */
24
    protected $view = 'admin.modules.index';
25
26
    /**
27
     * Returns the Module Admin View.
28
     *
29
     * Determines if a view exists by:
30
     * Looking for $this->view
31
     * Then looks for  'admin.modulename.index',
32
     * Then looks for  'admin.modulename',
33
     * Then defaults to 
34
     * 
35
     * @return string
36
     */
37
    public function getView()
38
    {
39
        if (view()->exists($this->view)) {
0 ignored issues
show
Bug introduced by
The method exists does only exist in Illuminate\Contracts\View\Factory, but not in Illuminate\View\View.

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...
40
            return $this->view;
41
        }
42
43
        if (view()->exists('admin.'.$this->urlPrefix().'.index')) {
44
            return 'admin.'.$this->urlPrefix().'.index';
45
        }
46
47
        if (view()->exists('admin.'.$this->urlPrefix())) {
48
            return 'admin.'.$this->urlPrefix();
49
        }
50
51
        if (view()->exists('flare::'.$this->view)) {
52
            return 'flare::'.$this->view;
53
        }
54
55
        return parent::getView();
56
    }
57
}
58