CharacterHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A convertRequest() 0 15 2
1
<?php
2
3
namespace App\Handler;
4
5
use App\Entity\Product;
6
use Doctrine\ORM\EntityManagerInterface;
7
use Doctrine\ORM\QueryBuilder;
8
use FOS\RestBundle\View\View;
9
use FOS\RestBundle\View\ViewHandlerInterface;
10
use Pagerfanta\Pagerfanta;
11
use Symfony\Component\HttpFoundation\Request;
12
use Pagerfanta\Adapter\DoctrineORMAdapter;
13
use Symfony\Component\HttpFoundation\RequestStack;
14
15
/**
16
 * Class ApiHandler
17
 *
18
 * @package App\Handler
19
 */
20
class CharacterHandler extends ApiHandler
21
{
22
    /**
23
     * @return QueryBuilder
24
     */
25
    public function convertRequest(): QueryBuilder
26
    {
27
        /** @var QueryBuilder $qb */
28
        $qb = $this->qb;
0 ignored issues
show
Bug introduced by
The property qb does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29
        $phrase = $this->request->query->all('phrase', null);
0 ignored issues
show
Unused Code introduced by
The call to ParameterBag::all() has too many arguments starting with 'phrase'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
30
31
        $alias = current($qb->getRootAliases());
32
        if (isset($phrase['phrase'])) {
33
            $qb->add('where',
34
                $qb->expr()->like($alias.'.name', $qb->expr()->literal('%' . $phrase['phrase'] . '%'))
35
            );
36
        }
37
38
        return $qb;
39
    }
40
}
41