Completed
Push — master ( 69f641...8fff44 )
by Richard
05:35
created

LanguageConstruct::entity_name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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
// TODO: Maybe this should not extend Entities
16
class LanguageConstruct extends Entities {
17
    /**
18
     * @var string
19
     */
20
    private $construct_name;
21
22 38
    public function __construct($construct_name, $name = null) {
23 38
        parent::__construct($name);
24 38
        assert('is_string($construct_name)');
25
        // TODO: Restrict the possible construct_names (like @, unset, echo, ...)
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
26 38
        $this->construct_name = $construct_name;     
27 38
    }
28
29
    /**
30
     * @return  string
31
     */
32 35
    public function construct_name() {
33 35
        return $this->construct_name;
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39 33
    public function meaning() {
40 33
        return $this->construct_name();
41
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46 1
    public function id() {
47 1
        return Variable::LANGUAGE_CONSTRUCT_TYPE;
48
    }
49
50
    /**
51
     * @inheritdocs
52
     */
53 4
    public function compile($negate = false) {
54 4
        if (!$negate) {
55
            return function(Node $n) {
56 4
                return $n->type() == Variable::LANGUAGE_CONSTRUCT_TYPE
57 4
                    && $n->property("name") == $this->construct_name();
58 4
            };
59
        }
60
        else {
61
            return function(Node $n) {
62
                return $n->type() != Variable::LANGUAGE_CONSTRUCT_TYPE
63
                    || $n->property("name") != $this->construct_name();
64
            };
65
        }
66
67
    }
68
}
69
70