Passed
Push — master ( 2802ef...c7d11a )
by Bruno
06:54
created

RenderableBuefyTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 39
ccs 0
cts 22
cp 0
rs 10
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B editable() 0 27 7
1
<?php
2
3
namespace Formularium\Frontend\Buefy;
4
5
use Formularium\Field;
6
use Formularium\HTMLElement;
7
8
trait RenderableBuefyTrait
9
{
10
    /**
11
     * Subcall of wrapper editable() from RenderableMaterializeTrait
12
     *
13
     * @param mixed $value
14
     * @param Field $field
15
     * @param HTMLElement $previous
16
     * @return HTMLElement
17
     */
18
    abstract public function _editable($value, Field $field, HTMLElement $previous): HTMLElement;
19
20
    public function editable($value, Field $field, HTMLElement $previous): HTMLElement
21
    {
22
        /** @var HTMLElement $base */
23
        $base = $this->_editable($value, $field, $previous);
24
25
        $extensions = $field->getExtensions();
26
        $base->setTag('b-field');
27
28
        if (array_key_exists('label', $extensions)) {
29
            $base->setAttribute('label', $extensions['label']);
30
        }
31
        if (array_key_exists('comment', $extensions)) {
32
            $base->setAttribute('message', $extensions['comment']);
33
        }
34
        $base->filter(function ($e) {
35
            if ($e instanceof HTMLElement) {
36
                if ($e->getTag() === 'label') {
37
                    return false;
38
                }
39
                if ($e->getTag() === 'div' && $e->getAttribute('class') === ['comment']) {
40
                    return false;
41
                }
42
            }
43
            return true;
44
        });
45
46
        return $base;
47
    }
48
}
49