Completed
Pull Request — master (#24)
by Adam
02:31
created

Xml   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 24
ccs 6
cts 6
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 4 1
A fromArray() 0 8 2
1
<?php
2
3
namespace BestServedCold\PhalueObjects\Format\String;
4
5
use BestServedCold\PhalueObjects\Contract\VOArrayable;
6
use Sabre\Xml\Service;
7
8
/**
9
 * Class Xml
10
 *
11
 * @package BestServedCold\PhalueObjects\Format
12
 */
13
class Xml extends AbstractString implements VOArrayable
14
{
15
    /**
16
     * @return array
17
     */
18 1
    public function toArray()
19
    {
20 1
        return (array) (new Service())->parse($this->getValue());
21
    }
22
23
    /**
24
     * @param  array  $array
25
     * @throws \InvalidArgumentException
26
     * @return static
27
     */
28 1
    public static function fromArray(array $array)
29
    {
30 1
        if (count($array) > 1) {
31 1
            throw new \InvalidArgumentException('Array must only have one element.');
32
        }
33
34 1
        return new static((new Service())->write(key($array), reset($array)));
35
    }
36
}
37