1 | <?php |
||
15 | class ClassMethod extends AbstractDefinition |
||
16 | { |
||
17 | protected $type; |
||
18 | |||
19 | /** |
||
20 | * @var Node\Stmt\ClassMethod |
||
21 | */ |
||
22 | protected $statement; |
||
23 | |||
24 | /** |
||
25 | * Return type |
||
26 | * |
||
27 | * @var int |
||
28 | */ |
||
29 | protected $returnType = CompiledExpression::VOID; |
||
30 | |||
31 | /** |
||
32 | * Array of possible return values |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $possibleReturnValues = array(); |
||
37 | |||
38 | /** |
||
39 | * @param string $name |
||
40 | * @param Node\Stmt\ClassMethod $statement |
||
41 | * @param integer $type |
||
42 | */ |
||
43 | 17 | public function __construct($name, Node\Stmt\ClassMethod $statement, $type) |
|
49 | |||
50 | /** |
||
51 | * @param Context $context |
||
52 | * @return boolean|null |
||
53 | */ |
||
54 | 16 | public function compile(Context $context) |
|
55 | { |
||
56 | 16 | $context->getEventManager()->fire( |
|
57 | 16 | Event\StatementBeforeCompile::EVENT_NAME, |
|
58 | 16 | new Event\StatementBeforeCompile( |
|
59 | 16 | $this->statement, |
|
60 | $context |
||
61 | 16 | ) |
|
62 | 16 | ); |
|
63 | |||
64 | 16 | $this->compiled = true; |
|
65 | 16 | $context->scopePointer = $this->getPointer(); |
|
66 | |||
67 | 16 | if ($this->statement->getDocComment() === null) { |
|
68 | 4 | $context->notice( |
|
69 | 4 | 'missing-docblock', |
|
70 | 4 | sprintf('Missing docblock for %s() method', $this->name), |
|
71 | 4 | $this->statement |
|
72 | 4 | ); |
|
73 | 4 | } |
|
74 | |||
75 | /** |
||
76 | * It's not needed to compile empty method via it's abstract |
||
77 | */ |
||
78 | 16 | if ($this->isAbstract()) { |
|
79 | /** @var ClassDefinition $scope */ |
||
80 | $scope = $context->scope; |
||
81 | if (!$scope->isAbstract()) { |
||
82 | $context->notice( |
||
83 | 'not-abstract-class-with-abstract-method', |
||
84 | 'Class must be an abstract', |
||
85 | $this->statement |
||
86 | ); |
||
87 | } |
||
88 | |||
89 | return true; |
||
90 | } |
||
91 | |||
92 | 16 | if (count($this->statement->stmts) == 0) { |
|
93 | 1 | return $context->notice( |
|
94 | 1 | 'not-implemented-method', |
|
95 | 1 | sprintf('Method %s() is not implemented', $this->name), |
|
96 | 1 | $this->statement |
|
97 | 1 | ); |
|
98 | } |
||
99 | |||
100 | 16 | if ($this->statement->params) { |
|
|
|||
101 | 2 | foreach ($this->statement->params as $parameter) { |
|
102 | 2 | $type = CompiledExpression::UNKNOWN; |
|
103 | |||
104 | 2 | if ($parameter->type) { |
|
105 | if (is_string($parameter->type)) { |
||
106 | $type = Types::getType($parameter->type); |
||
107 | } elseif ($parameter->type instanceof Node\Name\FullyQualified) { |
||
108 | $type = CompiledExpression::OBJECT; |
||
109 | } |
||
110 | } |
||
111 | |||
112 | 2 | $context->addVariable( |
|
113 | 2 | new Parameter($parameter->name, null, $type, $parameter->byRef) |
|
114 | 2 | ); |
|
115 | 2 | } |
|
116 | 2 | } |
|
117 | |||
118 | 16 | foreach ($this->statement->stmts as $st) { |
|
119 | 16 | \PHPSA\nodeVisitorFactory($st, $context); |
|
120 | 16 | } |
|
121 | 16 | } |
|
122 | |||
123 | /** |
||
124 | * @param Context $context |
||
125 | * @param CompiledExpression[] $args |
||
126 | * @return CompiledExpression |
||
127 | * @throws \PHPSA\Exception\RuntimeException |
||
128 | */ |
||
129 | public function run(Context $context, array $args = null) |
||
130 | { |
||
131 | return new CompiledExpression(); |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * @return bool |
||
136 | */ |
||
137 | 16 | public function isAbstract() |
|
141 | |||
142 | /** |
||
143 | * @return bool |
||
144 | */ |
||
145 | 16 | public function isStatic() |
|
149 | |||
150 | /** |
||
151 | * @return bool |
||
152 | */ |
||
153 | public function isPublic() |
||
157 | |||
158 | /** |
||
159 | * @return bool |
||
160 | */ |
||
161 | public function isProtected() |
||
165 | |||
166 | /** |
||
167 | * @return bool |
||
168 | */ |
||
169 | public function isPrivate() |
||
173 | |||
174 | /** |
||
175 | * @param integer $newType |
||
176 | */ |
||
177 | 14 | public function addNewType($newType) |
|
185 | |||
186 | /** |
||
187 | * @return int |
||
188 | */ |
||
189 | public function getReturnType() |
||
193 | |||
194 | /** |
||
195 | * @param $value |
||
196 | */ |
||
197 | 14 | public function addReturnPossibleValue($value) |
|
201 | |||
202 | /** |
||
203 | * @return array |
||
204 | */ |
||
205 | public function getPossibleReturnValues() |
||
209 | |||
210 | /** |
||
211 | * @return array |
||
212 | */ |
||
213 | 1 | public function getParams() |
|
217 | } |
||
218 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.