Xml   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

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