Issues (66)

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/Helper/Schema.php (4 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
 * SugarORM\Schema manages the creation of database table.
4
 *
5
 * @package Ibonly\SugarORM\Schema
6
 * @author  Ibraheem ADENIYI <[email protected]>
7
 * @license MIT <https://opensource.org/licenses/MIT>
8
 */
9
10
namespace Ibonly\PotatoORM;
11
12
use PDOException;
13
use Ibonly\PotatoORM\DatabaseQuery;
14
use Ibonly\PotatoORM\SchemaInterface;
15
16
class Schema extends DatabaseQuery implements SchemaInterface
17
{
18
    //Inject the inflector trait
19
    use Inflector;
20
21
    protected $fieldDescription = [];
22
23
    /**
24
     * field(arguments) contains the sql field statement
25
     *
26
     * @return array
27
     */
28
    public function field($type, $fieldName, $length=NULL)
29
    {
30
        if($length === null){
31
             $this->fieldDescription[] = $type ." ".$fieldName;
32
        }else
33
        {
34
         $this->fieldDescription[] = $type ." ".$fieldName." ".$length;
35
        }
36
37
    }
38
39
    /**
40
     * buildQuery(argument): Builds the CREATE query
41
     *
42
     * @return string
43
     */
44
    public function buildQuery($tablename)
45
    {
46
        $pluralTableName = self::pluralize($tablename);
47
        $query = "CREATE TABLE IF NOT EXISTS {$pluralTableName} (".PHP_EOL;
48
49
        $callback = function($fieldName) use (&$query)
50
        {
51
            $fields = explode(" ", $fieldName);
52
         
53
            $constrain = $fields[0];
54
            if(count($fields) == 2)
55
            {
56
                $query .= $this->$constrain($fields[1], 20) .", ".PHP_EOL;
57
            }else
58
            {
59
                    $query .= $this->$constrain($fields[1], $fields[2]) .", ".PHP_EOL;
60
            }
61
        };
62
        array_walk($this->fieldDescription, $callback);
63
        $query .= ');)';
64
65
        return $query;
66
    }
67
68
    /**
69
     * SanitizeQuery(argument) Removes the unwanted character in the build
70
     * and completes the statement
71
     *
72
     * @return string
73
     */
74
    public function sanitizeQuery($query)
75
    {
76
        $q = substr_replace($this->buildQuery($query), "", -6);
77
        $q .= ");";
78
        return $q;
79
    }
80
81
    /**
82
     * createTable(argument) Execute the CREATE query
83
     *
84
     * @return bool
85
     */
86
    public function createTable($tablename, $connection = NULL)
87
    {
88
        $connection = DatabaseQuery::connect();
89
        try
90
        {
91
            $sqlQuery = self::sanitizeQuery($tablename);
92
            $query = $connection->prepare($sqlQuery);
93
            if($query->execute())
94
            {
95
                return true;
96
            }
97
        }catch(PDOException $e){
98
            return $e->getMessage();
99
        }
100
    }
101
102
    /**
103
     * increments(argument)
104
     *
105
     * @return string
106
     */
107
    public function increments($value)
108
    {
109
        return $value." int(11) NOT NULL AUTO_INCREMENT";
110
    }
111
112
    /**
113
     * strings(arguments)
114
     *
115
     * @return string
116
     */
117
    public function strings($value, $length)
118
    {
119
        return $value ." varchar (".$length.") NOT NULL";
120
    }
121
122
    /**
123
     * text(argument)
124
     *
125
     * @return string
126
     */
127
    public function text($value)
128
    {
129
        return $value." text NOT NULL";
130
    }
131
132
    /**
133
     * increments(argument)
134
     *
135
     *
136
     * @return string
137
     */
138
    public function integer($value, $length)
139
    {
140
        return $value." int(".$length.") NOT NULL";
141
    }
142
143
    /**
144
     * increments(argument)
145
     *
146
     * @return string
147
     */
148
    public function primaryKey($value)
149
    {
150
        return "PRIMARY KEY ({$value})";
151
    }
152
153
    /**
154
     * unique(argument)
155
     *
156
     * @return string
157
     */
158
    public function unique($value)
159
    {
160
        return "UNIQUE KEY {$value} ({$value})";
161
    }
162
163
    /**
164
     * foreignKey(argument)
165
     *
166
     * @return string
167
     */
168
    public function foreignKey($value, $length)
169
    {
170
        $r = explode("-", $length);
171
        
172
        return "FOREIGN KEY ({$value}) REFERENCES ".$r[0]."(".$r[1].")";
173
    }
174
175
    /**
176
     * dateTime description]
177
     *
178
     * @param  [type] $value [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
179
     * @param  [type] $type  [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
180
     * @return [type]        [description]
0 ignored issues
show
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
181
     */
182
    public function dateTime($value, $type = NULL)
183
    {
184
        $apend = "";
0 ignored issues
show
$apend 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...
185
        switch ($type) {
186
            case 'time':
187
                    $apend = 'time';
188
                break;
189
            case 'timestamp':
190
                    $apend = 'timestamp';
191
                break;
192
            case 'date':
193
                    $apend = 'date';
194
                break;
195
            case 'datetime':
196
                    $apend = 'datetime';
197
                break;
198
            case 'year':
199
                    $apend = 'year(4)';
200
                break;
201
            default:
202
                    $apend = 'timestamp';
203
                break;
204
        }
205
        return $value . " " . $apend . " NOT NULL";
206
    }
207
}