Completed
Push — master ( b24285...12f2ad )
by Steve
18:04 queued 15:44
created

TextAtom   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 9
1
<?php
2
/**
3
 * (c) Steve Nebes <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
declare(strict_types=1);
10
11
namespace SN\RangeDifferencer\Tag;
12
13
/**
14
 * An Atom that represents a piece of ordinary text.
15
 */
16
class TextAtom implements AtomInterface
17
{
18
    /** @var string */
19
    private $str;
20
21
    /**
22
     * @param string $str
23
     */
24
    public function __construct(string $str)
25
    {
26
        if (!$this->isValidAtom($str)) {
27
            throw new \InvalidArgumentException('The given String is not a valid Text Atom.');
28
        }
29
30
        $this->str = $str;
31
    }
32
33
    /** {@inheritdoc} */
34
    public function getFullText(): string
35
    {
36
        return $this->str;
37
    }
38
39
    /** {@inheritdoc} */
40
    public function getIdentifier(): string
41
    {
42
        return $this->str;
43
    }
44
45
    /** {@inheritdoc} */
46
    public function getInternalIdentifiers(): string
47
    {
48
        throw new \RuntimeException('This Atom has no internal identifiers.');
49
    }
50
51
    /** {@inheritdoc} */
52
    public function hasInternalIdentifiers(): bool
53
    {
54
        return false;
55
    }
56
57
    /** {@inheritdoc} */
58
    public function isValidAtom(string $str): bool
59
    {
60
        return \mb_strlen($str) > 0;
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public function __toString(): string
67
    {
68
        return sprintf('TextAtom: %s', $this->getFullText());
69
    }
70
71
    /** {@inheritdoc} */
72
    public function equalsIdentifier(AtomInterface $other): bool
73
    {
74
        return $other->getIdentifier() === $this->str;
75
    }
76
}
77