Issues (102)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Phiber/Util/FuncoesReflections.php (5 issues)

Upgrade to new PHP Analysis Engine

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
$iterator++; 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 return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

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.

Loading history...
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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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
The parameter $obj is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
207
    {
208
        throw new NotImplementedException();
0 ignored issues
show
The call to NotImplementedException::__construct() misses a required argument $message.

This check looks for function calls that miss required arguments.

Loading history...
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 return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

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.

Loading history...
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