Passed
Push — master ( 015ca0...ec05e1 )
by Magnar Ovedal
02:36
created

Capitalizer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 28
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A applyCurrent() 0 10 2
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stadly\PasswordPolice\Formatter;
6
7
use Stadly\PasswordPolice\CharTree;
8
use Stadly\PasswordPolice\CodeMap\LowerCaseMap;
9
use Stadly\PasswordPolice\Formatter;
10
11
final class Capitalizer implements Formatter
12
{
13
    use Chaining;
14
15
    /**
16
     * @var Coder Lower case coder.
17
     */
18
    private $lowerCaseCoder;
19
20 5
    public function __construct()
21
    {
22 5
        $this->lowerCaseCoder = new Coder(new LowerCaseMap());
23 5
    }
24
25
    /**
26
     * @param CharTree $charTree Character tree to format.
27
     * @return CharTree Capitalized variant of the character tree.
28
     */
29 5
    protected function applyCurrent(CharTree $charTree): CharTree
30
    {
31 5
        $formatted = [];
32
33 5
        foreach ($charTree->getTreeTrimmedToLength(1) as $char) {
34 5
            $branches = [$this->lowerCaseCoder->apply($charTree->getBranchesAfterRoot($char))];
35 5
            $formatted[] = CharTree::fromString(mb_strtoupper($char), $branches);
36
        }
37
38 5
        return CharTree::fromArray($formatted);
39
    }
40
}
41