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 | /** |
||
4 | * Copyright (c) 2017. Este código foi feito por @marciioluucas, sob licença MIT |
||
5 | */ |
||
6 | namespace Phiber\Util; |
||
7 | |||
8 | use Exception; |
||
9 | use Phiber\ORM\Exceptions\NotImplementedException; |
||
10 | use ReflectionClass; |
||
11 | use ReflectionProperty; |
||
12 | |||
13 | /** |
||
14 | * |
||
15 | * Classe responsável por Fazer a reflexao das classes dos objetos. |
||
16 | * @package util |
||
17 | */ |
||
18 | class FuncoesReflections |
||
19 | { |
||
20 | /** |
||
21 | * Função responsável por pegar o nome dos métodos do objeto retornando um array dos mesmos |
||
22 | * |
||
23 | * @param $object |
||
24 | * @return array |
||
25 | */ |
||
26 | public function pegaNomesMetodosClasse($object) |
||
27 | { |
||
28 | return get_class_methods($object); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Função responsável por pegar o nome de um atributo espefífico. |
||
33 | * Caso o atributo pesquisado não exista, a função retornará falso. |
||
34 | * |
||
35 | * @param $object |
||
36 | * @param $nomeAtributo |
||
37 | * @return bool|string |
||
38 | * @throws Exception |
||
39 | */ |
||
40 | public function pegaNomeAtributoEspecifico($object, $nomeAtributo) |
||
41 | { |
||
42 | try { |
||
43 | $arrayAtributosObjeto = self::pegaAtributosDoObjeto($object); |
||
44 | |||
45 | $iterator = 0; |
||
46 | $limit = count($arrayAtributosObjeto); |
||
47 | for ($iterator; $iterator < $limit; $iterator++) { |
||
0 ignored issues
–
show
|
|||
48 | |||
49 | $atributoEspecifico = strstr( |
||
50 | $arrayAtributosObjeto[$iterator], |
||
51 | $nomeAtributo |
||
52 | ); |
||
53 | |||
54 | return $atributoEspecifico; |
||
55 | } |
||
56 | |||
57 | } catch (Exception $e) { |
||
58 | throw new Exception("Falha ao pegar nome do atributo específico", 3, $e); |
||
59 | } |
||
60 | |||
61 | return false; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Função responsável por pegar os nomes dos atributos do objeto, retornando um array dos mesmos. |
||
66 | * |
||
67 | * @param $obj |
||
68 | * @return array |
||
69 | */ |
||
70 | public function pegaAtributosDoObjeto($obj) |
||
71 | { |
||
72 | $properties = []; |
||
73 | $reflectionClass = new ReflectionClass($obj); |
||
74 | $propriedades = $reflectionClass->getProperties( |
||
75 | ReflectionProperty::IS_PUBLIC | |
||
76 | ReflectionProperty::IS_PROTECTED | |
||
77 | ReflectionProperty::IS_PRIVATE |
||
78 | ); |
||
79 | |||
80 | $iterator = 0; |
||
0 ignored issues
–
show
$iterator is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
81 | $limit = count($propriedades); |
||
82 | for ($iterator = 0; $iterator < $limit; $iterator++) { |
||
83 | $properties[$iterator] = $propriedades[$iterator]->name; |
||
84 | } |
||
85 | |||
86 | return $properties; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Função responsável por pegar o nome da classe do objeto em questão. |
||
91 | * |
||
92 | * @param $object |
||
93 | * @return string |
||
94 | */ |
||
95 | public function pegaNomeClasseObjeto($object) |
||
96 | { |
||
97 | $reflectionClass = new ReflectionClass($object); |
||
98 | |||
99 | return $reflectionClass->getShortName(); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Função responsável por retornar os valores dos atributos das classes mães, |
||
104 | * se as mesmas existirem, se caso a classe em questão não for uma classe filha, |
||
105 | * a função retornará false. |
||
106 | * |
||
107 | * @param $object |
||
108 | * @return bool|array |
||
109 | */ |
||
110 | public function retornaValoresAtributosClassesMaes($object) |
||
111 | { |
||
112 | if (self::verificaSeEClasseFilha($object)) { |
||
113 | |||
114 | $nomeClassesMae = self::retornaClassesMaes($object); |
||
115 | |||
116 | $valores = []; |
||
117 | $iterator = 0; |
||
118 | $limit = count($nomeClassesMae); |
||
119 | for ($iterator; $iterator < $limit; $iterator++) { |
||
120 | $valores[$iterator] = self::pegaValoresAtributoDoObjeto( |
||
121 | $nomeClassesMae[$iterator] |
||
122 | ); |
||
123 | } |
||
124 | |||
125 | return $valores; |
||
126 | } |
||
127 | |||
128 | return false; |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Função responsável por verifidar se a classe é filha de alguma outra classe, |
||
133 | * se caso não for. A função retornará falso. |
||
134 | * |
||
135 | * @param Object $object |
||
136 | * @return bool |
||
137 | */ |
||
138 | public function verificaSeEClasseFilha($object) |
||
139 | { |
||
140 | $class = new ReflectionClass($object); |
||
141 | |||
142 | if ($class->getParentClass()) { |
||
143 | return true; |
||
144 | } |
||
145 | |||
146 | return false; |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * Retorna o nome das classes mães, se caso o objeto em questão não ter uma classe mãe, |
||
151 | * a função retornará false. |
||
152 | * |
||
153 | * @param $object |
||
154 | * @return array|bool |
||
155 | */ |
||
156 | public function retornaClassesMaes($object) |
||
157 | { |
||
158 | $class = new ReflectionClass($object); |
||
159 | |||
160 | $parents = []; |
||
161 | $parent = ""; |
||
162 | if ( self::verificaSeEClasseFilha($object) ) { |
||
163 | while ($class->getParentClass()) { |
||
164 | $parents[] = $class->getParentClass()->getName(); |
||
165 | $class = $parent; |
||
166 | } |
||
167 | |||
168 | return $parents; |
||
169 | } |
||
170 | |||
171 | return false; |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * Função responsável por retornar um array de todos os valores dos atributos de um objeto |
||
176 | * |
||
177 | * @param $object |
||
178 | * @return array |
||
179 | */ |
||
180 | public function pegaValoresAtributoDoObjeto($object) |
||
181 | { |
||
182 | $nomeAtributos = self::pegaAtributosDoObjeto($object); |
||
183 | $valAtrFinal = []; |
||
184 | $reflectionClass = new ReflectionClass($object); |
||
185 | |||
186 | $iterator = 0; |
||
187 | $limit = count($nomeAtributos); |
||
188 | for ($iterator; $iterator < $limit; $iterator++) { |
||
189 | $reflectionProperty = $reflectionClass->getProperty($nomeAtributos[$iterator]); |
||
190 | $reflectionProperty->setAccessible(true); |
||
191 | $valAtrFinal[$iterator] = $reflectionProperty->getValue($object); |
||
192 | } |
||
193 | |||
194 | return $valAtrFinal; |
||
195 | } |
||
196 | |||
197 | |||
198 | /** |
||
199 | * Função responsável por retornar um array com todos os atributos das classes da hierarquia |
||
200 | * |
||
201 | * @todos Pendente de implementação |
||
202 | * |
||
203 | * @param $obj |
||
204 | * @return array |
||
205 | */ |
||
206 | public function retornaNomeAtributosClassesMaes($obj) |
||
0 ignored issues
–
show
|
|||
207 | { |
||
208 | throw new NotImplementedException(); |
||
0 ignored issues
–
show
|
|||
209 | |||
210 | $atributos = []; |
||
0 ignored issues
–
show
$atributos = array(); does not seem to be reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last ![]() |
|||
211 | $iterator = 0; |
||
212 | $limit = count(self::retornaClassesMaes($obj)); |
||
213 | for ($iterator; $iterator < $limit; $iterator++) { |
||
214 | $atributos[$iterator] = array(self::retornaClassesMaes($obj)[$iterator] => |
||
215 | self::pegaAtributosDoObjeto(self::retornaClassesMaes($obj)[$iterator])); |
||
216 | } |
||
217 | |||
218 | return $atributos; |
||
219 | } |
||
220 | |||
221 | /** |
||
222 | * Função responsável por retornar os comentários dos atributos do objeto em questão. |
||
223 | * |
||
224 | * @param $object |
||
225 | * @return array |
||
226 | */ |
||
227 | public function retornaComentariosAtributos($object) |
||
228 | { |
||
229 | $arrAttrNames = self::pegaAtributosDoObjeto($object); |
||
230 | $arrAttrComm = array(); |
||
231 | |||
232 | $iterator = 0; |
||
233 | $limit = count($arrAttrNames); |
||
234 | for ($iterator; $iterator < $limit; $iterator++) { |
||
235 | |||
236 | $reflectionAttr = new ReflectionProperty($object, $arrAttrNames[$iterator]); |
||
237 | |||
238 | $arrAttrComm[$arrAttrNames[$iterator]] = $reflectionAttr->getDocComment(); |
||
239 | } |
||
240 | |||
241 | /** |
||
242 | * @todo FAZER O FOR PARA PEGAR TODOS ATRIBUTOS, PASSAR NO SEGUNDO PARAMETRO; |
||
243 | */ |
||
244 | return $arrAttrComm; |
||
245 | } |
||
246 | } |
||
247 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.