Passed
Push — master ( b32226...446c00 )
by Chris
08:06
created

CombinationDataFormatter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WebTheory\Saveyour\Formatters;
4
5
use WebTheory\Saveyour\Contracts\DataFormatterInterface;
6
7
class CombinationDataFormatter implements DataFormatterInterface
8
{
9
    /**
10
     * @var DataFormatterInterface[]
11
     */
12
    protected $formatters = [];
13
14
    /**
15
     *
16
     */
17 9
    public function __construct(DataFormatterInterface ...$formatters)
18
    {
19 9
        $this->formatters = $formatters;
20 9
    }
21
22
    /**
23
     * Get the value of formatters
24
     *
25
     * @return array
26
     */
27 3
    public function getFormatters(): array
28
    {
29 3
        return $this->formatters;
30
    }
31
32
    /**
33
     *
34
     */
35 3
    public function formatData($value)
36
    {
37 3
        foreach ($this->formatters as $formatter) {
38 3
            $value = $formatter->formatData($value);
39
        }
40
41 3
        return $value;
42
    }
43
44
    /**
45
     *
46
     */
47 3
    public function formatInput($value)
48
    {
49 3
        foreach (array_reverse($this->formatters) as $formatter) {
50 3
            $value = $formatter->formatInput($value);
51
        }
52
53 3
        return $value;
54
    }
55
}
56