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

Xml::fromArray()   A

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 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