Completed
Push — master ( 7bef7a...470c23 )
by Richard
07:03
created

Variable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 72
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 72
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 14 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
use Lechimp\Dicto\Graph\Predicate;
15
use Lechimp\Dicto\Graph\PredicateFactory;
16
17
abstract class Variable extends Def\Definition {
18
    // TODO: Use these in Graph/IndexDB.
19
    const NAMESPACE_TYPE = "namespace";
20
    const CLASS_TYPE = "class";
21
    const INTERFACE_TYPE = "interface";
22
    const TRAIT_TYPE = "trait";
23
    const FILE_TYPE = "file";
24
    const GLOBAL_TYPE = "global";
25
    const FUNCTION_TYPE = "function";
26
    const METHOD_TYPE = "method";
27
    const LANGUAGE_CONSTRUCT_TYPE = "language construct";
28
29
    public static function is_type($t) {
30
        static $types = array
31
            ( "namespace"
32
            , "class"
33
            , "interface"
34
            , "trait"
35
            , "file"
36
            , "global"
37
            , "function"
38
            , "method"
39
            , "language construct"
40
            );
41
        return in_array($t, $types);
42
    }
43
44
    /**
45
     * @var string|null
46
     */
47
    private $name;
48
49 105
    public function __construct($name = null) {
50 105
        assert('is_string($name) || ($name === null)');
51 105
        $this->name = $name;
52 105
    }
53
54
    /**
55
     * @return  string|null
56
     */
57 307
    public function name() {
58 307
        return $this->name;
59
    }
60
61
    /**
62
     * @param   string  $name
63
     * @return  self
64
     */
65 43
    public function withName($name) {
66 43
        assert('is_string($name)');
67 43
        $clone = clone $this;
68 43
        $clone->name = $name;
69 43
        return $clone;
70
    }
71
72
    /**
73
     * Get the meaning of the variable.
74
     *
75
     * In opposite to name, this gives insight in the structure of this variable.
76
     *
77
     * @return  string
78
     */
79
    abstract public function meaning();
80
81
    /**
82
     * Compile the variable to a predicate on a graph node.
83
     *
84
     * @param   PredicateFactory $f
85
     * @return  Predicate
86
     */
87
    abstract public function compile(PredicateFactory $f);
88
}
89
90