This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace PHPDaemon\Clients\Redis; |
||
3 | |||
4 | use PHPDaemon\Core\CallbackWrapper; |
||
5 | |||
6 | /** |
||
7 | * @package NetworkClients |
||
8 | * @subpackage RedisClient |
||
9 | * @author Vasily Zorin <[email protected]> |
||
10 | */ |
||
11 | class Pool extends \PHPDaemon\Network\Client |
||
12 | { |
||
13 | /** |
||
14 | * @var Connection[] |
||
15 | */ |
||
16 | public $servConnSub = []; |
||
17 | |||
18 | protected $currentMasterAddr; |
||
19 | |||
20 | /** |
||
21 | * @TODO |
||
22 | * @param string $key |
||
23 | * @param integer $timeout |
||
24 | * @return Lock |
||
25 | */ |
||
26 | public function lock($key, $timeout) |
||
27 | { |
||
28 | return new Lock($key, $timeout, $this); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Easy wrapper for queue of eval's |
||
33 | * @param callable $cb |
||
0 ignored issues
–
show
|
|||
34 | * @return MultiEval |
||
35 | */ |
||
36 | public function meval($cb = null) |
||
37 | { |
||
38 | return new MultiEval($cb, $this); |
||
0 ignored issues
–
show
It seems like
$cb defined by parameter $cb on line 36 can also be of type null ; however, PHPDaemon\Clients\Redis\MultiEval::__construct() does only seem to accept callable , maybe add an additional type check?
This check looks at variables that have been passed in as parameters and are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble. ![]() |
|||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Wrapper for scans commands |
||
43 | * @param string $cmd Command |
||
44 | * @param array $args Arguments |
||
45 | * @param cllable $cbEnd Callback |
||
0 ignored issues
–
show
Should the type for parameter
$cbEnd not be cllable|null ?
This check looks for It makes a suggestion as to what type it considers more descriptive. Most often this is a case of a parameter that can be null in addition to its declared types. ![]() |
|||
46 | * @param integer $limit Limit |
||
0 ignored issues
–
show
Should the type for parameter
$limit not be integer|null ?
This check looks for It makes a suggestion as to what type it considers more descriptive. Most often this is a case of a parameter that can be null in addition to its declared types. ![]() |
|||
47 | * @return AutoScan |
||
48 | */ |
||
49 | public function autoscan($cmd, $args = [], $cbEnd = null, $limit = null) |
||
50 | { |
||
51 | return new AutoScan($this, $cmd, $args, $cbEnd, $limit); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @param string $chan |
||
56 | * @return integer |
||
57 | */ |
||
58 | public function getLocalSubscribersCount($chan) |
||
59 | { |
||
60 | $count = 0; |
||
61 | |||
62 | foreach ($this->servConnSub as $conn) { |
||
63 | $count += $conn->getLocalSubscribersCount($chan); |
||
64 | } |
||
65 | |||
66 | return $count; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Magic __call |
||
71 | * Example: |
||
72 | * $redis->lpush('mylist', microtime(true)); |
||
73 | * @param string $name Command name |
||
0 ignored issues
–
show
There is no parameter named
$name . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
74 | * @param array $args Arguments |
||
75 | * @return void |
||
76 | */ |
||
77 | public function __call($cmd, $args) |
||
78 | { |
||
79 | $cb = null; |
||
80 | View Code Duplication | for ($i = sizeof($args) - 1; $i >= 0; --$i) { |
|
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. ![]() |
|||
81 | $a = $args[$i]; |
||
82 | if ((is_array($a) || is_object($a)) && is_callable($a)) { |
||
83 | $cb = CallbackWrapper::wrap($a); |
||
84 | $args = array_slice($args, 0, $i); |
||
85 | break; |
||
86 | } elseif ($a !== null) { |
||
87 | break; |
||
88 | } |
||
89 | } |
||
90 | reset($args); |
||
91 | $cmd = strtoupper($cmd); |
||
92 | |||
93 | if ($this->sendSubCommand($cmd, $args, $cb)) { |
||
0 ignored issues
–
show
It seems like
$cb can be null ; however, sendSubCommand() does not accept null , maybe add an additional type check?
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: /** @return stdClass|null */
function mayReturnNull() { }
function doesNotAcceptNull(stdClass $x) { }
// With potential error.
function withoutCheck() {
$x = mayReturnNull();
doesNotAcceptNull($x); // Potential error here.
}
// Safe - Alternative 1
function withCheck1() {
$x = mayReturnNull();
if ( ! $x instanceof stdClass) {
throw new \LogicException('$x must be defined.');
}
doesNotAcceptNull($x);
}
// Safe - Alternative 2
function withCheck2() {
$x = mayReturnNull();
if ($x instanceof stdClass) {
doesNotAcceptNull($x);
}
}
![]() |
|||
94 | return; |
||
95 | } |
||
96 | |||
97 | if ($cmd === 'SENTINEL' || !isset($this->config->sentinelmaster->value)) { |
||
0 ignored issues
–
show
The property
sentinelmaster does not seem to exist in PHPDaemon\Config\Section .
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
98 | $this->sendCommand(null, $cmd, $args, $cb); |
||
0 ignored issues
–
show
It seems like
$cb can be null ; however, sendCommand() does not accept null , maybe add an additional type check?
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: /** @return stdClass|null */
function mayReturnNull() { }
function doesNotAcceptNull(stdClass $x) { }
// With potential error.
function withoutCheck() {
$x = mayReturnNull();
doesNotAcceptNull($x); // Potential error here.
}
// Safe - Alternative 1
function withCheck1() {
$x = mayReturnNull();
if ( ! $x instanceof stdClass) {
throw new \LogicException('$x must be defined.');
}
doesNotAcceptNull($x);
}
// Safe - Alternative 2
function withCheck2() {
$x = mayReturnNull();
if ($x instanceof stdClass) {
doesNotAcceptNull($x);
}
}
![]() |
|||
99 | return; |
||
100 | } |
||
101 | if ($this->currentMasterAddr !== null) { |
||
102 | $this->sendCommand($this->currentMasterAddr, $cmd, $args, $cb); |
||
0 ignored issues
–
show
It seems like
$cb can be null ; however, sendCommand() does not accept null , maybe add an additional type check?
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: /** @return stdClass|null */
function mayReturnNull() { }
function doesNotAcceptNull(stdClass $x) { }
// With potential error.
function withoutCheck() {
$x = mayReturnNull();
doesNotAcceptNull($x); // Potential error here.
}
// Safe - Alternative 1
function withCheck1() {
$x = mayReturnNull();
if ( ! $x instanceof stdClass) {
throw new \LogicException('$x must be defined.');
}
doesNotAcceptNull($x);
}
// Safe - Alternative 2
function withCheck2() {
$x = mayReturnNull();
if ($x instanceof stdClass) {
doesNotAcceptNull($x);
}
}
![]() |
|||
103 | return; |
||
104 | } |
||
105 | $this->sentinel('get-master-addr-by-name', $this->config->sentinelmaster->value, |
||
0 ignored issues
–
show
The method
sentinel does not exist on object<PHPDaemon\Clients\Redis\Pool> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when 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 { }
![]() |
|||
106 | function ($redis) use ($cmd, $args, $cb) { |
||
107 | $this->currentMasterAddr = 'tcp://' . $redis->result[0] . ':' . $redis->result[1]; |
||
108 | $this->sendCommand($this->currentMasterAddr, $cmd, $args, $cb); |
||
109 | }); |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @TODO |
||
114 | * @param string $cmd |
||
115 | * @param array $args |
||
116 | * @param callable $cb |
||
117 | * @callback $cb ( ) |
||
118 | * @return boolean |
||
119 | */ |
||
120 | protected function sendSubCommand($cmd, $args, $cb) |
||
121 | { |
||
122 | if (in_array($cmd, ['SUBSCRIBE', 'PSUBSCRIBE', 'UNSUBSCRIBE', 'PUNSUBSCRIBE', 'UNSUBSCRIBEREAL'])) { |
||
123 | foreach ($this->servConnSub as $conn) { |
||
124 | $conn->command($cmd, $args, $cb); |
||
125 | return true; |
||
126 | } |
||
127 | } |
||
128 | return false; |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * @TODO |
||
133 | * @param string $addr |
||
134 | * @param string $cmd |
||
135 | * @param array $args |
||
136 | * @param callable $cb |
||
137 | * @callback $cb ( ) |
||
138 | * @return void |
||
139 | */ |
||
140 | protected function sendCommand($addr, $cmd, $args, $cb) |
||
141 | { |
||
142 | $this->getConnection($addr, function ($conn) use ($cmd, $args, $cb) { |
||
143 | if (!$conn->isConnected()) { |
||
144 | if ($cb !== null) { |
||
145 | $cb(null); |
||
146 | } |
||
147 | return; |
||
148 | } |
||
149 | |||
150 | if ($this->sendSubCommand($cmd, $args, $cb)) { |
||
151 | return; |
||
152 | } |
||
153 | |||
154 | $conn->command($cmd, $args, $cb); |
||
155 | }); |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * Setting default config options |
||
160 | * Overriden from NetworkClient::getConfigDefaults |
||
161 | * @return array|bool |
||
162 | */ |
||
163 | protected function getConfigDefaults() |
||
164 | { |
||
165 | return [ |
||
166 | /* [string|array] Default servers */ |
||
167 | 'servers' => 'tcp://127.0.0.1', |
||
168 | |||
169 | /* [integer] Default port */ |
||
170 | 'port' => 6379, |
||
171 | |||
172 | /* [integer] Maximum connections per server */ |
||
173 | 'maxconnperserv' => 32, |
||
174 | |||
175 | /* [integer] Maximum allowed size of packet */ |
||
176 | 'max-allowed-packet' => new \PHPDaemon\Config\Entry\Size('1M'), |
||
177 | |||
178 | /* [boolean] If true, race condition between UNSUBSCRIBE and PUBLISH will be journaled */ |
||
179 | 'log-pub-sub-race-condition' => true, |
||
180 | |||
181 | /* [integer] Select storage number */ |
||
182 | 'select' => null, |
||
183 | |||
184 | /* [integer] <master name> for Sentinel */ |
||
185 | 'sentinel-master' => null, |
||
186 | ]; |
||
187 | } |
||
188 | } |
||
189 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.