Test Failed
Pull Request — master (#19)
by Pavel
10:42
created

CrudsRequestCheckerTrait::getRoute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 2.0185
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Listener;
4
5
use ScayTrase\Api\Cruds\CrudsBundle;
6
use Symfony\Component\HttpKernel\Event\KernelEvent;
7
8
trait CrudsRequestCheckerTrait
9
{
10
    /**
11
     * @param KernelEvent $event
12
     *
13
     * @return bool
14
     */
15
    protected function checkRequest(KernelEvent $event)
16
    {
17
        $request = $event->getRequest();
18 26
19
        if (!$request->attributes->get(CrudsBundle::CRUDS_REQUEST_ATTRIBUTE)) {
20 26
            return false;
21
        }
22 26
23
        return true;
24
    }
25
26 26
    protected function getNormalizedCrudApiOptions(KernelEvent $event)
27
    {
28
        $options = $event->getRequest()->attributes->get(CrudsBundle::CRUDS_REQUEST_ATTRIBUTE);
29
        if (!is_array($options)) {
30 26
            return [
31
                'enabled'   => (bool)$options,
32
                'arguments' => [],
33 26
                'context'   => [],
34
            ];
35 26
        }
36 26
37
        return array_merge(['enabled' => false, 'arguments' => [], 'context' => []], $options);
38 26
    }
39
}
40