Completed
Push — master ( f7852e...e666ea )
by Richard
06:08
created

Entities::compile()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 2
nop 1
crap 4
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
abstract class Entities extends Variable {
16 88
    public function __construct($name= null) {
17 88
        if ($name === null) {
18 70
            $name = ucfirst($this->entity_name());
19 70
        }
20 88
        parent::__construct($name);
21 88
    }
22
23
    /**
24
     * Get an id for the type of entity.
25
     *
26
     * @return  string
27
     */
28
    abstract public function id();
29
30
    /**
31
     * Get the name of the entity.
32
     *
33
     * TODO: Check, if that is really necessary.
34
     *
35
     * @return string
36
     */
37
    abstract public function entity_name();
38
39
    /**
40
     * @inheritdocs
41
     */
42 124
    public function meaning() {
43 124
        return $this->entity_name();
44
    }
45
46
    /**
47
     * @inheritdocs
48
     */
49 39
    public function compile($negate = false) {
50 39
        if (!$negate) {
51
            return function(Node $n) {
52 30
                return $n->type() == $this->id()
53 30
                    || $n->type() == $this->id()." reference";
54 31
            };
55
        }
56
        else {
57 9
            return function(Node $n) {
58 9
                return $n->type() != $this->id()
59 9
                    && $n->type() != $this->id()." reference";
60 9
            };
61
        }
62
    }
63
}
64
65