Failed Conditions
Pull Request — experimental/3.1 (#2285)
by Kiyotaka
41:31
created

Queries   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addCustomizer() 0 14 4
A customize() 0 10 3
1
<?php
2
3
4
namespace Eccube\Doctrine\Query;
5
6
7
use Doctrine\Common\Annotations\AnnotationReader;
8
use Doctrine\ORM\QueryBuilder;
9
use Eccube\Annotation\QueryExtension;
10
use Psr\Log\InvalidArgumentException;
11
12
class Queries
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
13
{
14
15
    private $customizers = [];
16
17
    public function addCustomizer(QueryCustomizer $customizer) {
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
18
        if (!$customizer) {
19
            throw new InvalidArgumentException('Customizer should not be null.');
20
        }
21
        $reader = new AnnotationReader();
22
        $rc = new \ReflectionClass($customizer);
23
        $anno = $reader->getClassAnnotation($rc, QueryExtension::class);
24
        if (!$anno) {
25
            throw new InvalidArgumentException(get_class($customizer).' doesn\'t have any '.QueryExtension::class.' annotation.');
26
        }
27
        foreach ($anno->value as $queryKey) {
28
            $this->customizers[$queryKey][] = $customizer;
29
        }
30
    }
31
32
    public function customize($queryKey, QueryBuilder $builder, $params)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
33
    {
34
        if (isset($this->customizers[$queryKey])) {
35
            /* @var QueryCustomizer $customizer */
36
            foreach ($this->customizers[$queryKey] as $customizer) {
37
                $customizer->customize($builder, $params, $queryKey);
38
            }
39
        }
40
        return $builder;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
41
    }
42
}