| Total Complexity | 9 |
| Total Lines | 60 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 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 |