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

_Not::compile_to_source()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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