Completed
Push — master ( 7e8f6f...c3bf25 )
by Дмитрий
04:06
created

TraitDefinition::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 9.4285
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
    private $statement;
22
23
    /**
24
     * @var ClassMethod[]
25
     */
26
    private $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