| Total Complexity | 5 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class XmlParser |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Loads an XML file and returns a SimpleXMLElement. |
||
| 13 | * |
||
| 14 | * @param string $filePath The path to the XML file. |
||
| 15 | * |
||
| 16 | * @throws Exception If the XML file cannot be loaded. |
||
| 17 | */ |
||
| 18 | 46 | public function parse(string $filePath): SimpleXMLElement |
|
| 19 | { |
||
| 20 | 46 | if (! file_exists($filePath)) { |
|
| 21 | 2 | throw new Exception("XML file not found: {$filePath}"); |
|
| 22 | } |
||
| 23 | |||
| 24 | 44 | $xml = @simplexml_load_file($filePath); |
|
| 25 | 44 | if ($xml === false) { |
|
| 26 | 2 | throw new Exception("Failed to load XML file: {$filePath}"); |
|
| 27 | } |
||
| 28 | |||
| 29 | 43 | return $xml; |
|
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Saves a SimpleXMLElement to a file. |
||
| 34 | * |
||
| 35 | * @param SimpleXMLElement $xml The XML element to save. |
||
| 36 | * @param string $filePath The path where the XML should be saved. |
||
| 37 | * |
||
| 38 | * @throws Exception If the XML file cannot be saved. |
||
| 39 | */ |
||
| 40 | 2 | public function save(SimpleXMLElement $xml, string $filePath): void |
|
| 45 | } |
||
| 46 | } |
||
| 48 |