Completed
Push — master ( 487726...07c1c1 )
by Michael
01:44
created

Stack   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 40
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A add() 0 6 1
A create() 0 4 1
1
<?php
2
3
namespace Schnittstabil\Psr7\Middleware;
4
5
/**
6
 * Immutable middleware stack.
7
 */
8
class Stack implements StackInterface
9
{
10
    use CallableStackTrait;
11
12
    /**
13
     * Create new stack.
14
     *
15
     * @param callable $bottomMiddleware last middleware to be called
16
     */
17
    public function __construct(callable $bottomMiddleware = null)
18
    {
19
        $this->middlewareStack = $bottomMiddleware;
20
    }
21
22
    /**
23
     * Push a middleware onto the top of a new Stack instance.
24
     *
25
     * @param callable $newTopMiddleware the middleware to be pushed onto the top.
26
     *
27
     * @return static the new instance
28
     */
29
    public function add(callable $newTopMiddleware)
30
    {
31
        $clone = clone $this;
32
33
        return $clone->push($newTopMiddleware);
34
    }
35
36
    /**
37
     * Create new stack.
38
     *
39
     * @param callable $bottomMiddleware last middleware to be called
40
     *
41
     * @return static a new stack instance
42
     */
43
    public static function create(callable $bottomMiddleware = null)
44
    {
45
        return new self($bottomMiddleware);
46
    }
47
}
48