Completed
Push — master ( c3bf25...e60cd1 )
by Дмитрий
04:08 queued 01:24
created

TraitDefinition::getMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * @author Patsura Dmitry https://github.com/ovr <[email protected]>
4
 */
5
6
namespace PHPSA\Definition;
7
8
use PHPSA\Context;
9
use PhpParser\Node\Stmt;
10
11
class TraitDefinition extends ParentDefinition
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $filepath;
17
18
    /**
19
     * @var Stmt\Trait_
20
     */
21
    protected $statement;
22
23
    /**
24
     * @var ClassMethod[]
25
     */
26
    protected $methods = [];
27
28
    public function __construct($name, Stmt\Trait_ $statement)
29
    {
30
        $this->name = $name;
31
        $this->statement = $statement;
32
    }
33
34
    /**
35
     * Compile the definition
36
     *
37
     * @param Context $context
38
     * @return boolean
39
     */
40
    public function compile(Context $context)
41
    {
42
        return true;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getFilepath()
49
    {
50
        return $this->filepath;
51
    }
52
53
    /**
54
     * @param string $filepath
55
     */
56
    public function setFilepath($filepath)
57
    {
58
        $this->filepath = $filepath;
59
    }
60
61
    /**
62
     * @return bool
63
     */
64
    public function precompile()
65
    {
66
        foreach ($this->statement->stmts as $stmt) {
67
            if ($stmt instanceof Stmt\ClassMethod) {
68
                $this->addMethod(new ClassMethod($stmt->name, $stmt, $stmt->type));
69
            }
70
        }
71
72
        return true;
73
    }
74
75
    /**
76
     * @param $method
77
     */
78
    public function addMethod($method)
79
    {
80
        $this->methods[] = $method;
81
    }
82
83
    /**
84
     * @return ClassMethod[]
85
     */
86
    public function getMethods()
87
    {
88
        return $this->methods;
89
    }
90
}
91