ButtonView::name()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Bdf\Form\Button\View;
4
5
use Bdf\Form\View\RenderableTrait;
6
7
/**
8
 * Base view object for buttons
9
 *
10
 * <code>
11
 * echo $view->class('btn btn-primary'); // <input type="submit" name="btn" value="ok" />
12
 * echo $view->class('btn btn-primary')->inner('Process'); // <button type="submit" name="btn" value="ok">Process</button>
13
 * </code>
14
 */
15
final class ButtonView implements ButtonViewInterface
16
{
17
    use RenderableTrait;
18
19
    /**
20
     * @var string
21
     */
22
    private $name;
23
24
    /**
25
     * @var string
26
     */
27
    private $value;
28
29
    /**
30
     * @var bool
31
     */
32
    private $clicked;
33
34
    /**
35
     * ButtonView constructor.
36
     *
37
     * @param string $name
38
     * @param mixed $value
39
     * @param bool $clicked
40
     */
41 13
    public function __construct(string $name, string $value, bool $clicked)
42
    {
43 13
        $this->name = $name;
44 13
        $this->value = $value;
45 13
        $this->clicked = $clicked;
46 13
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 8
    public function name(): string
52
    {
53 8
        return $this->name;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 8
    public function value(): string
60
    {
61 8
        return $this->value;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 2
    public function clicked(): bool
68
    {
69 2
        return $this->clicked;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 3
    public function render(?ButtonViewRendererInterface $renderer = null): string
76
    {
77 3
        return ($renderer ?? ButtonViewRenderer::instance())->render($this, $this->attributes);
78
    }
79
}
80