Passed
Branch master (23e82e)
by Divine Niiquaye
04:27
created

SampleMiddleware::process()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Flight Routing.
7
 *
8
 * PHP version 7.2 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2019 Biurad Group (https://biurad.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Flight\Routing\Tests\Fixtures;
19
20
use Psr\Http\Message\ResponseInterface;
21
use Psr\Http\Message\ServerRequestInterface;
22
use Psr\Http\Server\MiddlewareInterface;
23
use Psr\Http\Server\RequestHandlerInterface;
24
25
/**
26
 * Class SampleMiddleware.
27
 */
28
class SampleMiddleware implements MiddlewareInterface
29
{
30
    /**
31
     * @var string
32
     */
33
    public $content;
34
35
    /**
36
     * @var array
37
     */
38
    public static $output = [];
39
40
    /**
41
     * SampleMiddleware constructor.
42
     *
43
     * @param null|string $content
44
     */
45
    public function __construct(string $content = null)
46
    {
47
        static::$output = [];
48
49
        $this->content = $content ?: \mt_rand(1, 9999999);
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
56
    {
57
        static::$output[] = $this->content;
58
        $request          = $request->withAttribute(__CLASS__, $this->content);
59
60
        return $handler->handle($request);
61
    }
62
}
63