Completed
Push — master ( 1e9ef5...3740bc )
by Richard
05:53 queued 29s
created

_Not::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
c 1
b 0
f 1
cc 1
eloc 2
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 10
    public function __construct(Predicate $predicate) {
26 10
        $this->predicate = $predicate;
27 10
    }
28
29
    /**
30
     * @inheritdocs
31
     */
32 8
    public function compile() {
33 8
        $compiled = $this->predicate->compile();
34 8
        return function(Entity $e) use ($compiled) { 
35 8
            return !$compiled($e);
36 8
        };
37
    }
38
39
    /**
40
     * @inheritdocs
41
     */
42 8
    public function for_types($existing_types) {
43
        // Can't really know what is in predicate, so this could match
44
        // all types.
45 8
        return $existing_types;
46
    }
47
}
48