Issues (29)

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/Manager.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
namespace AsyncPHP\Icicle\Database;
4
5
use Icicle\Coroutine;
6
use Icicle\Promise\PromiseInterface;
7
8
final class Manager
9
{
10
    /**
11
     * @var Connector
12
     */
13
    private $connector;
14
15
    /**
16
     * @var Builder
17
     */
18
    private $builder;
19
20
    /**
21
     * @var array
22
     */
23
    private $operations = [];
24
25
    /**
26
     * @param Connector $connector
27
     * @param Builder $builder
28
     */
29 2
    public function __construct(Connector $connector, Builder $builder)
30
    {
31 2
        $this->connector = $connector;
32 2
        $this->builder = $builder;
33 2
    }
34
35
    /**
36
     * @param string $method
37
     * @param array $parameters
38
     *
39
     * @return mixed
40
     */
41 2
    public function __call($method, array $parameters = [])
42
    {
43 2
        $operations = $this->operations;
44 2
        $operations[] = [$method, $parameters];
45
46 2
        return $this->cloneWith("operations", $operations);
47
    }
48
49
    /**
50
     * @param string $key
51
     * @param mixed $value
52
     *
53
     * @return static
54
     */
55 2
    public function cloneWith($key, $value)
56
    {
57 2
        $clone = clone $this;
58 2
        $clone->$key = $value;
59
60 2
        return $clone;
61
    }
62
63
    /**
64
     * @param string $table
65
     *
66
     * @return static
67
     */
68 2
    public function table($table)
69
    {
70 2
        return $this->cloneWith("builder", $this->builder->table($table));
71
    }
72
73
    /**
74
     * @param string $columns
75
     *
76
     * @return static
77
     */
78 2
    public function select($columns = "*")
79
    {
80 2
        return $this->cloneWith("builder", $this->builder->select($columns));
81
    }
82
83
    /**
84
     * @return PromiseInterface
85
     */
86 2
    public function first()
87
    {
88
        return Coroutine\create(function () {
89 2
            $rows = (yield $this->limit(1)->get());
0 ignored issues
show
Documentation Bug introduced by
The method limit does not exist on object<AsyncPHP\Icicle\Database\Manager>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
90 2
            yield reset($rows);
91 2
        });
92
    }
93
94
    /**
95
     * @return PromiseInterface
96
     */
97 2
    public function get()
98
    {
99
        return Coroutine\create(function () {
100 2
            $builder = $this->applyOperationsTo($this->builder);
101
102 2
            list($statement, $values) = $builder->build();
103 2
            yield $this->connector->query($statement, $values);
104 2
        });
105
    }
106
107
    /**
108
     * @param Builder $builder
109
     *
110
     * @return Builder
111
     */
112 2
    private function applyOperationsTo($builder)
113
    {
114 2
        foreach ($this->operations as $operation) {
115 2
            list($method, $parameters) = $operation;
116 2
            $builder = call_user_func_array([$builder, $method], $parameters);
117 2
        }
118
119 2
        return $builder;
120
    }
121
122
    /**
123
     * @param array $data
124
     *
125
     * @return PromiseInterface
126
     */
127 2 View Code Duplication
    public function insert(array $data)
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...
128
    {
129
        return Coroutine\create(function () use ($data) {
130 2
            $builder = $this->builder->insert($data);
131 2
            $builder = $this->applyOperationsTo($builder);
132
133 2
            list($statement, $values) = $builder->build();
134 2
            yield $this->connector->query($statement, $values);
135 2
        });
136
    }
137
138
    /**
139
     * @param array $data
140
     *
141
     * @return PromiseInterface
142
     */
143 View Code Duplication
    public function update(array $data)
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...
144
    {
145
        return Coroutine\create(function () use ($data) {
146
            $builder = $this->builder->update($data);
147
            $builder = $this->applyOperationsTo($builder);
148
149
            list($statement, $values) = $builder->build();
150
            yield $this->connector->query($statement, $values);
151
        });
152
    }
153
154
    /**
155
     * @return PromiseInterface
156
     */
157 View Code Duplication
    public function delete()
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...
158
    {
159
        return Coroutine\create(function () {
160
            $builder = $this->builder->delete();
161
            $builder = $this->applyOperationsTo($builder);
162
163
            list($statement, $values) = $builder->build();
164
            yield $this->connector->query($statement, $values);
165
        });
166
    }
167
}
168