Completed
Push — master ( a19a47...15bbc5 )
by Arjay
15:59
created

TooltipDirective   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 6 1
1
<?php
2
3
namespace Yajra\CMS\View\Directives;
4
5
class TooltipDirective
6
{
7
    /**
8
     * Tooltip blade directive compiler.
9
     * @tooltip($tooltip, $template)
10
     *
11
     * @param string $tooltip
12
     * @param string $template
13
     * @return string
14
     * @throws \Exception
15
     * @throws \Throwable
16
     */
17
    public function handle($tooltip, $template = 'system.tooltip')
18
    {
19
        $tooltip = trans($tooltip);
20
21
        return view($template, compact('tooltip'))->render();
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...
22
    }
23
}