Handler::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Tleckie\DesignPatterns\ChainResponsibility;
4
5
/**
6
 * Class Handler
7
 *
8
 * @package Tleckie\DesignPatterns\ChainOfResponsibility
9
 * @author  Teodoro Leckie Westberg <[email protected]>
10
 */
11
class Handler implements HandlerInterface
12
{
13
    /** @var string */
14
    protected const TYPE = '';
15
16
    /** @var HandlerInterface|null */
17
    protected HandlerInterface|null $handler;
18
19
    /**
20
     * Handler constructor.
21
     */
22
    public function __construct()
23
    {
24
        $this->handler = null;
25
    }
26
27
    /**
28
     * @param HandlerInterface $handler
29
     * @return HandlerInterface
30
     */
31
    public function next(HandlerInterface $handler): HandlerInterface
32
    {
33
        $this->handler = $handler;
34
35
        return $handler;
36
    }
37
38
    /**
39
     * @param OperationInterface $operation
40
     * @return float|null
41
     */
42
    public function handle(OperationInterface $operation): float|null
43
    {
44
        if ($this->handler) {
45
            return $this->handler->handle($operation);
46
        }
47
48
        return null;
49
    }
50
}
51