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

ApiVersion   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 11
c 1
b 0
f 0
dl 0
loc 38
ccs 9
cts 12
cp 0.75
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getContainer() 0 3 1
A handle() 0 12 1
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