ButtonViewRenderer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 37
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 13 3
A instance() 0 7 2
1
<?php
2
3
namespace Bdf\Form\Button\View;
4
5
use Bdf\Form\View\HtmlRenderer;
6
7
/**
8
 * Renderer for @see ButtonViewInterface
9
 */
10
final class ButtonViewRenderer implements ButtonViewRendererInterface
11
{
12
    /**
13
     * @var self|null
14
     */
15
    private static $instance;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 7
    public function render(ButtonViewInterface $view, array $attributes): string
21
    {
22 7
        if (!isset($attributes['type'])) {
23 7
            $attributes['type'] = 'submit';
24
        }
25
26 7
        $attributes['name'] = $view->name();
27 7
        $attributes['value'] = $view->value();
28
29 7
        $inner = $attributes['inner'] ?? null;
30 7
        unset($attributes['inner']);
31
32 7
        return HtmlRenderer::element($inner !== null ? 'button' : 'input', $attributes, $inner);
33
    }
34
35
    /**
36
     * Get the renderer instance
37
     *
38
     * @return self
39
     */
40 4
    public static function instance(): self
41
    {
42 4
        if (self::$instance) {
43 4
            return self::$instance;
44
        }
45
46 1
        return self::$instance = new self;
47
    }
48
}
49