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

SearchQueryFactoryBase::createFromConstraints()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
nop 2
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