Completed
Push — master ( 42324d...1863b6 )
by Steve
03:59 queued 02:04
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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getFullText() 0 3 1
A __toString() 0 3 1
A isValidAtom() 0 3 1
A equalsIdentifier() 0 3 1
A getIdentifier() 0 3 1
A hasInternalIdentifiers() 0 3 1
A getInternalIdentifiers() 0 3 1
A __construct() 0 8 2
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
            var_dump($str);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($str) looks like debug code. Are you sure you do not want to remove it?
Loading history...
28
            throw new \InvalidArgumentException('The given String is not a valid Text Atom.');
29
        }
30
31
        $this->str = $str;
32
    }
33
34
    /** {@inheritdoc} */
35
    public function getFullText(): string
36
    {
37
        return $this->str;
38
    }
39
40
    /** {@inheritdoc} */
41
    public function getIdentifier(): string
42
    {
43
        return $this->str;
44
    }
45
46
    /** {@inheritdoc} */
47
    public function getInternalIdentifiers(): string
48
    {
49
        throw new \RuntimeException('This Atom has no internal identifiers.');
50
    }
51
52
    /** {@inheritdoc} */
53
    public function hasInternalIdentifiers(): bool
54
    {
55
        return false;
56
    }
57
58
    /** {@inheritdoc} */
59
    public function isValidAtom(string $str): bool
60
    {
61
        return \mb_strlen($str) > 0;
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    public function __toString(): string
68
    {
69
        return sprintf('TextAtom: %s', $this->getFullText());
70
    }
71
72
    /** {@inheritdoc} */
73
    public function equalsIdentifier(AtomInterface $other): bool
74
    {
75
        return $other->getIdentifier() === $this->str;
76
    }
77
}
78