Completed
Push — master ( b69735...6d6276 )
by John
05:05
created

RequestMatcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A matches() 0 12 2
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\SwaggerBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
namespace KleijnWeb\SwaggerBundle\Security;
9
10
use KleijnWeb\PhpApi\Descriptions\Description\Repository;
11
use KleijnWeb\SwaggerBundle\EventListener\Request\RequestMeta;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
14
15
16
/**
17
 * @author John Kleijn <[email protected]>
18
 */
19
class RequestMatcher implements RequestMatcherInterface
20
{
21
    /**
22
     * @var Repository
23
     */
24
    private $repository;
25
26
    /**
27
     * @param Repository $repository
28
     */
29
    public function __construct(Repository $repository)
30
    {
31
        $this->repository = $repository;
32
    }
33
34
    /**
35
     * @param Request $request
36
     * @return bool
37
     */
38
    public function matches(Request $request)
39
    {
40
        if(!$request->attributes->has(RequestMeta::ATTRIBUTE_URI)){
41
            return false;
42
        }
43
        $description = $this->repository->get($request->attributes->get(RequestMeta::ATTRIBUTE_URI));
44
        $operation   = $description
45
            ->getPath($request->attributes->get(RequestMeta::ATTRIBUTE_PATH))
46
            ->getOperation($request->getMethod());
47
48
        return $operation->isSecured();
49
    }
50
}
51