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

Except::id()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 1
cc 1
eloc 2
nc 1
nop 0
crap 1
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