| Total Complexity | 5 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | abstract class Response implements \ArrayAccess |
||
| 21 | { |
||
| 22 | use ArrayAccessTrait; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param \SimpleXMLElement $xml |
||
| 26 | * @throws Exception |
||
| 27 | */ |
||
| 28 | public function __construct($xml) |
||
| 29 | { |
||
| 30 | $array = json_decode(json_encode($xml), true); |
||
| 31 | $array = array_map(function ($value) { |
||
| 32 | if (is_array($value) && empty($value)) { |
||
| 33 | return ''; |
||
| 34 | } |
||
| 35 | |||
| 36 | return $value; |
||
| 37 | }, $array); |
||
| 38 | $this->fromArray($array); |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @return mixed |
||
| 43 | */ |
||
| 44 | public function toXML() |
||
| 45 | { |
||
| 46 | $data = $this->toArray(); |
||
| 47 | $xml = new \SimpleXMLElement('<GestPayCryptDecrypt/>'); |
||
| 48 | array_walk_recursive($data, function ($value, $key) use ($xml) { |
||
| 49 | $xml->addChild($key, $value); |
||
| 50 | }); |
||
| 51 | |||
| 52 | $dom = new \DOMDocument('1.0'); |
||
| 53 | $dom->preserveWhiteSpace = false; |
||
| 54 | $dom->formatOutput = true; |
||
| 55 | $dom->loadXML($xml->asXML()); |
||
| 56 | |||
| 57 | return $dom->saveXML(null, LIBXML_NOEMPTYTAG); |
||
| 58 | } |
||
| 59 | |||
| 60 | public function isOK() |
||
| 63 | } |
||
| 64 | } |
||
| 65 |