TextBuilder::text()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DH\Adf\Builder;
6
7
use DH\Adf\Node\Inline\Text;
8
use DH\Adf\Node\Mark\Em;
9
use DH\Adf\Node\Mark\Link;
10
use DH\Adf\Node\Mark\Strike;
11
use DH\Adf\Node\Mark\Strong;
12
use DH\Adf\Node\Mark\Subsup;
13
use DH\Adf\Node\Mark\TextColor;
14
use DH\Adf\Node\Mark\Underline;
15
use DH\Adf\Node\Node;
16
17
trait TextBuilder
18
{
19
    public function text(string $text): self
20
    {
21
        $this->append(new Text($text));
22
23
        return $this;
24
    }
25
26
    public function em(string $text): self
27
    {
28
        $this->append(new Text($text, new Em()));
29
30
        return $this;
31
    }
32
33
    public function strong(string $text): self
34
    {
35
        $this->append(new Text($text, new Strong()));
36
37
        return $this;
38
    }
39
40
    public function underline(string $text): self
41
    {
42
        $this->append(new Text($text, new Underline()));
43
44
        return $this;
45
    }
46
47
    public function strike(string $text): self
48
    {
49
        $this->append(new Text($text, new Strike()));
50
51
        return $this;
52
    }
53
54
    public function sub(string $text): self
55
    {
56
        $this->append(new Text($text, new Subsup('sub')));
57
58
        return $this;
59
    }
60
61
    public function sup(string $text): self
62
    {
63
        $this->append(new Text($text, new Subsup('sup')));
64
65
        return $this;
66
    }
67
68
    public function color(string $text, string $color): self
69
    {
70
        $this->append(new Text($text, new TextColor($color)));
71
72
        return $this;
73
    }
74
75
    public function link(string $text, string $href, ?string $title = null): self
76
    {
77
        $this->append(new Text($text, new Link($href, $title)));
78
79
        return $this;
80
    }
81
82
    abstract protected function append(Node $node): void;
83
}
84