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

_And::compile()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
dl 14
loc 14
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 1
nop 0
crap 3
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
 * A predicate that is true if all of its subpredicates are true.
16
 */
17 View Code Duplication
class _And 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...
18
    /**
19
     * @inheritdocs
20
     */
21 30
    public function compile() {
22
        $compiled = array_map(function($p) {
23 30
            return $p->compile();
24 30
        }, $this->predicates);
25
26
        return function(Entity $e) use ($compiled) { 
27 30
            foreach ($compiled as $predicate) {
28 30
                if (!$predicate($e)) {
29 19
                    return false;
30
                }
31 27
            }
32 22
            return true;
33 30
        };
34
    }
35
36
    /**
37
     * @inheritdocs
38
     */
39
    public function for_types($existing_types) {
40 19
        $tss = array_map(function($p) use ($existing_types) {
41 19
            return $p->for_types($existing_types);
42 19
        }, $this->predicates);
43
44 19
        return array_values(call_user_func_array("array_intersect", $tss));
45
    }
46
}
47