Passed
Push — master ( 656593...4e2bc2 )
by Php Easy Api
03:42
created

SimpleXmlManager::toXml()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Resta\Support;
4
5
use Spatie\ArrayToXml\ArrayToXml;
6
7
class SimpleXmlManager
8
{
9
    /**
10
     * @var object
11
     */
12
    protected $xml;
13
14
    /**
15
     * SimpleXmlManager constructor.
16
     * @param $path
17
     */
18
    public function __construct($path)
19
    {
20
        $this->xml = \simplexml_load_file($path);
21
    }
22
23
    /**
24
     * get xml object
25
     *
26
     * @return object|\SimpleXMLElement
27
     */
28
    public function getXml()
29
    {
30
        return $this->xml;
31
    }
32
33
    /**
34
     * Convert XML to an Array
35
     *
36
     * @return array
37
     */
38
    public function toArray()
39
    {
40
        $xml = $this->getXml();
41
42
        return json_decode(json_encode((array) $xml), true);
43
    }
44
45
    /**
46
     * Convert Array to an xml
47
     *
48
     * @param array $data
49
     * @return string
50
     */
51
    public function toXml($data=array())
52
    {
53
        return ArrayToXml::convert($data);
54
    }
55
}