Passed
Push — master ( f55f17...bcf382 )
by Chris
06:38
created

Metabox::getLayout()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Leonidas\Library\Admin\Metabox;
4
5
use GuzzleHttp\Psr7\ServerRequest;
6
use Leonidas\Contracts\Admin\Components\MetaboxInterface;
7
use Leonidas\Contracts\Admin\Components\MetaboxLayoutInterface;
8
use Leonidas\Traits\CanBeRestrictedTrait;
9
use Leonidas\Traits\RendersWithViewTrait;
10
use Psr\Http\Message\ServerRequestInterface;
11
use WP_Post;
12
13
class Metabox implements MetaboxInterface
14
{
15 1
    use CanBeRestrictedTrait;
16
17
    /**
18
     * id
19
     *
20
     * @var string
21
     */
22
    protected $id;
23
24
    /**
25
     * title
26
     *
27
     * @var string
28
     */
29
    protected $title;
30
31
    /**
32
     * screen
33
     *
34
     * @var string|string[]|WP_Screen
0 ignored issues
show
Bug introduced by
The type Leonidas\Library\Admin\Metabox\WP_Screen was not found. Did you mean WP_Screen? If so, make sure to prefix the type with \.
Loading history...
35
     */
36
    protected $screen;
37
38
    /**
39
     * context
40
     *
41
     * @var null|string
42
     */
43
    protected $context = 'advanced';
44
45
    /**
46
     * priority
47
     *
48
     * @var string
49
     */
50
    protected $priority = 'default';
51
52
    /**
53
     * callbackArgs
54
     *
55
     * @var array
56
     */
57
    protected $callbackArgs = [];
58
59
    /**
60
     * layout
61
     *
62
     * @var MetaboxLayoutInterface
63
     */
64
    protected $layout;
65
66
    /**
67
     *
68
     */
69 36
    public function __construct(string $id, string $title, MetaboxLayoutInterface $layout)
70
    {
71 36
        $this->id = $id;
72 36
        $this->title = $title;
73 36
        $this->layout = $layout;
74 36
    }
75
76
    /**
77
     * Get id
78
     *
79
     * @return string
80
     */
81 4
    public function getId(): string
82
    {
83 4
        return $this->id;
84
    }
85
86
    /**
87
     * Get title
88
     *
89
     * @return string
90
     */
91 4
    public function getTitle(): string
92
    {
93 4
        return $this->title;
94
    }
95
96
    /**
97
     * Get screen
98
     *
99
     * @return string|string[]|WP_Screen
100
     */
101 8
    public function getScreen()
102
    {
103 8
        return $this->screen;
104
    }
105
106
    /**
107
     * Set screen
108
     *
109
     * @param string|string[]|WP_Screen $screen screen
110
     *
111
     * @return self
112
     */
113 8
    public function setScreen($screen)
114
    {
115 8
        $this->screen = $screen;
116
117 8
        return $this;
118
    }
119
120
    /**
121
     * Get context
122
     *
123
     * @return string
124
     */
125 6
    public function getContext(): string
126
    {
127 6
        return $this->context;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->context could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
128
    }
129
130
    /**
131
     * Set context
132
     *
133
     * @param string  $context  context
134
     *
135
     * @return self
136
     */
137 4
    public function setContext(string $context)
138
    {
139 4
        $this->context = $context;
140
141 4
        return $this;
142
    }
143
144
    /**
145
     * Get priority
146
     *
147
     * @return string
148
     */
149 4
    public function getPriority(): string
150
    {
151 4
        return $this->priority;
152
    }
153
154
    /**
155
     * Set priority
156
     *
157
     * @param string  $priority  priority
158
     *
159
     * @return self
160
     */
161 2
    public function setPriority(string $priority)
162
    {
163 2
        $this->priority = $priority;
164
165 2
        return $this;
166
    }
167
168
    /**
169
     * Get callbackArgs
170
     *
171
     * @return array
172
     */
173 2
    public function getCallbackArgs(): array
174
    {
175 2
        return $this->callbackArgs;
176
    }
177
178
    /**
179
     * Set callbackArgs
180
     *
181
     * @param array  $callbackArgs  callbackArgs
182
     *
183
     * @return self
184
     */
185 2
    public function setCallbackArgs(array $callbackArgs)
186
    {
187 2
        $this->callbackArgs = $callbackArgs;
188
189 2
        return $this;
190
    }
191
192
    /**
193
     * Get layout
194
     *
195
     * @return MetaboxLayoutInterface
196
     */
197 4
    public function getLayout(): MetaboxLayoutInterface
198
    {
199 4
        return $this->layout;
200
    }
201
202
    public function renderComponent(ServerRequestInterface $request): string
203
    {
204
        return $this->layout->renderComponent($request);
205
    }
206
}
207