CompositeDataFormatter::formatInput()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
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