GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Custom   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 22
c 0
b 0
f 0
dl 0
loc 97
ccs 0
cts 29
cp 0
rs 10
wmc 12

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getCallback() 0 3 1
A setCallback() 0 5 1
A getDisplay() 0 15 4
A __construct() 0 7 2
A setDisplay() 0 5 1
A save() 0 6 2
A render() 0 3 1
1
<?php
2
3
namespace SleepingOwl\Admin\Form\Element;
4
5
use Closure;
6
use Illuminate\Contracts\Support\Htmlable;
7
use Illuminate\Contracts\View\View as ViewContract;
8
use Illuminate\Http\Request;
9
use SleepingOwl\Admin\Form\FormElement;
10
11
class Custom extends FormElement
12
{
13
    /**
14
     * @var string|Closure
15
     */
16
    protected $display;
17
18
    /**
19
     * @var Closure
20
     */
21
    protected $callback;
22
23
    /**
24
     * Custom constructor.
25
     *
26
     * @param Closure|null $callback
27
     */
28
    public function __construct(Closure $callback = null)
29
    {
30
        if (! is_null($callback)) {
31
            $this->setCallback($callback);
32
        }
33
34
        parent::__construct();
35
    }
36
37
    /**
38
     * @return Closure|mixed|string
39
     */
40
    public function getDisplay()
41
    {
42
        if (is_callable($this->display)) {
43
            return call_user_func($this->display, $this->getModel());
44
        }
45
46
        if ($this->display instanceof Htmlable) {
0 ignored issues
show
introduced by
$this->display is never a sub-type of Illuminate\Contracts\Support\Htmlable.
Loading history...
47
            return $this->display->toHtml();
48
        }
49
50
        if ($this->display instanceof View) {
0 ignored issues
show
introduced by
$this->display is never a sub-type of SleepingOwl\Admin\Form\Element\View.
Loading history...
51
            return $this->display->with('model', $this->getModel())->render();
52
        }
53
54
        return $this->display;
55
    }
56
57
    /**
58
     * @param Closure|string|Htmlable|ViewContract $display
59
     *
60
     * @return $this
61
     */
62
    public function setDisplay($display)
63
    {
64
        $this->display = $display;
0 ignored issues
show
Documentation Bug introduced by
It seems like $display can also be of type Illuminate\Contracts\Support\Htmlable or Illuminate\Contracts\View\View. However, the property $display is declared as type Closure|string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
65
66
        return $this;
67
    }
68
69
    /**
70
     * @return Closure
71
     */
72
    public function getCallback()
73
    {
74
        return $this->callback;
75
    }
76
77
    /**
78
     * @param Closure $callback
79
     *
80
     * @return $this
81
     */
82
    public function setCallback(Closure $callback)
83
    {
84
        $this->callback = $callback;
85
86
        return $this;
87
    }
88
89
    /**
90
     * @return $this|self|mixed
91
     */
92
    public function render()
93
    {
94
        return $this->getDisplay();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getDisplay() also could return the type Closure which is incompatible with the return type mandated by Illuminate\Contracts\Support\Renderable::render() of string.
Loading history...
95
    }
96
97
    /**
98
     * @param \Illuminate\Http\Request $request
99
     *
100
     * @return void
101
     */
102
    public function save(Request $request)
103
    {
104
        $callback = $this->getCallback();
105
106
        if (is_callable($callback)) {
107
            call_user_func_array($callback, [$this->getModel(), $request]);
108
        }
109
    }
110
}
111