CompositeDataFormatter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A formatInput() 0 7 2
A __construct() 0 3 1
A formatData() 0 7 2
1
<?php
2
3
namespace WebTheory\Saveyour\Formatting;
4
5
use WebTheory\Saveyour\Contracts\Formatting\DataFormatterInterface;
6
7
class CompositeDataFormatter implements DataFormatterInterface
8
{
9
    /**
10
     * @var DataFormatterInterface[]
11
     */
12
    protected array $formatters = [];
13
14 6
    public function __construct(DataFormatterInterface ...$formatters)
15
    {
16 6
        $this->formatters = $formatters;
17
    }
18
19 3
    public function formatData($value)
20
    {
21 3
        foreach ($this->formatters as $formatter) {
22 3
            $value = $formatter->formatData($value);
23
        }
24
25 3
        return $value;
26
    }
27
28 3
    public function formatInput($value)
29
    {
30 3
        foreach (array_reverse($this->formatters) as $formatter) {
31 3
            $value = $formatter->formatInput($value);
32
        }
33
34 3
        return $value;
35
    }
36
}
37