Completed
Push — master ( 05840b...9b2a73 )
by Richard
05:47
created

_Not   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 61.53%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 38
ccs 8
cts 13
cp 0.6153
rs 10
c 1
b 0
f 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A _compile() 0 6 1
A compile_to_source() 0 5 1
A for_types() 0 5 1
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\Graph\Predicate;
12
13
use Lechimp\Dicto\Graph\Predicate;
14
use Lechimp\Dicto\Graph\Entity;
15
16
/**
17
 * A predicate that negates another predicate;
18
 */
19
class _Not extends _Combined {
20
    /**
21
     * @var Predicate
22
     */
23
    protected $predicate;
24
25 22
    public function __construct(Predicate $predicate) {
26 22
        $this->predicate = $predicate;
27 22
    }
28
29
    /**
30
     * @inheritdocs
31
     */
32
    public function _compile() {
33
        $compiled = $this->predicate->compile();
34
        return function(Entity $e) use ($compiled) { 
35
            return !$compiled($e);
36
        };
37
    }
38
39
    /**
40
     * @inheritdocs
41
     */
42 19
    public function compile_to_source(array &$custom_closures) {
43
        return
44 19
            $this->predicate->compile_to_source($custom_closures).
45 19
            "    \$value = !\$value;\n";
46
    }
47
48
    /**
49
     * @inheritdocs
50
     */
51 19
    public function for_types(array $existing_types) {
52
        // Can't really know what is in predicate, so this could match
53
        // all types.
54 19
        return $existing_types;
55
    }
56
}
57