Issues (58)

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/DriverAdapter.php (9 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
 * The MIT License
5
 *
6
 * Copyright 2014-2018 James Ekow Abaka Ainooson
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27
namespace ntentan\nibii;
28
29
/**
30
 * DriverAdapter provides a generic interface through which specific database operations can be performed.
31
 * It.
32
 */
33
abstract class DriverAdapter
34
{
35
    protected $data;
36
    private $insertQuery;
37
    private $updateQuery;
38
    private $modelInstance;
39
    protected $queryEngine;
40
    private $driver;
41
42 36
    public function setContext(ORMContext $context)
43
    {
44 36
        $this->driver = $context->getDbContext()->getDriver();
45 36
    }
46
47
    public function setData($data)
48
    {
49
        $this->data = $data;
50
    }
51
52
    /**
53
     * Convert datatypes from the database system's native type to a generic type
54
     * supported by nibii.
55
     *
56
     * @param string $nativeType The native datatype
57
     *
58
     * @return string The generic datatype for use in nibii.
59
     */
60
    abstract public function mapDataTypes($nativeType);
61
62
    /**
63
     * @param QueryParameters $parameters
64
     *
65
     * @return type
66
     */
67 24
    public function select($parameters)
68
    {
69 24
        $result = $this->driver->query(
70 24
            $this->getQueryEngine()->getSelectQuery($parameters),
71 24
            $parameters->getBoundData()
72
        );
73
74 24
        if ($parameters->getFirstOnly() && isset($result[0])) {
75 20
            $result = $result[0];
76
        }
77
78 24
        return $result;
79
    }
80
81
    /**
82
     * @param QueryParameters $parameters
83
     */
84
    public function count($parameters)
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
85
    {
86
        $result = $this->driver->query($this->getQueryEngine()->getCountQuery($parameters), $parameters->getBoundData());
87
88
        return $result[0]['count'];
89
    }
90
91 4
    private function initInsert()
92
    {
93 4
        $this->insertQuery = $this->getQueryEngine()->getInsertQuery($this->modelInstance);
94 4
    }
95
96 2
    private function initUpdate()
97
    {
98 2
        $this->updateQuery = $this->getQueryEngine()->getUpdateQuery($this->modelInstance);
99 2
    }
100
101 4
    public function insert($record)
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
102
    {
103 4
        if ($this->insertQuery === null) {
104 4
            $this->initInsert();
105
        }
106
107 4
        return $this->driver->query($this->insertQuery, $record);
108
    }
109
110 2
    public function update($record)
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
111
    {
112 2
        if ($this->updateQuery === null) {
113 2
            $this->initUpdate();
114
        }
115
116 2
        return $this->driver->query($this->updateQuery, $record);
117
    }
118
119
    /**
120
     * @param QueryParameters $parameters
121
     */
122 6
    public function bulkUpdate($data, $parameters)
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
123
    {
124 6
        return $this->driver->query(
125 6
            $this->getQueryEngine()->getBulkUpdateQuery($data, $parameters), array_merge($data, $parameters->getBoundData())
126
        );
127
    }
128
129
    /**
130
     * @param QueryParameters $parameters
131
     */
132 2
    public function delete($parameters)
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
133
    {
134 2
        return $this->driver->query(
135 2
            $this->getQueryEngine()->getDeleteQuery($parameters), $parameters->getBoundData()
136
        );
137
    }
138
139
    public function describe($model, $relationships)
0 ignored issues
show
The parameter $model 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...
140
    {
141
        return new ModelDescription(
142
            $this->driver->describeTable($table)[$table], $relationships, function ($type) {
0 ignored issues
show
The variable $table does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
The call to ModelDescription::__construct() has too many arguments starting with $relationships.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
143
                return $this->mapDataTypes($type);
144
            }
145
        );
146
    }
147
148
    /**
149
     * @return \ntentan\nibii\QueryEngine
150
     */
151 32
    private function getQueryEngine()
152
    {
153 32
        if ($this->queryEngine === null) {
154 32
            $this->queryEngine = new QueryEngine();
155 32
            $this->queryEngine->setDriver($this->driver);
156
        }
157
158 32
        return $this->queryEngine;
159
    }
160
161
    /**
162
     * @param RecordWrapper $model
163
     */
164 36
    public function setModel($model)
165
    {
166 36
        $this->modelInstance = $model;
167 36
    }
168
169
    public function getDriver()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
170
    {
171
        return $this->driver;
172
    }
173
}
174