RequestHandler::respond()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * This file is part of the Divergence package.
4
 *
5
 * (c) Henry Paradiz <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Divergence\Controllers;
12
13
use Divergence\App;
14
use Divergence\Responders\Response;
15
use Psr\Http\Message\ResponseInterface;
16
use Psr\Http\Message\ServerRequestInterface;
17
use Psr\Http\Server\RequestHandlerInterface;
18
19
abstract class RequestHandler implements RequestHandlerInterface
20
{
21
    public string $responseBuilder;
22
23 64
    public function peekPath()
24
    {
25 64
        return App::$App->Path->peekPath();
26
    }
27
28 66
    public function shiftPath()
29
    {
30 66
        return App::$App->Path->shiftPath();
31
    }
32
33 1
    public function unshiftPath($string)
34
    {
35 1
        return App::$App->Path->unshiftPath($string);
36
    }
37
38 55
    public function respond($responseID, $responseData = []): ResponseInterface
39
    {
40 55
        $className = $this->responseBuilder;
41 55
        return new Response(new $className($responseID, $responseData));
42
    }
43
44
    abstract public function handle(ServerRequestInterface $request): ResponseInterface;
45
}
46