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

_Custom::_compile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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