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
Pull Request — master (#15)
by
unknown
06:31
created

SpecificationRepository   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
lcom 1
cbo 7
dl 0
loc 99
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 14 2
A countMatching() 0 17 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
     * Get the query for a "SELECT COUNT(e) FROM entityName" after matching with given specification.
48
     *
49
     * @param SpecificationInterface $specification
50
     * @param ModifierInterface      $modifier
51
     *
52
     * @throws LogicException
53
     *
54
     * @return Query
55
     */
56
    public function countMatching(SpecificationInterface $specification, ModifierInterface $modifier = null)
57
    {
58
        if (! $specification->isSatisfiedBy($this->getEntityName())) {
59
            throw new LogicException(sprintf(
60
                'Specification "%s" not supported by this repository!',
61
                get_class($specification)
62
            ));
63
        }
64
65
        $queryBuilder = $this->getEntityManager()->createQueryBuilder()->select(
66
            $this->getEntityManager()->getExpressionBuilder()->count($this->dqlAlias)
67
        )
68
            ->from($this->_entityName, $this->dqlAlias);
69
        $this->modifyQueryBuilder($queryBuilder, $specification);
70
71
        return $this->modifyQuery($queryBuilder, $modifier);
72
    }
73
    
74
    /**
75
     * Modifies the QueryBuilder according to the passed Specification.
76
     * Will also set the condition for this query if needed.
77
     *
78
     * @param QueryBuilder           $queryBuilder
79
     * @param SpecificationInterface $specification
80
     *
81
     * @internal param string $dqlAlias
82
     */
83
    private function modifyQueryBuilder(QueryBuilder $queryBuilder, SpecificationInterface $specification)
84
    {
85
        $condition = $specification->modify($queryBuilder, $this->dqlAlias);
86
87
        if (empty($condition)) {
88
            return;
89
        }
90
91
        $queryBuilder->where($condition);
92
    }
93
94
    /**
95
     * Modifies and returns a Query object according to the (optional) result modifier.
96
     *
97
     * @param QueryBuilder           $queryBuilder
98
     * @param ModifierInterface|null $modifier
99
     *
100
     * @return Query
101
     */
102
    private function modifyQuery(QueryBuilder $queryBuilder, ModifierInterface $modifier = null)
103
    {
104
        $query = $queryBuilder->getQuery();
105
106
        if ($modifier) {
107
            $modifier->modify($query);
108
        }
109
110
        return $query;
111
    }
112
}
113