Completed
Push — develop ( 8a9a81...cf6437 )
by Abdelrahman
12:02
created

Tab::panels()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Foundation\Facades;
6
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Support\Facades\Facade;
9
10
class Tab extends Facade
11
{
12
    /**
13
     * Get the tab headers.
14
     *
15
     * @return string
16
     */
17
    public static function headers(string $service, Model $entity)
18
    {
19
        return app()->bound($service) ? app($service)->pluck('header')->map(function ($item) use ($entity) {
20
            return view(str_replace('{accessarea}', request('accessarea'), $item), ['entity' => $entity])->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...
21
        })->implode('') : '';
22
    }
23
24
    /**
25
     * Get the tab panels.
26
     *
27
     * @return string
28
     */
29
    public static function panels(string $service, Model $entity)
30
    {
31
        return app()->bound($service) ? app($service)->pluck('panel')->map(function ($item) use ($entity) {
32
            return view(str_replace('{accessarea}', request('accessarea'), $item), ['entity' => $entity])->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...
33
        })->implode('') : '';
34
    }
35
}
36