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

_Not   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 29
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A compile() 0 6 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 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