Container::replace()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Everlution\Ajaxcom\Responder;
6
7
/**
8
 * Class Container.
9
 *
10
 * @author Everlution s.r.o. <[email protected]>
11
 */
12
class Container extends AbstractResponder
13
{
14
    private const OPTION_VALUE = 'value';
15
    private const OPTION_TARGET = 'target';
16
    private const OPTION_METHOD = 'method';
17
    private const OPTION_ATTR = 'attr';
18
19
    public function __construct(string $identifier)
20
    {
21
        $this->registerOption(self::OPTION_VALUE);
22
        $this->registerOption(self::OPTION_TARGET);
23
        $this->registerOption(self::OPTION_METHOD);
24
        $this->registerOption(self::OPTION_ATTR);
25
26
        $this->setOption(self::OPTION_TARGET, $identifier);
27
    }
28
29
    public function append(string $html): self
30
    {
31
        $this->setOption(self::OPTION_VALUE, $html);
32
        $this->setOption(self::OPTION_METHOD, 'append');
33
34
        return $this;
35
    }
36
37
    public function prepend(string $html): self
38
    {
39
        $this->setOption(self::OPTION_VALUE, $html);
40
        $this->setOption(self::OPTION_METHOD, 'prepend');
41
42
        return $this;
43
    }
44
45
    public function insertBefore(string $html)
46
    {
47
        $this->setOption(self::OPTION_VALUE, $html);
48
        $this->setOption(self::OPTION_METHOD, 'insertBefore');
49
50
        return $this;
51
    }
52
53
    public function insertAfter(string $html)
54
    {
55
        $this->setOption(self::OPTION_VALUE, $html);
56
        $this->setOption(self::OPTION_METHOD, 'insertAfter');
57
58
        return $this;
59
    }
60
61
    public function replace(string $html): self
62
    {
63
        $this->setOption(self::OPTION_VALUE, $html);
64
        $this->setOption(self::OPTION_METHOD, 'replace');
65
66
        return $this;
67
    }
68
69
    public function html(string $html): self
70
    {
71
        $this->setOption(self::OPTION_VALUE, $html);
72
        $this->setOption(self::OPTION_METHOD, 'html');
73
74
        return $this;
75
    }
76
77
    public function remove(): self
78
    {
79
        $this->setOption(self::OPTION_METHOD, 'remove');
80
81
        return $this;
82
    }
83
84
    public function removeClass(string $class): self
85
    {
86
        $this->setOption(self::OPTION_VALUE, $class);
87
        $this->setOption(self::OPTION_METHOD, 'removeClass');
88
89
        return $this;
90
    }
91
92
    public function addClass(string $class): self
93
    {
94
        $this->setOption(self::OPTION_VALUE, $class);
95
        $this->setOption(self::OPTION_METHOD, 'addClass');
96
97
        return $this;
98
    }
99
100
    public function attr(string $attribute, string $value): self
101
    {
102
        $this->setOption(self::OPTION_METHOD, 'attr');
103
        $this->setOption(self::OPTION_ATTR, $attribute);
104
        $this->setOption(self::OPTION_VALUE, $value);
105
106
        return $this;
107
    }
108
109
    protected function getIdentifier(): string
110
    {
111
        return 'container';
112
    }
113
}
114