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

_Custom   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 81.82%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 34
ccs 9
cts 11
cp 0.8182
rs 10
c 1
b 0
f 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A _compile() 0 3 1
A compile_to_source() 0 6 1
A for_types() 0 3 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\Entity;
14
use Lechimp\Dicto\Graph\Predicate;
15
16
/**
17
 * A custom predicate on an entity.
18
 */
19
class _Custom extends Predicate {
20
    /**
21
     * @var \Closure 
22
     */
23
    protected $predicate;
24
25 30
    public function __construct(\Closure $predicate) {
26 30
        $this->predicate = $predicate;
27 30
    }
28
29
    /**
30
     * @inheritdocs
31
     */
32
    public function _compile() {
33
        return $this->predicate;
34
    }
35
36
    /**
37
     * @inheritdocs
38
     */
39 27
    public function compile_to_source(array &$custom_closures) {
40 27
        $num = count($custom_closures);
41 27
        $custom_closures[] = $this->predicate;
42
        return
43 27
            "    \$value = \$custom_closures[$num](\$e);\n";
44
    }
45
46
    /**
47
     * @inheritdocs
48
     */
49 4
    public function for_types(array $existing_types) {
50 4
        return $existing_types;
51
    }
52
}
53