Passed
Push — main ( 9f5a95...cd7e37 )
by Daniel
01:50
created

CombinationFormatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 18
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 0 6 2
A __construct() 0 6 2
1
<?php
2
declare(strict_types=1);
3
4
namespace RoadBunch\StringBean;
5
6
7
class CombinationFormatter extends AbstractFormatter
8
{
9
    private array $formatters;
10
11
    public function __construct(FormatterInterface ...$formatters)
12
    {
13
        if (empty($formatters)) {
14
            throw new \LogicException('You must provide formatters to instantiate this class');
15
        }
16
        $this->formatters = $formatters;
17
    }
18
19
    public function format(string $string): string
20
    {
21
        foreach ($this->formatters as $formatter) {
22
            $string = $formatter->format($string);
23
        }
24
        return $string;
25
    }
26
}
27