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

Except::compile()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 20
Code Lines 11

Duplication

Lines 14
Ratio 70 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 14
loc 20
ccs 11
cts 11
cp 1
rs 9.2
c 1
b 0
f 1
cc 4
eloc 11
nc 2
nop 1
crap 4
1
<?php
2
/******************************************************************************
3
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
4
 * 
5
 * Copyright (c) 2016, 2015 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
class Except extends Combinator {
16
    /**
17
     * @inheritdocs
18
     */
19 49
    public function id() {
20 49
        return "except";
21
    }
22
23
    /**
24
     * @inheritdocs
25
     */
26 8
    public function compile($negate = false) {
27 8
        $left_condition = $this->left()->compile($negate);
28 8
        $right_condition = $this->right()->compile($negate);
29
30
        // normal case: left_condition and not right_condition
31 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...
32
            return function(Node $n) use ($left_condition, $right_condition) {
33 7
                return $left_condition($n)
34 7
                    && !$right_condition($n);
35 7
            };
36
        }
37
        // negated case: not (left_condition and not right_condition)
38
        //             = not left_condition or right_condition
39
        else {
40 1
            return function(Node $n) use ($left_condition, $right_condition) {
41 1
                return $left_condition($n)
42 1
                    || !$right_condition($n);
43 1
            };
44
        }
45
    }
46
}
47