Completed
Push — master ( 04aca3...4b3d1a )
by
unknown
03:17
created

TransformFilteringParametersListener   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
dl 17
loc 17
rs 10
c 0
b 0
f 0
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A onKernelRequest() 14 14 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\JsonApi\EventListener;
15
16
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
17
18
/**
19
 * @see http://jsonapi.org/format/#fetching-filtering
20
 * @see http://jsonapi.org/recommendations/#filtering
21
 *
22
 * @author Héctor Hurtarte <[email protected]>
23
 * @author Baptiste Meyer <[email protected]>
24
 */
25 View Code Duplication
final class TransformFilteringParametersListener
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
{
27
    public function onKernelRequest(GetResponseEvent $event)
28
    {
29
        $request = $event->getRequest();
30
31
        if (
32
            'jsonapi' !== $request->getRequestFormat() ||
33
            null === ($filterParameters = $request->query->get('filter')) ||
34
            !is_array($filterParameters)
35
        ) {
36
            return;
37
        }
38
39
        $request->attributes->set('_api_filter_common', $filterParameters);
40
    }
41
}
42