Passed
Push — master ( 446c00...d7e047 )
by Chris
02:29
created

ArrayToListDataFormatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 29
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 2
A formatData() 0 3 1
A formatInput() 0 3 1
1
<?php
2
3
namespace WebTheory\Saveyour\Formatters;
4
5
use WebTheory\Saveyour\Contracts\DataFormatterInterface;
6
7
class ArrayToListDataFormatter implements DataFormatterInterface
8
{
9
    /**
10
     *
11
     */
12
    protected $delimiter = ', ';
13
14
    /**
15
     *
16
     */
17 15
    public function __construct(?string $delimiter = null)
18
    {
19 15
        $delimiter && $this->delimiter = $delimiter;
20 15
    }
21
22
    /**
23
     *
24
     */
25 6
    public function formatData($value)
26
    {
27 6
        return implode($this->delimiter, $value);
28
    }
29
30
    /**
31
     *
32
     */
33 6
    public function formatInput($value)
34
    {
35 6
        return explode($this->delimiter, $value);
36
    }
37
}
38