Issues (17)

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/Stream/Pool.php (2 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 Phloppy\Stream;
4
5
use Phloppy\Exception\ConnectException;
6
use Psr\Log\LoggerInterface;
7
use Psr\Log\NullLogger;
8
9
/**
10
 * Phloppy Node Pool.
11
 */
12
class Pool implements StreamInterface
13
{
14
15
    /**
16
     * @var array
17
     */
18
    protected $nodeUrls;
19
20
    /**
21
     * @var LoggerInterface
22
     */
23
    protected $log;
24
25
    /**
26
     * @var StreamInterface
27
     */
28
    protected $connected;
29
30
31
    /**
32
     * @param array                $nodeUrls
33
     * @param LoggerInterface|null $log
34
     *
35
     * @throws ConnectException
36
     */
37 28
    public function __construct(array $nodeUrls = array(), LoggerInterface $log = null)
38
    {
39 28
        $this->nodeUrls = $nodeUrls;
40
41 28
        if (!$log) {
42 4
            $log = new NullLogger();
43 4
        }
44
45 28
        $this->log       = $log;
46 28
        $this->connected = $this->connect();
47 27
    }
48
49
50
    /**
51
     * @return array
52
     */
53 1
    public function getNodeUrls()
54
    {
55 1
        return $this->nodeUrls;
56
    }
57
58
59
    /**
60
     * @return StreamInterface
61
     */
62 1
    public function getActiveNode()
63
    {
64 1
        return $this->connected;
65
    }
66
67
68
    /**
69
     * @return bool
70
     * @throws ConnectException
71
     */
72 1
    public function reconnect()
0 ignored issues
show
function reconnect() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
73
    {
74 1
        $this->close();
75 1
        $this->connected = $this->connect();
76
77 1
        return true;
78
    }
79
80
81
    /**
82
     * Connect to a random node in the node list.
83
     *
84
     * @return DefaultStream Stream to a connected node.
85
     *
86
     * @throws ConnectException
87
     */
88 28
    public function connect()
89
    {
90 28
        $nodes = $this->nodeUrls;
91
92 28
        while (count($nodes)) {
93
            // pick random server
94 28
            $idx = rand(0, count($nodes) - 1);
95
96
            try {
97 28
                $stream = new DefaultStream($nodes[$idx], $this->log);
98 28
                $stream->connect();
99
100 27
                return $stream;
101 1
            } catch (ConnectException $e) {
102 1
                $this->log->warning($e->getMessage());
103
            }
104
105
            // remove the selected server from the list
106 1
            array_splice($nodes, $idx, 1);
107 1
        }
108
109 1
        throw new ConnectException('unable to connect to any of ['.implode(',', $this->nodeUrls).']');
110
    }
111
112
113
    /**
114
     * Read a line from the stream
115
     *
116
     * @return string
117
     */
118 23
    public function readLine()
119
    {
120 23
        return $this->connected->readLine();
121
    }
122
123
124
    /**
125
     * Read bytes off from the stream.
126
     *
127
     * @param int|null $maxlen
128
     *
129
     * @return string The response.
130
     */
131 13
    public function readBytes($maxlen = null)
132
    {
133 13
        return $this->connected->readBytes($maxlen);
134
    }
135
136
137
    /**
138
     * @param string   $msg
139
     * @param int|null $len
140
     *
141
     * @return StreamInterface the Stream instance.
0 ignored issues
show
Consider making the return type a bit more specific; maybe use Pool.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
142
     */
143 23
    public function write($msg, $len = null)
144
    {
145 23
        $this->connected->write($msg, $len);
146
147 23
        return $this;
148
    }
149
150
151
    /**
152
     * Close the stream.
153
     *
154
     * @return bool True on success.
155
     */
156 26
    public function close()
157
    {
158 26
        return $this->connected->close();
159
    }
160
161
162
    /**
163
     * Check if the stream is connected.
164
     *
165
     * @return boolean True if the stream is connected.
166
     */
167 2
    public function isConnected()
168
    {
169 2
        return $this->connected->isConnected();
170
    }
171
172
173
    /**
174
     * return the internal stream url.
175
     *
176
     * @return string
177
     */
178 2
    public function getNodeUrl()
179
    {
180 2
        return $this->connected->getNodeUrl();
181
    }
182
}
183