Completed
Push — master ( 65fa37...c7bb09 )
by Song
02:44
created

src/Grid/Tools/FilterButton.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Encore\Admin\Grid\Tools;
4
5
use Encore\Admin\Admin;
6
7
class FilterButton extends AbstractTool
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $view = 'admin::filter.button';
13
14
    /**
15
     * @var string
16
     */
17
    protected $btnClassName;
18
19
    /**
20
     * @return \Encore\Admin\Grid\Filter
21
     */
22
    protected function filter()
23
    {
24
        return $this->grid->getFilter();
25
    }
26
27
    /**
28
     * Get button class name.
29
     *
30
     * @return string
31
     */
32
    protected function getElementClassName()
33
    {
34
        if (!$this->btnClassName) {
35
            $this->btnClassName = uniqid().'-filter-btn';
36
        }
37
38
        return $this->btnClassName;
39
    }
40
41
    /**
42
     * Set up script for export button.
43
     */
44
    protected function setUpScripts()
45
    {
46
        $id = $this->filter()->getFilterID();
47
48
        $script = <<<SCRIPT
49
$('.{$this->getElementClassName()}').unbind('click');
50
$('.{$this->getElementClassName()}').click(function (e) {
51
    if ($('#{$id}').is(':visible')) {
52
        $('#{$id}').addClass('hide');
53
    } else {
54
        $('#{$id}').removeClass('hide');
55
    }
56
});
57
SCRIPT;
58
59
        Admin::script($script);
60
    }
61
62
    /**
63
     * @return mixed
64
     */
65
    protected function renderScopes()
66
    {
67
        return $this->filter()->getScopes()->map->render()->implode("\r\n");
68
    }
69
70
    /**
71
     * Get label of current scope.
72
     *
73
     * @return string
74
     */
75
    protected function getCurrentScopeLabel()
76
    {
77
        if ($scope = $this->filter()->getCurrentScope()) {
78
            return "&nbsp;{$scope->getLabel()}&nbsp;";
79
        }
80
81
        return '';
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87
    public function render()
88
    {
89
        $this->setUpScripts();
90
91
        $variables = [
92
            'scopes'        => $this->filter()->getScopes(),
93
            'current_label' => $this->getCurrentScopeLabel(),
94
            'url_no_scopes' => $this->filter()->urlWithoutScopes(),
95
            'btn_class'     => $this->getElementClassName(),
96
            'expand'        => $this->filter()->expand,
97
        ];
98
99
        return view($this->view, $variables)->render();
0 ignored issues
show
The method render 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...
100
    }
101
}
102