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/Model.php (11 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
 * PotatoORM manages the persistence of database CRUD operations.
4
 *
5
 * @package Ibonly\PotatoORM\Model
6
 * @author  Ibraheem ADENIYI <[email protected]>
7
 * @license MIT <https://opensource.org/licenses/MIT>
8
 */
9
10
namespace Ibonly\PotatoORM;
11
12
use PDO;
13
use Exception;
14
use PDOException;
15
use Ibonly\PotatoORM\GetData;
16
use Ibonly\PotatoORM\DataNotFoundException;
17
use Ibonly\PotatoORM\EmptyDatabaseException;
18
use Ibonly\PotatoORM\ColumnNotExistExeption;
19
use Ibonly\PotatoORM\DataAlreadyExistException;
20
use Ibonly\PotatoORM\InvalidConnectionException;
21
22
class Model extends Relationships implements ModelInterface, RelationshipsInterface
23
{
24
    /**
25
     * getALL()
26
     * Get all record from the database
27
     *
28
     * @return object
29
     */
30 View Code Duplication
    public function getAll($dbConnection = NULL)
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...
31
    {
32
        $connection = DatabaseQuery::checkConnection($dbConnection);
33
34
        $sqlQuery = self::whereClause();
35
        $query = $connection->prepare($sqlQuery);
0 ignored issues
show
The method prepare cannot be called on $connection (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
36
        $query->execute();
37
        if ($query->rowCount()) {
38
            return new GetData($query->fetchAll($connection::FETCH_ASSOC));
39
        }
40
        throw new EmptyDatabaseException();
41
    }
42
43
    /**
44
     * where($data, $condition)
45
     * Get data from database where $data = $condition
46
     *
47
     * @return object
48
     */
49
    public function where($data, $condition = NULL, $dbConnection = NULL)
50
    {
51
        $databaseQuery = new DatabaseQuery();
52
        $connection = $databaseQuery->checkConnection($dbConnection);
53
54
        $sqlQuery = self::whereClause($data, $condition, $connection);
55
        $query = $connection->prepare($sqlQuery);
0 ignored issues
show
The method prepare cannot be called on $connection (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
56
        $query->execute();
57
        if ($query->rowCount()) {
58
            return new GetData($query->fetchAll($connection::FETCH_ASSOC));
59
        }
60
        throw new DataNotFoundException();
61
    }
62
63
    /**
64
     * find($value)
65
     * Find data from database where id = $value
66
     *
67
     * @return array
68
     */
69
    public static function find($value, $dbConnection = NULL)
70
    {
71
        $connection = DatabaseQuery::checkConnection($dbConnection);
72
73
        $sqlQuery = DatabaseQuery::selectQuery(self::getTableName($connection), self::fields(), ['id' => $value], NULL, $connection);
74
        $query = $connection->prepare($sqlQuery);
0 ignored issues
show
The method prepare cannot be called on $connection (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
75
        $query->execute();
76
        if ($query->rowCount()) {
77
            $found = new static;
78
            $found->id = $value;
0 ignored issues
show
The property id does not exist on object<Ibonly\PotatoORM\Model>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
79
            $found->data = $query->fetchAll($connection::FETCH_ASSOC);
0 ignored issues
show
The property data does not exist on object<Ibonly\PotatoORM\Model>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
80
            return $found;
81
        }
82
        throw new DataNotFoundException();
83
    }
84
85
    /**
86
     * save()
87
     * Insert data into database
88
     *
89
     * @return bool
90
     */
91 View Code Duplication
    public function save($dbConnection = NULL)
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...
92
    {
93
        $connection = DatabaseQuery::checkConnection($dbConnection);
94
95
        $query = $this->insertQuery(self::getTableName($connection));
96
        $statement = $connection->prepare($query);
0 ignored issues
show
The method prepare cannot be called on $connection (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
97
        if($statement->execute()) {
98
            return true;
99
        }
100
        throw new  DataAlreadyExistException();
101
102
    }
103
104
    /**
105
     * update()
106
     * Update details in database after ::find(2)
107
     *
108
     * @return bool
109
     */
110 View Code Duplication
    public function update($id, $dbConnection = NULL)
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...
111
    {
112
        $connection = DatabaseQuery::checkConnection($dbConnection);
113
114
        $updateQuery = $this->updateQuery(self::getTableName($connection), $id);
115
        $statement = $connection->prepare($updateQuery);
0 ignored issues
show
The method prepare cannot be called on $connection (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
116
        if ($statement->execute()) {
117
            return true;
118
        }
119
        throw new  DataAlreadyExistException();
120
    }
121
122
    /**
123
     * destroy($value)
124
     * Delete data from database
125
     *
126
     * @return bool
127
     */
128
    public function destroy($value, $dbConnection = NULL)
129
    {
130
        $connection = DatabaseQuery::checkConnection($dbConnection);
131
132
        $query = $connection->prepare('DELETE FROM ' . self::getTableName($connection) . ' WHERE id = '.$value);
0 ignored issues
show
The method prepare cannot be called on $connection (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
133
        $query->execute();
134
        $check = $query->rowCount();
135
        if ($check) {
136
            return true;
137
        }
138
        throw new DataNotFoundException;
139
    }
140
}