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

LogicalOperator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 39
loc 39
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 22 22 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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