Combiner::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stadly\PasswordPolice\DateFormatter;
6
7
use DateTimeInterface;
8
use Stadly\PasswordPolice\CharTree;
9
use Stadly\PasswordPolice\DateFormatter;
10
11
final class Combiner implements DateFormatter
12
{
13
    use Chaining;
14
15
    /**
16
     * @var array<DateFormatter> Date formatters.
17
     */
18
    private $dateFormatters;
19
20
    /**
21
     * @param array<DateFormatter> $dateFormatters Date formatters.
22
     */
23 2
    public function __construct(array $dateFormatters)
24
    {
25 2
        $this->dateFormatters = $dateFormatters;
26 2
    }
27
28
    /**
29
     * @param iterable<DateTimeInterface> $dates Dates to format.
30
     * @return CharTree The dates formatted by all the date formatters in the combiner.
31
     */
32 2
    protected function applyCurrent(iterable $dates): CharTree
33
    {
34 2
        $charTrees = [];
35
36 2
        foreach ($this->dateFormatters as $dateFormatter) {
37 2
            $charTrees[] = $dateFormatter->apply($dates);
38
        }
39
40 2
        return CharTree::fromArray($charTrees);
41
    }
42
}
43