Lines
100.00%
11 / 11
Methods
100.00%
2 / 2
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| from | 100.00% | 10 / 10 | 100.00% | 1 / 1 | 3 | ||
| 11 | final readonly class XmlMessage implements Message | |
| 12 | { | |
| 13 | public function __construct( | |
| 14 | public DOMDocument $dom, | |
| 15 | public string $raw, | |
| 16 | ) {} | |
| 17 | ||
| 18 | /** @return Option\Option<static> */ | |
| 19 | #[Override] | |
| 20 | public static function from(string $message): Option\Option | |
| 21 | { | |
| 22 | if ($message === '') { | |
| 23 | return Option\none(); | |
| 24 | } | |
| 25 | ||
| 26 | $dom = new DOMDocument(); | |
| 27 | $previous = libxml_use_internal_errors(true); | |
| 28 | $loaded = $dom->loadXML($message); | |
| 29 | libxml_clear_errors(); | |
| 30 | libxml_use_internal_errors($previous); | |
| 31 | ||
| 32 | if ($loaded === false) { | |
| 33 | return Option\none(); | |
| 34 | } | |
| 35 | ||
| 36 | return Option\some(new self($dom, $message)); | |
| 37 | } | |
| 38 | } |