Chaining   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 8
c 1
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 getNext() 0 3 1
A apply() 0 6 2
A setNext() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stadly\PasswordPolice\DateFormatter;
6
7
use DateTimeInterface;
8
use Stadly\PasswordPolice\CharTree;
9
use Stadly\PasswordPolice\Formatter;
10
11
trait Chaining
12
{
13
    /**
14
     * @var Formatter|null Next character tree formatter in the chain.
15
     */
16
    private $next = null;
17
18
    /**
19
     * @param Formatter|null $next Formatter to apply after this date formatter.
20
     */
21 2
    public function setNext(?Formatter $next): void
22
    {
23 2
        $this->next = $next;
24 2
    }
25
26
    /**
27
     * @return Formatter|null Next formatter in the chain.
28
     */
29 2
    public function getNext(): ?Formatter
30
    {
31 2
        return $this->next;
32
    }
33
34
    /**
35
     * @param iterable<DateTimeInterface> $dates Dates to format.
36
     * @return CharTree The dates formatted by the formatter chain.
37
     */
38 5
    public function apply(iterable $dates): CharTree
39
    {
40 5
        if ($this->next === null) {
41 2
            return $this->applyCurrent($dates);
42
        } else {
43 3
            return $this->next->apply($this->applyCurrent($dates));
44
        }
45
    }
46
47
    /**
48
     * @param iterable<DateTimeInterface> $dates Dates to format.
49
     * @return CharTree The dates formatted by this date formatter.
50
     */
51
    abstract protected function applyCurrent(iterable $dates): CharTree;
52
}
53