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

Variable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 78.56%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 68
ccs 11
cts 14
cp 0.7856
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A is_type() 0 11 1
A __construct() 0 4 1
A name() 0 3 1
A withName() 0 6 1
meaning() 0 1 ?
compile() 0 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\Definition as Def;
14
15
abstract class Variable extends Def\Definition {
16
    // TODO: Use these in Graph/IndexDB.
17
    const CLASS_TYPE = "class";
18
    const FILE_TYPE = "file";
19
    const GLOBAL_TYPE = "global";
20
    const FUNCTION_TYPE = "function";
21
    const METHOD_TYPE = "method";
22
    const LANGUAGE_CONSTRUCT_TYPE = "language construct";
23
24
    static public function is_type($t) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
25
        static $types = array
26
            ( "class"
27
            , "file"
28
            , "global"
29
            , "function"
30
            , "method"
31
            , "language construct"
32
            );
33
        return in_array($t, $types);
34
    }
35
36
    /**
37
     * @var string|null
38
     */
39
    private $name;
40
41 90
    public function __construct($name = null) {
42 90
        assert('is_string($name) || ($name === null)');
43 90
        $this->name = $name;
44 90
    }
45
46
    /**
47
     * @return  string|null
48
     */
49 183
    public function name() {
50 183
        return $this->name;
51
    }
52
53
    /**
54
     * @param   string  $name
55
     * @return  self
56
     */
57 32
    public function withName($name) {
58 32
        assert('is_string($name)');
59 32
        $clone = clone $this;
60 32
        $clone->name = $name;
61 32
        return $clone;
62
    }
63
64
    /**
65
     * Get the meaning of the variable.
66
     *
67
     * In opposite to name, this gives insight in the structure of this variable.
68
     *
69
     * @return  string
70
     */
71
    abstract public function meaning();
72
73
    /**
74
     * Compile the variable to a condition on a graph node.
75
     *
76
     * TODO: Maybe negate can go away.
77
     *
78
     * @param   bool        $negate
79
     * @return  \Closure    Node -> bool
80
     */
81
    abstract public function compile($negate = false);
82
}
83
84