Passed
Branch master (3daac1)
by Vincent
07:53
created

CheckboxHtmlRenderer::instance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Bdf\Form\Leaf\View;
4
5
use Bdf\Form\View\FieldViewInterface;
6
use Bdf\Form\View\FieldViewRendererInterface;
7
use Bdf\Form\View\HtmlRenderer;
8
9
/**
10
 * Default renderer for @see BooleanElementView
11
 *
12
 * @implements FieldViewRendererInterface<BooleanElementView>
13
 */
14
final class CheckboxHtmlRenderer implements FieldViewRendererInterface
15
{
16
    /**
17
     * @var CheckboxHtmlRenderer|null
18
     */
19
    private static $instance;
20
21
    /**
22
     * {@inheritdoc}
23
     *
24
     * @param BooleanElementView $view
25
     */
26 6
    public function render(FieldViewInterface $view, array $attributes): string
27
    {
28 6
        if (!isset($attributes['type'])) {
29 6
            $attributes['type'] = 'checkbox';
30
        }
31
32 6
        $attributes['name'] = $view->name();
33 6
        $attributes['value'] = $view->httpValue();
0 ignored issues
show
Bug introduced by
The method httpValue() does not exist on Bdf\Form\View\FieldViewInterface. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        /** @scrutinizer ignore-call */ 
34
        $attributes['value'] = $view->httpValue();
Loading history...
34 6
        $attributes['checked'] = $view->checked();
0 ignored issues
show
Bug introduced by
The method checked() does not exist on Bdf\Form\View\FieldViewInterface. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        /** @scrutinizer ignore-call */ 
35
        $attributes['checked'] = $view->checked();
Loading history...
35
36 6
        return HtmlRenderer::element('input', $attributes);
37
    }
38
39
    /**
40
     * Get the renderer instance
41
     *
42
     * @return self
43
     */
44 4
    public static function instance(): self
45
    {
46 4
        if (self::$instance) {
47 4
            return self::$instance;
48
        }
49
50 1
        return self::$instance = new self;
51
    }
52
}
53