Xml::fromArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace BestServedCold\PhalueObjects\Format;
4
5
use BestServedCold\PhalueObjects\Contract\VOArrayable;
6
use BestServedCold\PhalueObjects\VOString;
7
use Sabre\Xml\Service;
8
9
/**
10
 * Class Xml
11
 *
12
 * @package BestServedCold\PhalueObjects\Format
13
 */
14
class Xml extends VOString implements VOArrayable
15
{
16
    use StringMixin;
17
18
    /**
19
     * @return array
20
     */
21 1
    public function toArray()
22
    {
23 1
        return (array) (new Service())->parse($this->getValue());
24
    }
25
26
    /**
27
     * @param  array  $array
28
     * @throws \InvalidArgumentException
29
     * @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...
30
     */
31 1
    public static function fromArray(array $array)
32
    {
33 1
        if (count($array) > 1) {
34 1
            throw new \InvalidArgumentException('Array must only have one element.');
35
        }
36
37 1
        return new static((new Service())->write(key($array), reset($array)));
38
    }
39
}
40