ErrorHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 25
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 5 1
A __construct() 0 4 1
1
<?php
2
3
namespace Simply\Application\Handler;
4
5
use Psr\Http\Message\ResponseFactoryInterface;
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Psr\Http\Message\StreamFactoryInterface;
9
use Psr\Http\Server\RequestHandlerInterface;
10
11
/**
12
 * A simple handler that sends a 500 error response.
13
 * @author Riikka Kalliomäki <[email protected]>
14
 * @copyright Copyright (c) 2018 Riikka Kalliomäki
15
 * @license http://opensource.org/licenses/mit-license.php MIT License
16
 */
17
class ErrorHandler implements RequestHandlerInterface
18
{
19
    /** @var ResponseFactoryInterface The factory used to generate the response */
20
    private $responseFactory;
21
22
    /** @var StreamFactoryInterface The factory used to generate the body for the response */
23
    private $streamFactory;
24
25
    /**
26
     * NotFoundHandler constructor.
27
     * @param ResponseFactoryInterface $responseFactory The factory used to generate the response
28
     * @param StreamFactoryInterface $streamFactory The factory used to generate the body for the response
29
     */
30 12
    public function __construct(ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory)
31
    {
32 12
        $this->responseFactory = $responseFactory;
33 12
        $this->streamFactory = $streamFactory;
34 12
    }
35
36
    /** {@inheritdoc} */
37 1
    public function handle(ServerRequestInterface $request): ResponseInterface
38
    {
39 1
        return $this->responseFactory->createResponse(500, 'Internal Server Error')
40 1
            ->withHeader('Content-Type', 'text/plain; charset=utf-8')
41 1
            ->withBody($this->streamFactory->createStream('Internal Server Error'));
42
    }
43
}
44