Completed
Push — master ( f7852e...e666ea )
by Richard
06:08
created

Any::compile()   C

Complexity

Conditions 7
Paths 3

Size

Total Lines 29
Code Lines 16

Duplication

Lines 20
Ratio 68.97 %

Code Coverage

Tests 18
CRAP Score 7.0071

Importance

Changes 0
Metric Value
dl 20
loc 29
ccs 18
cts 19
cp 0.9474
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 16
nc 3
nop 1
crap 7.0071
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 Lechimp\Dicto\Graph\Node;
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 12
    public function __construct(array $variables) {
25 12
        parent::__construct();
26
        $this->variables = array_map(function(Variable $v) { return $v; }, $variables);
27 12
    }
28
29
    /**
30
     * @inheritdocs
31
     */
32 49
    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 8
    public function compile($negate = false) {
41
        $conditions = array_map(function(Variable $v) use ($negate) {
42 8
            return $v->compile($negate);
43 8
        }, $this->variables);
44
45
        // 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...
46 8 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...
47
            return function(Node $n) use (&$conditions) {
48 7
                foreach ($conditions as $condition) {
49 7
                    if ($condition($n)) {
50 3
                        return true;
51
                    }
52 7
                }
53 7
                return false;
54 7
            };
55
        }
56
        // negated case: not (left_condition or right_condition)
57
        //             = not left_condition and not right_condition
58 1 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...
59 1
            return function(Node $n) use (&$conditions) {
60 1
                foreach ($conditions as $condition) {
61 1
                    if (!$condition($n)) {
62 1
                        return false;
63
                    }
64 1
                }
65 1
                return true;
66 1
            };
67
        }
68
    }
69
}
70
71