1 | <?php |
||
17 | class FunctionDefinition extends ParentDefinition |
||
18 | { |
||
19 | /** |
||
20 | * @todo Use Finder |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $filepath; |
||
25 | |||
26 | /** |
||
27 | * @var Node\Stmt\Function_ |
||
28 | */ |
||
29 | protected $statement; |
||
30 | |||
31 | /** |
||
32 | * @var int |
||
33 | */ |
||
34 | protected $returnTypes = CompiledExpression::MIXED; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $possibleReturnTypes = array(); |
||
40 | |||
41 | /** |
||
42 | * @param string $name |
||
43 | * @param Node\Stmt\Function_ $statement |
||
44 | */ |
||
45 | 4 | public function __construct($name, Node\Stmt\Function_ $statement) |
|
50 | |||
51 | /** |
||
52 | * Compile function to check it |
||
53 | * |
||
54 | * @param Context $context |
||
55 | * @return bool |
||
56 | */ |
||
57 | 4 | public function compile(Context $context) |
|
58 | { |
||
59 | 4 | if ($this->compiled) { |
|
60 | return true; |
||
61 | } |
||
62 | |||
63 | 4 | $context->getEventManager()->fire( |
|
64 | 4 | Event\StatementBeforeCompile::EVENT_NAME, |
|
65 | 4 | new Event\StatementBeforeCompile( |
|
66 | 4 | $this->statement, |
|
67 | $context |
||
68 | 4 | ) |
|
69 | 4 | ); |
|
70 | |||
71 | 4 | $context->setFilepath($this->filepath); |
|
72 | 4 | $this->compiled = true; |
|
73 | |||
74 | 4 | $context->scopePointer = $this->getPointer(); |
|
75 | 4 | $context->setScope(null); |
|
76 | |||
77 | 4 | if (count($this->statement->stmts) == 0) { |
|
78 | 1 | return $context->notice( |
|
79 | 1 | 'not-implemented-function', |
|
80 | 1 | sprintf('Function %s() is not implemented', $this->name), |
|
81 | 1 | $this->statement |
|
82 | 1 | ); |
|
83 | } |
||
84 | |||
85 | 3 | if (count($this->statement->params) > 0) { |
|
86 | /** @var Node\Param $parameter */ |
||
87 | 2 | foreach ($this->statement->params as $parameter) { |
|
88 | 2 | $context->addSymbol($parameter->name); |
|
89 | 2 | } |
|
90 | 2 | } |
|
91 | |||
92 | 3 | foreach ($this->statement->stmts as $st) { |
|
93 | 3 | \PHPSA\nodeVisitorFactory($st, $context); |
|
94 | 3 | } |
|
95 | |||
96 | 3 | return true; |
|
97 | } |
||
98 | |||
99 | /** |
||
100 | * @return string |
||
101 | */ |
||
102 | 4 | public function getFilepath() |
|
106 | |||
107 | /** |
||
108 | * @param string $filepath |
||
109 | */ |
||
110 | 4 | public function setFilepath($filepath) |
|
114 | |||
115 | /** |
||
116 | * @return string |
||
117 | */ |
||
118 | public function getNamespace() |
||
122 | |||
123 | /** |
||
124 | * @return Node\Param[] |
||
125 | */ |
||
126 | 1 | public function getParams() |
|
130 | } |
||
131 |