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

Any::compile()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 19
Code Lines 11

Duplication

Lines 14
Ratio 73.68 %

Code Coverage

Tests 7
CRAP Score 8.125

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 14
loc 19
ccs 7
cts 14
cp 0.5
rs 8.8571
c 2
b 0
f 1
cc 5
eloc 11
nc 5
nop 3
crap 8.125
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