Passed
Push — master ( 429320...4248bd )
by Chris
03:24
created

CombinationFormatter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
c 1
b 0
f 1
dl 0
loc 47
ccs 13
cts 13
cp 1
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A formatInput() 0 7 2
A getFormatters() 0 3 1
A __construct() 0 3 1
A formatData() 0 7 2
1
<?php
2
3
namespace WebTheory\Saveyour\Formatters;
4
5
use WebTheory\Saveyour\Contracts\DataFormatterInterface;
6
7
class CombinationFormatter 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