Issues (19)

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.

LiteRecord.php (1 issue)

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
 * KumbiaPHP web & app Framework.
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://wiki.kumbiaphp.com/Licencia
11
 * If you did not receive a copy of the license and are unable to
12
 * obtain it through the world-wide-web, please send an email
13
 * to [email protected] so we can send you a copy immediately.
14
 *
15
 * @category   Kumbia
16
 *
17
 * @copyright  2005 - 2016 Kumbia Team (http://www.kumbiaphp.com)
18
 * @license    http://wiki.kumbiaphp.com/Licencia     New BSD License
19
 */
20
namespace Kumbia\ActiveRecord;
21
22
/**
23
 * Implementación de patrón ActiveRecord sin ayudantes de consultas SQL.
24
 */
25
class LiteRecord extends BaseRecord
26
{
27
    /**
28
     * Obtener objeto por clave primaria, $var = Modelo($id).
29
     *
30
     * @param  string $id valor para clave primaria
31
     * @return self
32
     */
33
    public function __invoke($id)
34
    {
35
        return self::get($id);
36
    }
37
38
    /**
39
     * Invoca el callback.
40
     *
41
     * @param  string  $callback
42
     * @return mixed
43
     */
44
    protected function callback($callback)
45
    {
46
        if (\method_exists($this, $callback)) {
47
            return $this->$callback();
48
        }
49
    }
50
51
    /**
52
     * Crear registro.
53
     *
54
     * @param  array           $data
55
     * @throws \PDOException
56
     * @return bool
57
     */
58
    public function create(array $data = [])
59
    {
60
        $this->dump($data);
61
62
        // Callback antes de crear
63
        if ($this->callback('_beforeCreate') === \false) {
64
            return \false;
65
        }
66
67
        $sql = QueryGenerator::insert($this, $data);
68
69
        if ( ! self::prepare($sql)->execute($data)) {
70
            return \false;
71
        }
72
73
        // Verifica si la PK es autogenerada
74
        $pk = static::getPK();
75
        if ( ! isset($this->$pk)) {
76
            $this->$pk = QueryGenerator::query(
77
                static::getDriver(),
78
                'last_insert_id',
79
                self::dbh(),
80
                $pk,
81
                static::getTable(),
82
                static::getSchema()
83
            );
84
        }
85
        // Callback despues de crear
86
        $this->callback('_afterCreate');
87
88
        return \true;
89
    }
90
91
    /**
92
     * Actualizar registro.
93
     *
94
     * @param  array              $data
95
     * @throws \KumbiaException
96
     * @return bool
97
     */
98
    public function update(array $data = [])
99
    {
100
        $this->dump($data);
101
        // Callback antes de actualizar
102
        if ($this->callback('_beforeUpdate') === \false) {
103
            return \false;
104
        }
105
        $this->hasPK();
106
        $values = [];
107
        $sql    = QueryGenerator::update($this, $values);
108
        //var_dump($values);var_dump($sql);die;
109
        if ( ! self::prepare($sql)->execute($values)) {
110
            return \false;
111
        }
112
        // Callback despues de actualizar
113
        $this->callback('_afterUpdate');
114
115
        return \true;
116
    }
117
118
    /**
119
     * Guardar registro.
120
     *
121
     * @param  array  $data
122
     * @return bool
123
     */
124
    public function save(array $data = [])
125
    {
126
        $this->dump($data);
127
128
        if ($this->callback('_beforeSave') === \false) {
129
            return \false;
130
        }
131
132
        $method = $this->saveMethod();
133
        $result = $this->$method();
134
135
        if ( ! $result) {
136
            return \false;
137
        }
138
139
        $this->callback('_afterSave');
140
141
        return \true;
142
    }
143
144
    /**
145
     * Retorna el nombre del metodo a llamar durante un save (create o update).
146
     *
147
     * @return string
148
     */
149
    protected function saveMethod()
150
    {
151
        $pk = static::getPK();
152
153
        return (empty($this->$pk) || ! static::exists($this->$pk)) ?
154
        'create' : 'update';
155
    }
156
157
    /**
158
     * Eliminar registro por pk.
159
     *
160
     * @param  int    $pk valor para clave primaria
161
     * @return bool
162
     */
163 View Code Duplication
    public static function delete($pk)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
164
    {
165
        $source  = static::getSource();
166
        $pkField = static::getPK();
167
168
        return static::query("DELETE FROM $source WHERE $pkField = ?", (int) $pk)->rowCount() > 0;
169
    }
170
171
    /**
172
     * Buscar por clave primaria.
173
     *
174
     * @param  string       $pk     valor para clave primaria
175
     * @param  string       $fields campos que se desean obtener separados por coma
176
     * @return LiteRecord
177
     */
178
    public static function get($pk, $fields = '*')
179
    {
180
        $source  = static::getSource();
181
        $pkField = static::getPK();
182
183
        $sql = "SELECT $fields FROM $source WHERE $pkField = ?";
184
185
        return static::query($sql, $pk)->fetch();
186
    }
187
188
    /**
189
     * Obtiene todos los registros de la consulta sql.
190
     *
191
     * @param  string  $sql
192
     * @param  string  |      array $values
193
     * @return array
194
     */
195
    public static function all($sql = '', $values = \null)
196
    {
197
        if ( ! $sql) {
198
            $source = static::getSource();
199
            $sql    = "SELECT * FROM $source";
200
        }
201
202
        return static::query($sql, $values)->fetchAll();
203
    }
204
205
    /**
206
     * Obtiene el primer registro de la consulta sql.
207
     *
208
     * @param  string  $sql
209
     * @param  string  |      array $values
210
     * @return array
211
     */
212
    public static function first($sql, $values = \null)
213
    {
214
        return static::query($sql, $values)->fetch();
215
    }
216
}
217