Completed
Push — master ( a68cc8...839f22 )
by Pavel
09:30
created

CrudsRequestCheckerTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 76.92%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 5
dl 0
loc 37
ccs 10
cts 13
cp 0.7692
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
getRouter() 0 1 ?
A checkRequest() 0 14 3
A getRoute() 0 11 2
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Listener;
4
5
use Symfony\Component\HttpKernel\Event\KernelEvent;
6
use Symfony\Component\Routing\RouterInterface;
7
8
trait CrudsRequestCheckerTrait
9
{
10
    /** @return RouterInterface */
11
    abstract protected function getRouter();
12
13
    /**
14
     * @param KernelEvent $event
15
     *
16
     * @return bool
17
     */
18 12
    protected function checkRequest(KernelEvent $event)
19
    {
20 12
        $route = $this->getRoute($event);
21
22 12
        if (null === $route) {
23
            return false;
24
        }
25
26 12
        if (!$route->getOption('cruds_api')) {
27
            return false;
28
        }
29
30 12
        return true;
31
    }
32
33 12
    protected function getRoute(KernelEvent $event)
34
    {
35 12
        $request = $event->getRequest();
36 12
        $route   = $request->attributes->get('_route');
37
38 12
        if (null === $route) {
39
            return null;
40
        }
41
42 12
        return $this->getRouter()->getRouteCollection()->get($route);
43
    }
44
}
45