Completed
Push — master ( d1b735...0bfc48 )
by Daniel
08:29
created

Composite   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 40 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 16
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 16 16 2
A getExpressions() 0 4 1
A getType() 0 4 1

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
declare(strict_types=1);
4
5
namespace Psi\Component\ObjectAgent\Query;
6
7
class Composite implements Expression
8
{
9
    const AND = 'and';
10
    const OR = 'or';
11
12
    private static $validTypes = [
13
        self::AND,
14
        self::OR,
15
    ];
16
17
    private $expressions;
18
    private $type;
19
20 View Code Duplication
    public function __construct(string $type, array $expressions)
0 ignored issues
show
Duplication introduced by
This method 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...
21
    {
22
        // ensure types
23
        array_map(function (Expression $expr) {
0 ignored issues
show
Unused Code introduced by
The parameter $expr is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
        }, $expressions);
25
26
        if (!in_array($type, self::$validTypes)) {
27
            throw new \InvalidArgumentException(sprintf(
28
                'Invalid composite type "%s", must be one of "%s"',
29
                $type, implode('", "', self::$validTypes)
30
            ));
31
        }
32
33
        $this->expressions = $expressions;
34
        $this->type = $type;
35
    }
36
37
    public function getExpressions()
38
    {
39
        return $this->expressions;
40
    }
41
42
    public function getType()
43
    {
44
        return $this->type;
45
    }
46
}
47