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

Handler::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
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