MiddlewareNode   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zanzara\Middleware;
6
7
use Zanzara\Context;
8
9
/**
10
 * A node of the middleware stack.
11
 * The last node is the callback to be executed and does not have a next node.
12
 *
13
 */
14
class MiddlewareNode
15
{
16
17
    /**
18
     * @var MiddlewareInterface|callable
19
     */
20
    private $current;
21
22
    /**
23
     * @var MiddlewareNode|null
24
     */
25
    private $next;
26
27
    /**
28
     * @param MiddlewareInterface|callable $current
29
     * @param MiddlewareNode|null $next
30
     */
31
    public function __construct($current, ?MiddlewareNode $next = null)
32
    {
33
        $this->current = $current;
34
        $this->next = $next;
35
    }
36
37
    /**
38
     * @param Context $ctx
39
     */
40
    public function __invoke(Context $ctx)
41
    {
42
        if ($this->current instanceof MiddlewareInterface) {
43
            $this->current->handle($ctx, $this->next);
44
        } else {
45
            call_user_func($this->current, $ctx, $this->next);
46
        }
47
    }
48
49
}
50