Handler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 2
b 0
f 0
dl 0
loc 38
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 2
A __construct() 0 3 1
A next() 0 5 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