AbstractAdminField::getLabel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Leonidas\Library\Admin\Component\Abstracts;
4
5
use Leonidas\Contracts\Admin\Component\AdminFieldInterface;
6
use Psr\Http\Message\ServerRequestInterface;
7
use WebTheory\Saveyour\Contracts\Controller\FormFieldControllerInterface;
8
use WebTheory\Saveyour\Contracts\Field\FormFieldInterface;
9
10
abstract class AbstractAdminField implements AdminFieldInterface
11
{
12
    /**
13
     * label
14
     */
15
    protected ?string $label = null;
16
17
    /**
18
     * description
19
     */
20
    protected ?string $description = null;
21
22
    protected FormFieldControllerInterface $formFieldController;
23
24
    public function __construct(FormFieldControllerInterface $formFieldController)
25
    {
26
        $this->formFieldController = $formFieldController;
27
    }
28
29
    /**
30
     * Get label
31
     *
32
     * @return string
33
     */
34
    public function getLabel(): string
35
    {
36
        return $this->label;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->label 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...
37
    }
38
39
    /**
40
     * Set label
41
     *
42
     * @param string $label label
43
     *
44
     * @return $this
45
     */
46
    public function setLabel(string $label)
47
    {
48
        $this->label = $label;
49
50
        return $this;
51
    }
52
53
    /**
54
     * Get description
55
     *
56
     * @return string
57
     */
58
    public function getDescription(): string
59
    {
60
        return $this->description;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->description 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...
61
    }
62
63
    /**
64
     * Set description
65
     *
66
     * @param string $description description
67
     *
68
     * @return $this
69
     */
70
    public function setDescription(string $description)
71
    {
72
        $this->description = $description;
73
74
        return $this;
75
    }
76
77
    public function renderInputField(ServerRequestInterface $request): string
78
    {
79
        return $this->formFieldController->render($request);
80
    }
81
82
    protected function renderFormField(ServerRequestInterface $request): FormFieldInterface
83
    {
84
        return $this->formFieldController->compose($request);
85
    }
86
}
87