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

StopperMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A process() 0 8 1
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\ResponseFactoryInterface;
21
use Psr\Http\Message\ResponseInterface;
22
use Psr\Http\Message\ServerRequestInterface;
23
use Psr\Http\Server\MiddlewareInterface;
24
use Psr\Http\Server\RequestHandlerInterface;
25
26
/**
27
 * Class StopperMiddleware.
28
 */
29
class StopperMiddleware implements MiddlewareInterface
30
{
31
    /**
32
     * @var string
33
     */
34
    public $content;
35
36
    /**
37
     * @var array
38
     */
39
    public static $output = [];
40
41
    private $response;
42
43
    /**
44
     * SampleMiddleware constructor.
45
     *
46
     * @param string $content
47
     */
48
    public function __construct(ResponseFactoryInterface $responseHandler, string $content = null)
49
    {
50
        $this->content  = $content ?: \mt_rand(1, 9999999);
51
        $this->response = $responseHandler->createResponse();
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
58
    {
59
        static::$output[] = $this->content;
60
61
        $this->response->getBody()->write('Stopped in middleware.');
62
        $response = $this->response->withHeader('Content-Type', 'text/plain; charset=utf-8');
63
64
        return $response;
65
    }
66
}
67