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

Csv   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 37
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 fromArray() 0 4 1
A fromVOArray() 0 4 1
A toArray() 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\ValueObject;
8
use BestServedCold\PhalueObjects\VOArray;
9
10
/**
11
 * Class Csv
12
 *
13
 * @package BestServedCold\PhalueObjects\Format
14
 */
15
class Csv extends ValueObject implements Arrayable, VOArrayable
16
{
17
    /**
18
     * @param  array       $array
19
     * @param  string|null $space
20
     * @return static
21
     */
22 14
    public static function fromArray(array $array, $space = null)
23
    {
24 14
        return new static(implode(',' . $space, $array));
25
    }
26
27
    /**
28
     * @param  VOArray $voArray
29
     * @return static
30
     */
31 1
    public static function fromVOArray(VOArray $voArray)
32
    {
33 1
        return self::fromArray($voArray->getValue());
34
    }
35
36
    /**
37
     * @return array
38
     */
39 2
    public function toArray()
40
    {
41 2
        return explode(',', $this->getValue());
42
    }
43
44
    /**
45
     * @return VOArray
46
     */
47 1
    public function toVOArray()
48
    {
49 1
        return VOArray::fromArray(self::toArray());
50
    }
51
}
52