Issues (26)

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/Connections/DatabaseTransactionsTrait.php (15 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
namespace Opeyemiabiodun\PotatoORM\Connections;
4
5
use InvalidArgumentException;
6
7
trait DatabaseTransactionsTrait
8
{
9
    /**
10
     * Creates a record in the database.
11
     *
12
     * @param string $table  The table where the a new record is made.
13
     * @param array  $record The record to be made in the database.
14
     *
15
     * @return bool
16
     */
17 1
    public function createRecord($table, $record)
18
    {
19 1
        if (gettype($table) !== 'string') {
20
            throw new InvalidArgumentException("The parameter {$table} is not a string. A string is required instead.");
21
        }
22
23 1
        if (gettype($record) !== 'array') {
24
            throw new InvalidArgumentException("The parameter {$record} is not an array. An array is required instead.");
25
        }
26
27 1
        $count = count($record);
28
29 1
        $sql = "INSERT INTO {$table} (";
30 1 View Code Duplication
        foreach ($record as $key => $value) {
0 ignored issues
show
This code seems to be duplicated across 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...
31 1
            $count--;
32
33 1
            if ($key === $this->getPrimaryKey($table)) {
0 ignored issues
show
It seems like getPrimaryKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
34 1
                continue;
35
            }
36
37 1
            if ($count > 0) {
38 1
                $sql = $sql."{$key}, ";
39 1
            } else {
40 1
                $sql = $sql."{$key}) ";
41
            }
42 1
        }
43
44 1
        $count = count($record);
45
46 1
        $sql .= 'VALUES (';
47 1
        foreach ($record as $key => $value) {
48 1
            $count--;
49
50 1
            if ($key === $this->getPrimaryKey($table)) {
0 ignored issues
show
It seems like getPrimaryKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
51 1
                continue;
52
            }
53
54 1
            if ($count > 0) {
55 1
                $sql = (empty($value)) ? $sql.'NULL, ' : $sql."'{$value}', ";
56 1
            } else {
57 1
                $sql = (empty($value)) ? $sql.'NULL ' : $sql."'{$value}') ";
58
            }
59 1
        }
60
61 1
        return $this->getPdo()->prepare($sql)->execute();
0 ignored issues
show
It seems like getPdo() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
62
    }
63
64
    /**
65
     * Remove a record in the database.
66
     *
67
     * @param string $table The table where the record is removed in the database.
68
     * @param string $pk    The primary key value of the record.
69
     *
70
     * @return bool Returns boolean true if the record was successfully deleted or else it returns false.
71
     */
72 1 View Code Duplication
    public function deleteRecord($table, $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...
73
    {
74 1
        if (gettype($table) !== 'string') {
75
            throw new InvalidArgumentException("The parameter {$table} is not a string. A string is required instead.");
76
        }
77
78 1
        return $this->getPdo()->prepare("DELETE FROM {$table}
0 ignored issues
show
It seems like getPdo() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
79 1
                                            WHERE {$this->getPrimaryKey($table)}={$pk}")->execute();
0 ignored issues
show
It seems like getPrimaryKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
80
    }
81
82
    /**
83
     * Returns a particular record in a table.
84
     *
85
     * @param string $table The table of the record. 
86
     * @param string $pk    The primary key value of the record.
87
     *
88
     * @return array An array containing the particular record.
89
     */
90 1 View Code Duplication
    public function findRecord($table, $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...
91
    {
92 1
        if (gettype($table) !== 'string') {
93
            throw new InvalidArgumentException("The parameter {$table} is not a string. A string is required instead.");
94
        }
95
96 1
        return $this->getPdo()->query("SELECT * FROM {$table}
0 ignored issues
show
It seems like getPdo() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
97 1
                                        WHERE {$this->getPrimaryKey($table)}={$pk}")->fetchAll();
0 ignored issues
show
It seems like getPrimaryKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
98
    }
99
100
    /**
101
     * Returns all the records in a table.
102
     *
103
     * @param string $table The table inspected for all its records.
104
     *
105
     * @return array All the records in the table.        
106
     */
107 1
    public function getAllRecords($table)
108
    {
109 1
        if (gettype($table) !== 'string') {
110
            throw new InvalidArgumentException("The parameter {$table} is not a string. A string is required instead.");
111
        }
112
113 1
        return $this->getPdo()->query("SELECT * FROM {$table}")->fetchAll();
0 ignored issues
show
It seems like getPdo() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
114
    }
115
116
    /**
117
     * Update a record in the database.
118
     *
119
     * @param string $table  The table where the record update is being made.
120
     * @param string $pk     The primary key value of the record to be updated.
121
     * @param array  $record The updates to be made to the record in the database.
122
     *
123
     * @return bool Returns boolean true if the record was successfully updated or else it returns false.
124
     */
125 1
    public function updateRecord($table, $pk, $record)
126
    {
127 1
        if (gettype($table) !== 'string') {
128
            throw new InvalidArgumentException("The parameter {$table} is not a string. A string is required instead.");
129
        }
130
131 1
        if (gettype($pk) !== 'string') {
132
            throw new InvalidArgumentException("The parameter {$pk} is not a string. A string is required instead.");
133
        }
134
135 1
        if (gettype($record) !== 'array') {
136
            throw new InvalidArgumentException("The parameter {$record} is not an array. An array is required instead.");
137
        }
138
139 1
        $count = count($record);
140
141 1
        $sql = "UPDATE {$table} SET ";
142 1 View Code Duplication
        foreach ($record as $key => $value) {
0 ignored issues
show
This code seems to be duplicated across 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...
143 1
            $count--;
144
145 1
            if ($key === $this->getPrimaryKey($table)) {
0 ignored issues
show
It seems like getPrimaryKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
146 1
                continue;
147
            }
148
149 1
            if ($count > 0) {
150 1
                $sql = $sql."{$key}='{$value}', ";
151 1
            } else {
152 1
                $sql = $sql."{$key}='{$value}' ";
153
            }
154 1
        }
155 1
        $sql .= "WHERE {$this->getPrimaryKey($table)}='{$pk}'";
0 ignored issues
show
It seems like getPrimaryKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
156
157 1
        return $this->getPdo()->prepare($sql)->execute();
0 ignored issues
show
It seems like getPdo() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
158
    }
159
}
160