Combiner   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 41
ccs 11
cts 11
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A applyCurrent() 0 13 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stadly\PasswordPolice\Formatter;
6
7
use Stadly\PasswordPolice\CharTree;
8
use Stadly\PasswordPolice\Formatter;
9
10
final class Combiner implements Formatter
11
{
12
    use Chaining;
13
14
    /**
15
     * @var array<Formatter> Character tree formatters.
16
     */
17
    private $formatters;
18
19
    /**
20
     * @var bool Whether the result should also include the character tree unformatted.
21
     */
22
    private $includeUnformatted;
23
24
    /**
25
     * @param array<Formatter> $formatters Character tree formatters.
26
     * @param bool $includeUnformatted Whether the result should also include the character tree unformatted.
27
     */
28 3
    public function __construct(array $formatters, bool $includeUnformatted = true)
29
    {
30 3
        $this->formatters = $formatters;
31 3
        $this->includeUnformatted = $includeUnformatted;
32 3
    }
33
34
    /**
35
     * @param CharTree $charTree Character tree to format.
36
     * @return CharTree The character tree formatted by all the formatters in the combiner.
37
     */
38 3
    protected function applyCurrent(CharTree $charTree): CharTree
39
    {
40 3
        $charTrees = [];
41
42 3
        if ($this->includeUnformatted) {
43 1
            $charTrees[] = $charTree;
44
        }
45
46 3
        foreach ($this->formatters as $formatter) {
47 3
            $charTrees[] = $formatter->apply($charTree);
48
        }
49
50 3
        return CharTree::fromArray($charTrees);
51
    }
52
}
53