This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @author Patsura Dmitry https://github.com/ovr <[email protected]> |
||
4 | */ |
||
5 | |||
6 | namespace PHPSA\Definition; |
||
7 | |||
8 | use PhpParser\Node; |
||
9 | use PHPSA\CompiledExpression; |
||
10 | use PHPSA\Compiler\Parameter; |
||
11 | use PHPSA\Compiler\Types; |
||
12 | use PHPSA\Compiler\Event; |
||
13 | use PHPSA\Context; |
||
14 | use PHPSA\ControlFlow\ControlFlowGraph; |
||
15 | |||
16 | /** |
||
17 | * Class Method Definition |
||
18 | */ |
||
19 | class ClassMethod extends AbstractDefinition |
||
20 | { |
||
21 | /** |
||
22 | * Contains a number representing all modifiers (public, static, ...) |
||
23 | * |
||
24 | * @var int |
||
25 | */ |
||
26 | protected $type; |
||
27 | |||
28 | /** |
||
29 | * @var Node\Stmt\ClassMethod |
||
30 | */ |
||
31 | protected $statement; |
||
32 | |||
33 | /** |
||
34 | * @var \PHPSA\ControlFlow\ControlFlowGraph |
||
35 | */ |
||
36 | protected $cfg; |
||
37 | |||
38 | /** |
||
39 | * Return type |
||
40 | * |
||
41 | * @var int |
||
42 | */ |
||
43 | protected $returnType = CompiledExpression::UNKNOWN; |
||
44 | |||
45 | /** |
||
46 | * Array of possible return values |
||
47 | * |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $possibleReturnValues = []; |
||
51 | |||
52 | /** |
||
53 | * @param string $name |
||
54 | * @param Node\Stmt\ClassMethod $statement |
||
55 | * @param integer $type |
||
56 | */ |
||
57 | public function __construct($name, Node\Stmt\ClassMethod $statement, $type) |
||
58 | { |
||
59 | $this->name = $name; |
||
60 | $this->statement = $statement; |
||
61 | $this->type = $type; |
||
62 | |||
63 | // @todo Better support... |
||
64 | $returnType = $statement->getReturnType(); |
||
65 | if ($returnType == 'void') { |
||
66 | $this->returnType = CompiledExpression::VOID; |
||
67 | } |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @param Context $context |
||
72 | * @return boolean|null |
||
73 | */ |
||
74 | public function compile(Context $context) |
||
75 | { |
||
76 | $context->getEventManager()->fire( |
||
77 | Event\StatementBeforeCompile::EVENT_NAME, |
||
78 | new Event\StatementBeforeCompile( |
||
79 | $this->statement, |
||
80 | $context |
||
81 | ) |
||
82 | ); |
||
83 | |||
84 | $this->compiled = true; |
||
85 | $context->scopePointer = $this->getPointer(); |
||
86 | |||
87 | /** |
||
88 | * It's not needed to compile empty method via it's abstract |
||
89 | */ |
||
90 | if ($this->isAbstract()) { |
||
91 | /** @var ClassDefinition $scope */ |
||
92 | $scope = $context->scope; |
||
93 | if (!$scope->isAbstract()) { |
||
94 | $context->notice( |
||
95 | 'not-abstract-class-with-abstract-method', |
||
96 | 'Class must be abstract', |
||
97 | $this->statement |
||
98 | ); |
||
99 | } |
||
100 | |||
101 | return true; |
||
102 | } |
||
103 | |||
104 | if ($this->statement->params) { |
||
0 ignored issues
–
show
|
|||
105 | foreach ($this->statement->params as $parameter) { |
||
106 | $type = CompiledExpression::UNKNOWN; |
||
107 | |||
108 | if ($parameter->type) { |
||
109 | if (is_string($parameter->type)) { |
||
110 | $type = Types::getType($parameter->type); |
||
111 | } elseif ($parameter->type instanceof Node\Name) { |
||
112 | $type = CompiledExpression::OBJECT; |
||
113 | } |
||
114 | } |
||
115 | |||
116 | $context->addVariable( |
||
117 | new Parameter($parameter->name, null, $type, $parameter->byRef) |
||
118 | ); |
||
119 | } |
||
120 | } |
||
121 | |||
122 | foreach ($this->statement->stmts as $st) { |
||
0 ignored issues
–
show
The expression
$this->statement->stmts of type array<integer,object<PhpParser\Node\Stmt>>|null is not guaranteed to be traversable. How about adding an additional type check?
There are different options of fixing this problem.
![]() |
|||
123 | \PHPSA\nodeVisitorFactory($st, $context); |
||
124 | } |
||
125 | |||
126 | $this->cfg = new ControlFlowGraph( |
||
127 | $this->statement, |
||
128 | $context |
||
129 | ); |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * @param Context $context |
||
134 | * @param CompiledExpression[] $args |
||
135 | * @return CompiledExpression |
||
136 | * @throws \PHPSA\Exception\RuntimeException |
||
137 | */ |
||
138 | public function run(Context $context, array $args = null) |
||
0 ignored issues
–
show
|
|||
139 | { |
||
140 | return new CompiledExpression(); |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * @return bool |
||
145 | */ |
||
146 | public function isAbstract() |
||
147 | { |
||
148 | return (bool) ($this->type & Node\Stmt\Class_::MODIFIER_ABSTRACT); |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * @return bool |
||
153 | */ |
||
154 | public function isStatic() |
||
155 | { |
||
156 | return (bool) ($this->type & Node\Stmt\Class_::MODIFIER_STATIC); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * @return bool |
||
161 | */ |
||
162 | public function isPublic() |
||
163 | { |
||
164 | return ($this->type & Node\Stmt\Class_::MODIFIER_PUBLIC) !== 0 || $this->type === 0; |
||
165 | } |
||
166 | |||
167 | /** |
||
168 | * @return bool |
||
169 | */ |
||
170 | public function isProtected() |
||
171 | { |
||
172 | return (bool) ($this->type & Node\Stmt\Class_::MODIFIER_PROTECTED); |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * @return bool |
||
177 | */ |
||
178 | public function isPrivate() |
||
179 | { |
||
180 | return (bool) ($this->type & Node\Stmt\Class_::MODIFIER_PRIVATE); |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * @param integer $newType |
||
185 | */ |
||
186 | public function addNewType($newType) |
||
187 | { |
||
188 | if ($this->returnType != CompiledExpression::VOID) { |
||
189 | $this->returnType = $this->returnType | $newType; |
||
190 | } else { |
||
191 | $this->returnType = $newType; |
||
192 | } |
||
193 | } |
||
194 | |||
195 | /** |
||
196 | * @return int |
||
197 | */ |
||
198 | public function getReturnType() |
||
199 | { |
||
200 | return $this->returnType; |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * @param $value |
||
205 | */ |
||
206 | public function addReturnPossibleValue($value) |
||
207 | { |
||
208 | $this->possibleReturnValues[] = $value; |
||
209 | } |
||
210 | |||
211 | /** |
||
212 | * @return array |
||
213 | */ |
||
214 | public function getPossibleReturnValues() |
||
215 | { |
||
216 | return $this->possibleReturnValues; |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * @return Node\Param[] |
||
221 | */ |
||
222 | public function getParams() |
||
223 | { |
||
224 | return $this->statement->params; |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * @return int |
||
229 | */ |
||
230 | public function getModifier() |
||
231 | { |
||
232 | return $this->type; |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * @param int $type |
||
237 | */ |
||
238 | public function setModifier($type) |
||
239 | { |
||
240 | $this->type = $type; |
||
241 | } |
||
242 | |||
243 | /** |
||
244 | * @return \PHPSA\ControlFlow\ControlFlowGraph |
||
245 | */ |
||
246 | public function getCFG() |
||
247 | { |
||
248 | return $this->cfg; |
||
249 | } |
||
250 | } |
||
251 |
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.