UpperCaseConverter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 8
c 4
b 0
f 0
dl 0
loc 28
ccs 8
cts 8
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A applyCurrent() 0 10 2
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\UpperCaseMap;
9
10
final class UpperCaseConverter extends Coder
11
{
12
    use Chaining;
13
14
    /**
15
     * @var array<CharTree> Memoization of formatted character trees.
16
     */
17
    private static $memoization = [];
18
19 7
    public function __construct()
20
    {
21 7
        parent::__construct(new UpperCaseMap());
22 7
    }
23
24
    /**
25
     * @param CharTree $charTree Character tree to format.
26
     * @return CharTree Upper case converted variant of the character tree.
27
     */
28 7
    protected function applyCurrent(CharTree $charTree): CharTree
29
    {
30
        // When PHP 7.1 is no longer supported, change to using spl_object_id.
31 7
        $hash = spl_object_hash($charTree);
32
33 7
        if (!isset(self::$memoization[$hash])) {
34 7
            self::$memoization[$hash] = $this->format($charTree);
35
        }
36
37 7
        return self::$memoization[$hash];
38
    }
39
}
40