MiddlewareStackTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A push() 0 18 2
1
<?php
2
3
namespace Schnittstabil\Psr7\MiddlewareStack;
4
5
/**
6
 * Implentations of stack operations.
7
 */
8
trait MiddlewareStackTrait
9
{
10
    protected $middlewareStack;
11
12
    /**
13
     * Push a middleware onto the top of this stack.
14
     *
15
     * @param callable $newTopMiddleware the middleware to be pushed onto the top.
16
     *
17
     * @return static $this
18
     */
19
    protected function push(callable $newTopMiddleware)
20
    {
21
        $oldStack = $this->middlewareStack;
22
23
        if ($oldStack === null) {
24
            $this->middlewareStack = $newTopMiddleware;
25
26
            return $this;
27
        }
28
29
        $this->middlewareStack = function ($request, $response, callable $next) use ($oldStack, $newTopMiddleware) {
30
            return $newTopMiddleware($request, $response, function ($req, $res) use ($next, $oldStack) {
31
                return $oldStack($req, $res, $next);
32
            });
33
        };
34
35
        return $this;
36
    }
37
}
38