Completed
Push — master ( 798e92...ea2dad )
by Yaro
04:12 queued 26s
created

ShowHideColumnsTool::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
ccs 0
cts 4
cp 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Yaro\Jarboe\Table\Toolbar;
4
5
use Illuminate\Http\Request;
6
7
class ShowHideColumnsTool extends AbstractTool
8
{
9
    /**
10
     * Position where should tool be placed.
11
     */
12
    public function position()
13
    {
14
        return self::POSITION_HEADER;
15
    }
16
17
    /**
18
     * Unique tool identifier.
19
     */
20 2
    public function identifier(): string
21
    {
22 2
        return 'show_hide_columns';
23
    }
24
25
    /**
26
     * Tool's view.
27
     */
28
    public function render()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
29
    {
30
        return view('jarboe::crud.toolbar.show_hide_columns', [
0 ignored issues
show
Bug introduced by
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...
31
            'tool' => $this,
32
        ])->render();
33
    }
34
35
    /**
36
     * Handle tool execution.
37
     * @param Request $request
38
     */
39
    public function handle(Request $request)
40
    {
41
        // dummy
42
    }
43
44
    /**
45
     * Check allowance to show and process tool.
46
     */
47
    public function check(): bool
48
    {
49
        return true;
50
    }
51
}
52