Passed
Push — main ( 90c8f5...cf7c53 )
by Daniel
01:54
created

BulkFormatter::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
4
namespace RoadBunch\StringBean;
5
6
7
class BulkFormatter 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