GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SpecificationRepositoryTrait::modifyQueryBuilder()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace Rb\Specification\Doctrine;
4
5
use Doctrine\ORM\Query;
6
use Doctrine\ORM\QueryBuilder;
7
use Rb\Specification\Doctrine\Exception\LogicException;
8
use Rb\Specification\Doctrine\Result\ModifierInterface;
9
10
/**
11
 * Class SpecificationRepositoryTrait.
12
 */
13
trait SpecificationRepositoryTrait
14
{
15
    /**
16
     * @var string
17
     */
18
    protected $dqlAlias = 'e';
19
20
    /**
21
     * @see SpecificationAwareInterface::match()
22
     *
23
     * @param SpecificationInterface $specification
24
     * @param ModifierInterface|null $modifier
25
     *
26
     * @throws LogicException
27
     *
28
     * @return Query
29
     */
30
    public function match(SpecificationInterface $specification, ModifierInterface $modifier = null)
31
    {
32
        if (! $specification->isSatisfiedBy($this->getEntityName())) {
0 ignored issues
show
Bug introduced by
It seems like getEntityName() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
33
            throw new LogicException(sprintf(
34
                'Specification "%s" not supported by this repository!',
35
                get_class($specification)
36
            ));
37
        }
38
39
        $queryBuilder = $this->createQueryBuilder($this->dqlAlias);
0 ignored issues
show
Bug introduced by
It seems like createQueryBuilder() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
40
        $this->modifyQueryBuilder($queryBuilder, $specification);
41
42
        return $this->modifyQuery($queryBuilder, $modifier);
43
    }
44
45
    /**
46
     * Modifies the QueryBuilder according to the passed Specification.
47
     * Will also set the condition for this query if needed.
48
     *
49
     * @param QueryBuilder           $queryBuilder
50
     * @param SpecificationInterface $specification
51
     *
52
     * @internal param string $dqlAlias
53
     */
54
    private function modifyQueryBuilder(QueryBuilder $queryBuilder, SpecificationInterface $specification)
55
    {
56
        $condition = $specification->modify($queryBuilder, $this->dqlAlias);
57
58
        if (empty($condition)) {
59
            return;
60
        }
61
62
        $queryBuilder->where($condition);
63
    }
64
65
    /**
66
     * Modifies and returns a Query object according to the (optional) result modifier.
67
     *
68
     * @param QueryBuilder           $queryBuilder
69
     * @param ModifierInterface|null $modifier
70
     *
71
     * @return Query
72
     */
73
    private function modifyQuery(QueryBuilder $queryBuilder, ModifierInterface $modifier = null)
74
    {
75
        $query = $queryBuilder->getQuery();
76
77
        if ($modifier) {
78
            $modifier->modify($query);
79
        }
80
81
        return $query;
82
    }
83
}
84