SpecificationQueryHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 28
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handleSpecification() 0 7 1
1
<?php
2
3
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
namespace GpsLab\Component\Query\Specification;
12
13
use Doctrine\ORM\EntityManagerInterface;
14
use Happyr\DoctrineSpecification\EntitySpecificationRepositoryInterface;
15
16
class SpecificationQueryHandler
17
{
18
    /**
19
     * @var EntityManagerInterface
20
     */
21
    private $em;
22
23
    /**
24
     * @param EntityManagerInterface $em
25
     */
26 1
    public function __construct(EntityManagerInterface $em)
27
    {
28 1
        $this->em = $em;
29 1
    }
30
31
    /**
32
     * @param SpecificationQuery $query
33
     *
34
     * @return mixed
35
     */
36 1
    public function handleSpecification(SpecificationQuery $query)
37
    {
38
        /* @var $rep EntitySpecificationRepositoryInterface */
39 1
        $rep = $this->em->getRepository($query->entity());
40
41 1
        return $rep->match($query->spec(), $query->modifier());
0 ignored issues
show
Bug introduced by
It seems like $query->modifier() can be null; however, match() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
42
    }
43
}
44