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.
Completed
Push — master ( 48537c...c7a876 )
by Rik
02:13
created

SpecificationRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 6
Bugs 1 Features 2
Metric Value
wmc 6
c 6
b 1
f 2
lcom 1
cbo 5
dl 0
loc 71
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 14 2
A modifyQueryBuilder() 0 10 2
A modifyQuery() 0 10 2
1
<?php
2
3
namespace Rb\Specification\Doctrine;
4
5
use Doctrine\ORM\EntityRepository;
6
use Doctrine\ORM\Query;
7
use Doctrine\ORM\QueryBuilder;
8
use Rb\Specification\Doctrine\Exception\LogicException;
9
use Rb\Specification\Doctrine\Result\ModifierInterface;
10
11
/**
12
 * Class SpecificationRepository.
13
 */
14
class SpecificationRepository extends EntityRepository
15
{
16
    /**
17
     * @var string
18
     */
19
    private $dqlAlias = 'e';
20
21
    /**
22
     * Get the query after matching with given specification.
23
     *
24
     * @param SpecificationInterface $specification
25
     * @param ModifierInterface      $modifier
26
     *
27
     * @throws LogicException
28
     *
29
     * @return Query
30
     */
31
    public function match(SpecificationInterface $specification, ModifierInterface $modifier = null)
32
    {
33
        if (! $specification->isSatisfiedBy($this->getEntityName())) {
34
            throw new LogicException(sprintf(
35
                'Specification "%s" not supported by this repository!',
36
                get_class($specification)
37
            ));
38
        }
39
40
        $queryBuilder = $this->createQueryBuilder($this->dqlAlias);
41
        $this->modifyQueryBuilder($queryBuilder, $specification);
42
43
        return $this->modifyQuery($queryBuilder, $modifier);
44
    }
45
46
    /**
47
     * Modifies the QueryBuilder according to the passed Specification.
48
     * Will also set the condition for this query if needed.
49
     *
50
     * @param QueryBuilder           $queryBuilder
51
     * @param SpecificationInterface $specification
52
     *
53
     * @internal param string $dqlAlias
54
     */
55
    private function modifyQueryBuilder(QueryBuilder $queryBuilder, SpecificationInterface $specification)
56
    {
57
        $condition = $specification->modify($queryBuilder, $this->dqlAlias);
58
59
        if (empty($condition)) {
60
            return;
61
        }
62
63
        $queryBuilder->where($condition);
64
    }
65
66
    /**
67
     * Modifies and returns a Query object according to the (optional) result modifier.
68
     *
69
     * @param QueryBuilder           $queryBuilder
70
     * @param ModifierInterface|null $modifier
71
     *
72
     * @return Query
73
     */
74
    private function modifyQuery(QueryBuilder $queryBuilder, ModifierInterface $modifier = null)
75
    {
76
        $query = $queryBuilder->getQuery();
77
78
        if ($modifier) {
79
            $modifier->modify($query);
80
        }
81
82
        return $query;
83
    }
84
}
85