| Total Complexity | 10 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | class Text extends InlineNode |
||
| 15 | { |
||
| 16 | protected string $type = 'text'; |
||
| 17 | private string $text; |
||
| 18 | private array $marks = []; |
||
| 19 | |||
| 20 | public function __construct(string $text, MarkNode ...$marks) |
||
| 21 | { |
||
| 22 | $this->text = $text; |
||
| 23 | |||
| 24 | foreach ($marks as $mark) { |
||
| 25 | $this->addMark($mark); |
||
| 26 | } |
||
| 27 | } |
||
| 28 | |||
| 29 | public function jsonSerialize(): array |
||
| 30 | { |
||
| 31 | $result = parent::jsonSerialize(); |
||
| 32 | if ($this->marks) { |
||
|
|
|||
| 33 | $result['marks'] = $this->marks; |
||
| 34 | } |
||
| 35 | $result['text'] = $this->text; |
||
| 36 | |||
| 37 | return $result; |
||
| 38 | } |
||
| 39 | |||
| 40 | public function getMarks(): array |
||
| 43 | } |
||
| 44 | |||
| 45 | public static function load(array $data): self |
||
| 60 | } |
||
| 61 | |||
| 62 | public function getText(): string |
||
| 63 | { |
||
| 64 | return $this->text; |
||
| 65 | } |
||
| 66 | |||
| 67 | protected function addMark(MarkNode $mark): void |
||
| 70 | } |
||
| 71 | } |
||
| 72 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.