Completed
Push — master ( 024746...0b49f1 )
by Song
04:00
created

Panel::getParent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Show;
4
5
use Encore\Admin\Show;
6
use Illuminate\Contracts\Support\Renderable;
7
use Illuminate\Support\Collection;
8
9
class Panel implements Renderable
10
{
11
    /**
12
     * The view to be rendered.
13
     *
14
     * @var string
15
     */
16
    protected $view = 'admin::show.panel';
17
18
    /**
19
     * The fields that this panel holds.
20
     *
21
     * @var Collection
22
     */
23
    protected $fields;
24
25
    /**
26
     * Variables in the view.
27
     *
28
     * @var array
29
     */
30
    protected $data;
31
32
    /**
33
     * Parent show instance.
34
     *
35
     * @var Show
36
     */
37
    protected $parent;
38
39
    /**
40
     * Panel constructor.
41
     */
42
    public function __construct(Show $show)
43
    {
44
        $this->parent = $show;
45
46
        $this->initData();
47
    }
48
49
    /**
50
     * Initialize view data.
51
     */
52
    protected function initData()
53
    {
54
        $this->data = [
55
            'fields' => new Collection(),
56
            'tools'  => new Tools($this),
57
            'style'  => 'info',
58
            'title'  => trans('admin.detail'),
59
        ];
60
    }
61
62
    /**
63
     * Set parent container.
64
     *
65
     * @param Show $show
66
     *
67
     * @return $this
68
     */
69
    public function setParent(Show $show)
70
    {
71
        $this->parent = $show;
72
73
        return $this;
74
    }
75
76
    /**
77
     * Get parent container.
78
     *
79
     * @return Show
80
     */
81
    public function getParent()
82
    {
83
        return $this->parent;
84
    }
85
86
    /**
87
     * Set style for this panel.
88
     *
89
     * @param string $style
90
     *
91
     * @return $this
92
     */
93
    public function style($style = 'info')
94
    {
95
        $this->data['style'] = $style;
96
97
        return $this;
98
    }
99
100
    /**
101
     * Set title for this panel.
102
     *
103
     * @param string $title
104
     *
105
     * @return $this
106
     */
107
    public function title($title)
108
    {
109
        $this->data['title'] =  $title;
110
111
        return $this;
112
    }
113
114
    /**
115
     * Set view for this panel to render.
116
     *
117
     * @param string $view
118
     *
119
     * @return $this
120
     */
121
    public function view($view)
122
    {
123
        $this->view = $view;
124
125
        return $this;
126
    }
127
128
    /**
129
     * Build panel tools.
130
     *
131
     * @param $callable
132
     */
133
    public function tools($callable)
134
    {
135
        call_user_func($callable, $this->data['tools']);
136
    }
137
138
    /**
139
     * Fill fields to panel.
140
     *
141
     * @param []Field $fields
0 ignored issues
show
Documentation introduced by
The doc-type []Field could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
142
     *
143
     * @return $this
144
     */
145
    public function fill($fields)
146
    {
147
        $this->data['fields'] = $fields;
148
149
        return $this;
150
    }
151
152
    /**
153
     * Render this panel.
154
     *
155
     * @return string
156
     */
157
    public function render()
158
    {
159
        return view($this->view, $this->data)->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...
160
    }
161
}
162