Test Failed
Pull Request — master (#5)
by Ayan
03:44
created

ApiVersion::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1.0787

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 12
ccs 4
cts 7
cp 0.5714
rs 10
cc 1
nc 1
nop 3
crap 1.0787
1
<?php
2
3
namespace Phprest\Middleware;
4
5
use League\Container\ContainerInterface;
6
use Negotiation\FormatNegotiator;
7
use Phprest\Application;
8
use Phprest\HttpFoundation\Request;
9
use Phprest\Util;
10
use Symfony\Component\HttpFoundation\Request as BaseRequest;
11
use Symfony\Component\HttpFoundation\Response;
12
use Symfony\Component\HttpKernel\HttpKernelInterface;
13
14
class ApiVersion implements HttpKernelInterface
15
{
16
    use Util\Mime;
17
18
    protected Application $app;
19
20 1
    public function __construct(Application $app)
21
    {
22 1
        $this->app = $app;
23 1
    }
24
25
    /**
26
     * @param BaseRequest $request
27
     * @param int $type
28
     * @param bool $catch
29
     *
30
     * @return Response
31
     */
32 1
    public function handle(BaseRequest $request, $type = self::MASTER_REQUEST, $catch = true)
33
    {
34 1
        $request        = new Request($request);
35 1
        $mimeProcResult = $this->processMime(
36 1
            (new FormatNegotiator())->getBest($request->headers->get('Accept', '*/*'))->getValue()
37
        );
38
39
        $request->setApiVersion(
40
            str_pad($mimeProcResult->apiVersion, 3, '.0')
41
        );
42
43
        return $this->app->handle($request, $type, $catch);
44
    }
45
46
    /**
47
     * @return ContainerInterface
48
     */
49 1
    public function getContainer()
50
    {
51 1
        return $this->app->getConfiguration()->getContainer();
52
    }
53
}
54