Completed
Pull Request — master (#397)
by Kristof
03:55
created

SearchQueryFactoryBase   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 42
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromConstraint() 0 6 1
A createFromConstraints() 0 16 3
createQueryString() 0 4 ?
1
<?php
2
3
namespace CultuurNet\UDB3\Offer\Security;
4
5
use CultuurNet\Search\Parameter\Query;
6
use ValueObjects\StringLiteral\StringLiteral;
7
8
abstract class SearchQueryFactoryBase implements SearchQueryFactoryInterface
9
{
10
    /**
11
     * @inheritdoc
12
     */
13
    public function createFromConstraint(
14
        StringLiteral $constraint,
15
        StringLiteral $offerId
16
    ) {
17
        return new Query($this->createQueryString($constraint, $offerId));
18
    }
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function createFromConstraints(
24
        array $constraints,
25
        StringLiteral $offerId
26
    ) {
27
        $queryString = '';
28
29
        foreach ($constraints as $constraint) {
30
            if (strlen($queryString)) {
31
                $queryString .= ' OR ';
32
            }
33
34
            $queryString .= $this->createQueryString($constraint, $offerId);
35
        }
36
37
        return new Query($queryString);
38
    }
39
40
    /**
41
     * @param StringLiteral $constraint
42
     * @param StringLiteral $offerId
43
     * @return string
44
     */
45
    abstract protected function createQueryString(
46
        StringLiteral $constraint,
47
        StringLiteral $offerId
48
    );
49
}
50