Chaining   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setNext() 0 3 1
A apply() 0 6 2
A getNext() 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\Formatter;
9
10
trait Chaining
11
{
12
    /**
13
     * @var Formatter|null Next character tree formatter in the chain.
14
     */
15
    private $next = null;
16
17
    /**
18
     * @param Formatter|null $next Formatter to apply after this one.
19
     */
20 2
    public function setNext(?Formatter $next): void
21
    {
22 2
        $this->next = $next;
23 2
    }
24
25
    /**
26
     * @return Formatter|null Next formatter in the chain.
27
     */
28 2
    public function getNext(): ?Formatter
29
    {
30 2
        return $this->next;
31
    }
32
33
    /**
34
     * @param CharTree $charTree Character tree to format.
35
     * @return CharTree The character tree formatted by the formatter chain.
36
     */
37 59
    public function apply(CharTree $charTree): CharTree
38
    {
39 59
        if ($this->next === null) {
40 50
            return $this->applyCurrent($charTree);
41
        } else {
42 10
            return $this->next->apply($this->applyCurrent($charTree));
43
        }
44
    }
45
46
    /**
47
     * @param CharTree $charTree Character tree to format.
48
     * @return CharTree The character tree formatted by this formatter.
49
     */
50
    abstract protected function applyCurrent(CharTree $charTree): CharTree;
51
}
52