Completed
Push — master ( 8c9478...0f7d17 )
by Adam
02:25
created

Json   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 36
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2
ccs 8
cts 8
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 4 1
A fromArray() 0 4 1
A fromVOArray() 0 4 1
A toVOArray() 0 4 1
1
<?php
2
3
namespace BestServedCold\PhalueObjects\Format;
4
5
use BestServedCold\PhalueObjects\Contract\Arrayable;
6
use BestServedCold\PhalueObjects\Contract\VOArrayable;
7
use BestServedCold\PhalueObjects\Format;
8
use BestServedCold\PhalueObjects\VOArray;
9
10
/**
11
 * Class Json
12
 *
13
 * @package BestServedCold\PhalueObjects\Format
14
 */
15
class Json extends Format implements Arrayable, VOArrayable
16
{
17
    /**
18
     * @return array
19
     */
20 2
    public function toArray()
21
    {
22 2
        return (array) json_decode($this->getValue(), true);
23
    }
24
25
    /**
26
     * @param  array  $array
27
     * @return static
28
     */
29 2
    public static function fromArray(array $array)
30
    {
31 2
        return new static(json_encode($array));
32
    }
33
34
    /**
35
     * @param  VOArray $voArray
36
     * @return Json
37
     */
38 1
    public static function fromVOArray(VOArray $voArray)
39
    {
40 1
        return self::fromArray($voArray->getValue());
41
    }
42
43
    /**
44
     * @return VOArray
45
     */
46 1
    public function toVOArray()
47
    {
48 1
        return VOArray::fromArray(self::toArray());
49
    }
50
}
51