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

PageHeaderDirective   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 4 1
1
<?php
2
3
namespace Yajra\CMS\View\Directives;
4
5
class PageHeaderDirective
6
{
7
    /**
8
     * Page header blade directive compiler.
9
     * @pageHeader($title, $description, $icon, $template)
10
     *
11
     * @param string $title
12
     * @param string $description
13
     * @param string $icon
14
     * @param string $template
15
     * @return string
16
     * @throws \Exception
17
     * @throws \Throwable
18
     */
19
    public function handle($title, $description, $icon, $template = 'system.page-header-title')
20
    {
21
        return view($template, compact('title', 'description', 'icon'))->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
}