Completed
Pull Request — master (#4)
by GBProd
02:33
created

Handler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 50
ccs 6
cts 12
cp 0.5
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A handle() 0 6 1
A registerFactory() 0 4 1
1
<?php
2
3
namespace GBProd\DoctrineSpecification;
4
5
use Doctrine\ORM\QueryBuilder;
6
use GBProd\DoctrineSpecification\QueryFactory\AndXFactory;
7
use GBProd\DoctrineSpecification\QueryFactory\Factory;
8
use GBProd\DoctrineSpecification\QueryFactory\NotFactory;
9
use GBProd\DoctrineSpecification\QueryFactory\OrXFactory;
10
use GBProd\Specification\AndX;
11
use GBProd\Specification\Not;
12
use GBProd\Specification\OrX;
13
use GBProd\Specification\Specification;
14
15
/**
16
 * Handler for doctrine specifications
17
 *
18
 * @author gbprod <[email protected]>
19
 */
20
class Handler
21
{
22
    /**
23
     * @var Registry
24
     */
25
    private $registry;
26
27
    /**
28
     * @var QueryBuilder
29
     */
30
    private $qb;
31
32
    /**
33
     * @param Registry     $registry
34
     * @param QueryBuilder $qb
35
     */
36 1
    public function __construct(Registry $registry, QueryBuilder $qb)
0 ignored issues
show
Unused Code introduced by
The parameter $qb is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
37
    {
38 1
        $this->registry = $registry;
39
40 1
        $this->registry->register(AndX::class, new AndXFactory($registry));
41 1
        $this->registry->register(OrX::class, new OrXFactory($registry));
42 1
        $this->registry->register(Not::class, new NotFactory($registry));
43 1
    }
44
45
    /**
46
     * handle specification for queryfactory
47
     *
48
     * @param Specification $spec
49
     *
50
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be \Doctrine\ORM\Query\Expr\Base?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
51
     */
52
    public function handle(Specification $spec)
53
    {
54
        $factory = $this->registry->getFactory($spec);
55
56
        return $factory->create($spec, $this->qb);
57
    }
58
59
    /**
60
     * Register a factory for specification
61
     *
62
     * @param string  $classname specification fully qualified classname
63
     * @param Factory $factory
64
     */
65
    public function registerFactory($classname, Factory $factory)
66
    {
67
        $this->registry->register($classname, $factory);
68
    }
69
}
70