Completed
Branch master (832503)
by Michael
02:05
created

MiddlewareStack::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Schnittstabil\Psr7\MiddlewareStack;
4
5
/**
6
 * Immutable middleware stack.
7
 */
8
class MiddlewareStack implements MiddlewareStackInterface
9
{
10
    use CallableMiddlewareStackTrait;
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