Completed
Push — master ( 50437b...6d2b5a )
by Adam
02:31
created

Xml::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace BestServedCold\PhalueObjects\Format;
4
5
use BestServedCold\PhalueObjects\Contract\VOArrayable;
6
use BestServedCold\PhalueObjects\VOString;
7
use BestServedCold\PhalueObjects\VOArray\Mixin as VOArrayMixin;
8
use Sabre\Xml\Service;
9
10
/**
11
 * Class Xml
12
 *
13
 * @package BestServedCold\PhalueObjects\Format
14
 */
15
class Xml extends VOString implements VOArrayable
16
{
17
    use VOArrayMixin;
18
19
    /**
20
     * @return array
21
     */
22 1
    public function toArray()
23
    {
24 1
        return (array) (new Service())->parse($this->getValue());
25
    }
26
27
    /**
28
     * @param  array  $array
29
     * @throws \InvalidArgumentException
30
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be Xml?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
31
     */
32 1
    public static function fromArray(array $array)
33
    {
34 1
        if (count($array) > 1) {
35 1
            throw new \InvalidArgumentException('Array must only have one element.');
36
        }
37
38 1
        return new static((new Service())->write(key($array), reset($array)));
39
    }
40
}
41