Completed
Push — master ( cc2765...340ff8 )
by Richard
08:19
created

Any   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 61.11%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
lcom 1
cbo 3
dl 14
loc 42
ccs 11
cts 18
cp 0.6111
rs 10
c 2
b 0
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A meaning() 0 4 1
B compile() 14 19 5

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
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
4
 * 
5
 * Copyright (c) 2016 Richard Klees <[email protected]>
6
 *
7
 * This software is licensed under The MIT License. You should have received 
8
 * a copy of the license along with the code.
9
 */
10
11
namespace Lechimp\Dicto\Variables;
12
13
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
14
15
/**
16
 * Variable matching any of the sub variables.
17
 */
18
class Any extends Variable {
19
    /**
20
     * @var Variable[]
21
     */
22
    protected $variables;
23
24 10
    public function __construct(array $variables) {
25 10
        parent::__construct();
26
        $this->variables = array_map(function(Variable $v) { return $v; }, $variables);
27 10
    }
28
29
    /**
30
     * @inheritdocs
31
     */
32
    public function meaning() {
33
        $meanings = array_map(function($v) { return $v->meaning(); }, $this->variables);
34 49
        return "{".implode(", ", $meanings)."}";
35
    }
36
37
    /**
38
     * @inheritdocs
39
     */
40 3
    public function compile(ExpressionBuilder $builder, $table_name, $negate = false) {
41
        // normal case: 1 or 2 or 3 ...
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
42 3 View Code Duplication
        if (!$negate) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
43 3
            $orX = $builder->orX();
44 3
            foreach ($this->variables as $variable) {
45 3
                $orX->add($variable->compile($builder, $table_name));
46 3
            }
47 3
            return $orX;
48
        }
49
        // negated case: not (left_condition or right_condition)
50
        //             = not left_condition and not right_condition
51 View Code Duplication
        if ($negate) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
52
            $andX = $builder->andX();
53
            foreach ($this->variables as $variable) {
54
                $andX->add($variable->compile($builder, $table_name, true));
55
            }
56
            return $andX;
57
        }
58
    }
59
}
60
61