Passed
Push — master ( a90def...5de986 )
by Chris
04:49
created

TrixEditor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 65
ccs 0
cts 30
cp 0
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A defineControlId() 0 3 1
A resolveAttributes() 0 4 1
A createEditorFormControl() 0 3 1
A renderHtmlMarkup() 0 10 1
A getControlId() 0 3 1
1
<?php
2
3
namespace WebTheory\Saveyour\Fields;
4
5
use WebTheory\Html\AbstractHtmlElement;
6
use WebTheory\Saveyour\Contracts\FormFieldInterface;
7
8
class TrixEditor extends AbstractFormField implements FormFieldInterface
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $controlId;
14
15
    /**
16
     *
17
     */
18
    public function __construct(string $controlId)
19
    {
20
        $this->controlId = $controlId;
21
22
        parent::__construct();
23
    }
24
25
    /**
26
     * Get the value of controlId
27
     *
28
     * @return string
29
     */
30
    public function getControlId(): string
31
    {
32
        return $this->controlId;
33
    }
34
35
    /**
36
     *
37
     */
38
    protected function resolveAttributes(): AbstractHtmlElement
39
    {
40
        return parent::resolveAttributes()
41
            ->addAttribute('input', $this->controlId);
0 ignored issues
show
Bug introduced by
'input' of type string is incompatible with the type array expected by parameter $attribute of WebTheory\Html\AbstractHtmlElement::addAttribute(). ( Ignorable by Annotation )

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

41
            ->addAttribute(/** @scrutinizer ignore-type */ 'input', $this->controlId);
Loading history...
42
    }
43
44
    /**
45
     *
46
     */
47
    protected function renderHtmlMarkup(): string
48
    {
49
        $control = $this->createEditorFormControl()
50
            ->setName($this->name)
51
            ->setValue($this->value)
52
            ->setId($this->controlId);
53
54
        $editor = $this->tag('trix-editor', '', $this->attributes);
55
56
        return $control . $editor;
57
    }
58
59
    /**
60
     *
61
     */
62
    protected function createEditorFormControl(): Hidden
63
    {
64
        return new Hidden;
65
    }
66
67
    /**
68
     *
69
     */
70
    protected function defineControlId(): string
71
    {
72
        return $this->id . '-form-control';
73
    }
74
}
75