Test Failed
Push — master ( 25b8d1...f70cb8 )
by Pavel
03:49
created

CrudsRequestCheckerTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 5
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
getRouter() 0 1 ?
B checkRequest() 0 22 4
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
    protected function checkRequest(KernelEvent $event)
19
    {
20
        $request = $event->getRequest();
21
        $route   = $request->attributes->get('_route');
22
23
        if (null === $route) {
24
            return false;
25
        }
26
27
        $collection = $this->getRouter()->getRouteCollection();
28
        $route      = $collection->get($route);
29
30
        if (null === $route) {
31
            return false;
32
        }
33
34
        if (!$route->getOption('cruds_api')) {
35
            return false;
36
        }
37
38
        return true;
39
    }
40
}
41