Combiner::applyCurrent()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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