Completed
Push — master ( cfe8d7...fcc746 )
by André
19:36 queued 06:48
created

LogicalOperator::__construct()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 22
Code Lines 14

Duplication

Lines 22
Ratio 100 %

Importance

Changes 0
Metric Value
cc 6
eloc 14
nc 6
nop 1
dl 22
loc 22
rs 8.6737
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\API\Repository\Values\URL\Query\Criterion;
8
9
use eZ\Publish\API\Repository\Values\URL\Query\Criterion;
10
use InvalidArgumentException;
11
12 View Code Duplication
abstract class LogicalOperator extends Criterion
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
{
14
    /**
15
     * The set of criteria combined by the logical operator.
16
     *
17
     * @var Criterion[]
18
     */
19
    public $criteria = [];
20
21
    /**
22
     * Creates a Logic operation with the given criteria.
23
     *
24
     * @param Criterion[] $criteria
25
     *
26
     * @throws \InvalidArgumentException
27
     */
28
    public function __construct(array $criteria)
29
    {
30
        foreach ($criteria as $key => $criterion) {
31
            if (!$criterion instanceof Criterion) {
32
                if ($criterion === null) {
33
                    $type = 'null';
34
                } elseif (is_object($criterion)) {
35
                    $type = get_class($criterion);
36
                } elseif (is_array($criterion)) {
37
                    $type = 'Array, with keys: ' . implode(', ', array_keys($criterion));
38
                } else {
39
                    $type = gettype($criterion) . ", with value: '{$criterion}'";
40
                }
41
42
                throw new InvalidArgumentException(
43
                    "Only Criterion objects are accepted, at index '{$key}': " . $type
44
                );
45
            }
46
47
            $this->criteria[] = $criterion;
48
        }
49
    }
50
}
51