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

_Or::_compile()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 12
loc 12
ccs 0
cts 9
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 1
nop 0
crap 12
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
15
/**
16
 * A predicate that is true if any of its subpredicates are true.
17
 */
18 View Code Duplication
class _Or extends _Combined {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
    /**
20
     * @inheritdocs
21
     */
22
    public function _compile() {
23
        $compiled = $this->compiled_predicates();
24
25
        return function(Entity $e) use ($compiled) { 
26
            foreach ($compiled as $predicate) {
27
                if ($predicate($e)) {
28
                    return true;
29
                }
30
            }
31
            return false;
32
        };
33
    }
34
35
    /**
36
     * @inheritdocs
37
     */
38 43
    public function compile_to_source(array &$custom_closures) {
39
        $code =
40 43
            "    while(true) {\n";
41 43
        foreach ($this->predicates as $predicate) {
42
            $code .=
43 43
                 $predicate->compile_to_source($custom_closures).
44 43
            "    if (\$value) break;\n";
45 43
        }
46
        return
47
            $code.
48 43
            "break;\n".
49 43
            "}\n";
50
    }
51
52
    /**
53
     * @inheritdocs
54
     */
55 33
    public function for_types(array $existing_types) {
56 33
        $tss = $this->for_types_of_predicates($existing_types);
57 33
        return array_values(array_unique(call_user_func_array("array_merge", $tss)));
58
    }
59
}
60