Completed
Push — master ( e666ea...addc16 )
by Richard
05:13
created

Any::compile()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 10
cts 10
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\Variables;
12
13
use Lechimp\Dicto\Graph\Node;
14
15
/**
16
 * Variable matching any of the sub variables.
17
 */
18
class Any extends Variable {
19
    /**
20
     * @var Variable[]
21
     */
22
    protected $variables;
23
24 11
    public function __construct(array $variables) {
25 11
        parent::__construct();
26
        $this->variables = array_map(function(Variable $v) { return $v; }, $variables);
27 11
    }
28
29
    /**
30
     * @inheritdocs
31
     */
32 49
    public function meaning() {
33
        $meanings = array_map(function($v) { return $v->meaning(); }, $this->variables);
34 49
        return "{".implode(", ", $meanings)."}";
35
    }
36
37
    /**
38
     * @inheritdocs
39
     */
40 7
    public function compile() {
41
        $conditions = array_map(function(Variable $v) {
42 7
            return $v->compile();
43 7
        }, $this->variables);
44
45 7
        return function(Node $n) use (&$conditions) {
46 7
            foreach ($conditions as $condition) {
47 7
                if ($condition($n)) {
48 3
                    return true;
49
                }
50 7
            }
51 7
            return false;
52 7
        };
53
    }
54
}
55
56