Chaining::getNext()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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