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

Except   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 43.75 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
lcom 0
cbo 2
dl 14
loc 32
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A id() 0 3 1
A compile() 14 20 4

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, 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