Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More code styling changes.

  • Loading branch information...
commit 55a3fd65a2ec48e9f5c68d076643ce9727a2d417 1 parent 6c732c7
@nrk authored
Showing with 260 additions and 232 deletions.
  1. +1 −2  FAQ.md
  2. +1 −1  README.md
  3. +1 −1  bin/create-phar.php
  4. +10 −9 bin/create-single-file.php
  5. +6 −5 examples/CustomDistributionStrategy.php
  6. +1 −1  examples/DispatcherLoop.php
  7. +2 −2 examples/MasterSlaveReplicationComplex.php
  8. +1 −1  examples/MultiExecTransactionsWithCAS.php
  9. +1 −1  examples/PipelineContext.php
  10. +2 −4 examples/PubSubContext.php
  11. +1 −0  lib/Predis/Autoloader.php
  12. +3 −5 lib/Predis/Client.php
  13. +1 −0  lib/Predis/Command/AbstractCommand.php
  14. +4 −4 lib/Predis/Command/Hash/CommandHashStrategy.php
  15. +1 −0  lib/Predis/Command/HashGetAll.php
  16. +5 −4 lib/Predis/Command/KeySort.php
  17. +1 −0  lib/Predis/Command/ListPopFirstBlocking.php
  18. +2 −4 lib/Predis/Command/Processor/ProcessorChain.php
  19. +1 −2  lib/Predis/Command/ScriptedCommand.php
  20. +1 −5 lib/Predis/Command/ServerBackgroundSave.php
  21. +3 −0  lib/Predis/Command/ServerClient.php
  22. +1 −0  lib/Predis/Command/ServerConfig.php
  23. +3 −2 lib/Predis/Command/ServerInfo.php
  24. +2 −2 lib/Predis/Command/ServerInfoV26x.php
  25. +1 −0  lib/Predis/Command/ZSetAdd.php
  26. +1 −0  lib/Predis/Command/ZSetUnionStore.php
  27. +3 −4 lib/Predis/CommunicationException.php
  28. +1 −0  lib/Predis/Connection/AbstractConnection.php
  29. +7 −4 lib/Predis/Connection/ComposableStreamConnection.php
  30. +3 −0  lib/Predis/Connection/ConnectionFactory.php
  31. +2 −0  lib/Predis/Connection/ConnectionParameters.php
  32. +6 −9 lib/Predis/Connection/MasterSlaveReplication.php
  33. +4 −5 lib/Predis/Connection/PhpiredisConnection.php
  34. +1 −2  lib/Predis/Connection/PredisCluster.php
  35. +3 −0  lib/Predis/Connection/RedisCluster.php
  36. +12 −14 lib/Predis/Connection/StreamConnection.php
  37. +9 −10 lib/Predis/Connection/WebdisConnection.php
  38. +7 −7 lib/Predis/Distribution/HashRing.php
  39. +1 −0  lib/Predis/Distribution/KetamaPureRing.php
  40. +1 −0  lib/Predis/Helpers.php
  41. +4 −5 lib/Predis/Iterator/MultiBulkResponseSimple.php
  42. +3 −2 lib/Predis/Monitor/MonitorContext.php
  43. +4 −3 lib/Predis/Option/ClientCluster.php
  44. +3 −0  lib/Predis/Option/ClientConnectionFactory.php
  45. +2 −3 lib/Predis/Option/ClientOptions.php
  46. +2 −0  lib/Predis/Option/ClientProfile.php
  47. +4 −0 lib/Predis/Option/ClientReplication.php
  48. +4 −7 lib/Predis/Option/CustomOption.php
  49. +0 −1  lib/Predis/Pipeline/MultiExecExecutor.php
  50. +3 −5 lib/Predis/Pipeline/PipelineContext.php
  51. +2 −4 lib/Predis/Pipeline/SafeClusterExecutor.php
  52. +2 −4 lib/Predis/Pipeline/SafeExecutor.php
  53. +4 −0 lib/Predis/Profile/ServerProfile.php
  54. +1 −2  lib/Predis/Profile/ServerVersionNext.php
  55. +1 −2  lib/Predis/Protocol/Text/ResponseMultiBulkHandler.php
  56. +1 −0  lib/Predis/Protocol/Text/TextProtocol.php
  57. +2 −0  lib/Predis/Protocol/Text/TextResponseReader.php
  58. +1 −2  lib/Predis/PubSub/AbstractPubSubContext.php
  59. +4 −2 lib/Predis/PubSub/DispatcherLoop.php
  60. +1 −0  lib/Predis/PubSub/PubSubContext.php
  61. +1 −0  lib/Predis/ServerException.php
  62. +0 −1  lib/Predis/Transaction/AbortedMultiExecException.php
  63. +8 −9 lib/Predis/Transaction/MultiExecContext.php
  64. +5 −3 tests/Predis/ClientTest.php
  65. +1 −1  tests/Predis/Command/Hash/CommandHashStrategyTest.php
  66. +1 −2  tests/Predis/CommunicationExceptionTest.php
  67. +7 −5 tests/Predis/Connection/ConnectionFactoryTest.php
  68. +1 −1  tests/Predis/Connection/MasterSlaveReplicationTest.php
  69. +3 −1 tests/Predis/Option/ClientClusterTest.php
  70. +3 −1 tests/Predis/Option/ClientProfileTest.php
  71. +14 −16 tests/Predis/Pipeline/PipelineContextTest.php
  72. +1 −1  tests/Predis/Profile/ServerProfileTest.php
  73. +1 −1  tests/Predis/PubSub/DispatcherLoopTest.php
  74. +1 −1  tests/Predis/PubSub/PubSubContextTest.php
  75. +48 −37 tests/Predis/Transaction/MultiExecContextTest.php
View
3  FAQ.md
@@ -70,8 +70,7 @@ $client = new Predis\Client();
try {
$client->connect();
-}
-catch (Predis\Connection\ConnectionException $exception) {
+} catch (Predis\Connection\ConnectionException $exception) {
// We could not connect to Redis! Your handling code goes here.
}
View
2  README.md
@@ -102,7 +102,7 @@ $redis = new Predis\Client(array(
array('host' => '10.0.0.2', 'port' => 6379)
));
-$replies = $redis->pipeline(function($pipe) {
+$replies = $redis->pipeline(function ($pipe) {
for ($i = 0; $i < 1000; $i++) {
$pipe->set("key:$i", str_pad($i, 4, '0', 0));
$pipe->get("key:$i");
View
2  bin/create-phar.php
@@ -50,7 +50,7 @@ function getPharStub($options)
return <<<EOSTUB
<?php
Phar::mapPhar('predis.phar');
-spl_autoload_register(function(\$class) {
+spl_autoload_register(function (\$class) {
if (strpos(\$class, 'Predis\\\\') === 0) {
\$file = 'phar://predis.phar/'.strtr(\$class, '\\\', '/').'.php';
if (file_exists(\$file)) {
View
19 bin/create-single-file.php
@@ -184,7 +184,7 @@ private function getOrderedNamespaces($dependencyScores)
{
$namespaces = array_fill_keys(array_unique(
array_map(
- function($fqn) { return PhpNamespace::extractName($fqn); },
+ function ($fqn) { return PhpNamespace::extractName($fqn); },
array_keys($dependencyScores)
)
), 0);
@@ -200,7 +200,7 @@ function($fqn) { return PhpNamespace::extractName($fqn); },
private function getOrderedClasses(PhpNamespace $phpNamespace, $classes)
{
- $nsClassesFQNs = array_map(function($cl) { return $cl->getFQN(); }, $phpNamespace->getClasses());
+ $nsClassesFQNs = array_map(function ($cl) { return $cl->getFQN(); }, $phpNamespace->getClasses());
$nsOrderedClasses = array();
foreach ($nsClassesFQNs as $nsClassFQN) {
@@ -352,7 +352,9 @@ public function getIterator()
public function getPhpCode()
{
- $reducer = function($str, $use) { return $str .= "use $use;\n"; };
+ $reducer = function ($str, $use) {
+ return $str .= "use $use;\n";
+ };
return array_reduce($this->getList(), $reducer, '');
}
@@ -430,7 +432,7 @@ private function extractData()
{
$useDirectives = $this->getNamespace()->getUseDirectives();
- $useExtractor = function($m) use($useDirectives) {
+ $useExtractor = function ($m) use ($useDirectives) {
$useDirectives->add(($namespacedPath = $m[1]));
};
@@ -453,7 +455,7 @@ private function extractHierarchy()
$implements = array();
$extends = array();
- $extractor = function($iterator, $callback) {
+ $extractor = function ($iterator, $callback) {
$className = '';
$iterator->seek($iterator->key() + 1);
@@ -464,8 +466,7 @@ private function extractHierarchy()
if (preg_match('/\s?,\s?/', $token)) {
$callback(trim($className));
$className = '';
- }
- else if ($token == '{') {
+ } else if ($token == '{') {
$callback(trim($className));
return;
}
@@ -510,13 +511,13 @@ private function extractHierarchy()
break;
case T_IMPLEMENTS:
- $extractor($iterator, function($fqn) use (&$implements) {
+ $extractor($iterator, function ($fqn) use (&$implements) {
$implements[] = $fqn;
});
break;
case T_EXTENDS:
- $extractor($iterator, function($fqn) use (&$extends) {
+ $extractor($iterator, function ($fqn) use (&$extends) {
$extends[] = $fqn;
});
break;
View
11 examples/CustomDistributionStrategy.php
@@ -37,7 +37,7 @@ public function add($node, $weight = null)
public function remove($node)
{
- $this->nodes = array_filter($this->nodes, function($n) use($node) {
+ $this->nodes = array_filter($this->nodes, function ($n) use ($node) {
return $n !== $node;
});
@@ -46,8 +46,7 @@ public function remove($node)
public function get($key)
{
- $count = $this->nodesCount;
- if ($count === 0) {
+ if (0 === $count = $this->nodesCount) {
throw new RuntimeException('No connections');
}
@@ -61,9 +60,11 @@ public function hash($value)
}
$options = array(
- 'cluster' => function() {
+ 'cluster' => function () {
$distributor = new NaiveDistributionStrategy();
- return new PredisCluster($distributor);
+ $cluster = new PredisCluster($distributor);
+
+ return $cluster;
},
);
View
2  examples/DispatcherLoop.php
@@ -60,7 +60,7 @@ public function __invoke($payload)
$dispatcher->attachCallback('events', ($events = new EventsListener()));
// Attach a function to control the dispatcher loop termination with a message.
-$dispatcher->attachCallback('control', function($payload) use ($dispatcher) {
+$dispatcher->attachCallback('control', function ($payload) use ($dispatcher) {
if ($payload === 'terminate_dispatcher') {
$dispatcher->stop();
}
View
4 examples/MasterSlaveReplicationComplex.php
@@ -50,13 +50,13 @@ public function getScript() {
);
$options = array(
- 'profile' => function($options) {
+ 'profile' => function ($options) {
$profile = ServerProfile::get('2.6');
$profile->defineCommand('hmgetall', 'HashMultipleGetAll');
return $profile;
},
- 'replication' => function($options) {
+ 'replication' => function ($options) {
$replication = new MasterSlaveReplication();
$replication->setScriptReadOnly(HashMultipleGetAll::BODY);
View
2  examples/MultiExecTransactionsWithCAS.php
@@ -33,7 +33,7 @@ function zpop($client, $key)
// which the client bails out with an exception.
);
- $client->multiExec($options, function($tx) use ($key, &$element) {
+ $client->multiExec($options, function ($tx) use ($key, &$element) {
@list($element) = $tx->zrange($key, 0, 0);
if (isset($element)) {
View
2  examples/PipelineContext.php
@@ -16,7 +16,7 @@
$client = new Predis\Client($single_server);
-$replies = $client->pipeline(function($pipe) {
+$replies = $client->pipeline(function ($pipe) {
$pipe->ping();
$pipe->flushdb();
$pipe->incrby('counter', 10);
View
6 examples/PubSubContext.php
@@ -38,12 +38,10 @@
if ($message->payload == 'quit_loop') {
echo "Aborting pubsub loop...\n";
$pubsub->unsubscribe();
- }
- else {
+ } else {
echo "Received an unrecognized command: {$message->payload}.\n";
}
- }
- else {
+ } else {
echo "Received the following message from {$message->channel}:\n",
" {$message->payload}\n\n";
}
View
1  lib/Predis/Autoloader.php
@@ -53,6 +53,7 @@ public function autoload($className)
if (0 === strpos($className, $this->prefix)) {
$parts = explode('\\', substr($className, $this->prefixLength));
$filepath = $this->directory.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $parts).'.php';
+
if (is_file($filepath)) {
require($filepath);
}
View
8 lib/Predis/Client.php
@@ -189,10 +189,9 @@ public function getConnection($id = null)
{
if (isset($id)) {
if (!$this->connection instanceof AggregatedConnectionInterface) {
- throw new NotSupportedException(
- 'Retrieving connections by alias is supported only with aggregated connections (cluster or replication)'
- );
+ throw new NotSupportedException('Retrieving connections by alias is supported only with aggregated connections');
}
+
return $this->connection->getConnectionById($id);
}
@@ -257,8 +256,7 @@ protected function onResponseError(CommandInterface $command, ResponseErrorInter
}
if ($this->options->exceptions === true) {
- $message = $response->getMessage();
- throw new ServerException($message);
+ throw new ServerException($response->getMessage());
}
return $response;
View
1  lib/Predis/Command/AbstractCommand.php
@@ -110,6 +110,7 @@ protected function toStringArgumentReducer($accumulator, $argument)
if (strlen($argument) > 32) {
$argument = substr($argument, 0, 32) . '[...]';
}
+
$accumulator .= " $argument";
return $accumulator;
View
8 lib/Predis/Command/Hash/CommandHashStrategy.php
@@ -317,9 +317,11 @@ protected function checkSameHashForKeys(Array $keys)
for ($i = 1; $i < $count; $i++) {
$nextKey = $this->extractKeyTag($keys[$i]);
+
if ($currentKey !== $nextKey) {
return false;
}
+
$currentKey = $nextKey;
}
@@ -335,10 +337,8 @@ protected function checkSameHashForKeys(Array $keys)
*/
protected function extractKeyTag($key)
{
- $start = strpos($key, '{');
- if ($start !== false) {
- $end = strpos($key, '}', $start);
- if ($end !== false) {
+ if (false !== $start = strpos($key, '{')) {
+ if (false !== $end = strpos($key, '}', $start)) {
$key = substr($key, ++$start, $end - $start);
}
}
View
1  lib/Predis/Command/HashGetAll.php
@@ -37,6 +37,7 @@ public function parseResponse($data)
}
$result = array();
+
for ($i = 0; $i < count($data); $i++) {
$result[$data[$i]] = $data[++$i];
}
View
9 lib/Predis/Command/KeySort.php
@@ -44,20 +44,21 @@ protected function filterArguments(Array $arguments)
if (isset($sortParams['GET'])) {
$getargs = $sortParams['GET'];
+
if (is_array($getargs)) {
foreach ($getargs as $getarg) {
$query[] = 'GET';
$query[] = $getarg;
}
- }
- else {
+ } else {
$query[] = 'GET';
$query[] = $getargs;
}
}
- if (isset($sortParams['LIMIT']) && is_array($sortParams['LIMIT'])
- && count($sortParams['LIMIT']) == 2) {
+ if (isset($sortParams['LIMIT']) &&
+ is_array($sortParams['LIMIT']) &&
+ count($sortParams['LIMIT']) == 2) {
$query[] = 'LIMIT';
$query[] = $sortParams['LIMIT'][0];
View
1  lib/Predis/Command/ListPopFirstBlocking.php
@@ -34,6 +34,7 @@ protected function filterArguments(Array $arguments)
list($arguments, $timeout) = $arguments;
array_push($arguments, $timeout);
}
+
return $arguments;
}
View
6 lib/Predis/Command/Processor/ProcessorChain.php
@@ -45,8 +45,7 @@ public function add(CommandProcessorInterface $processor)
*/
public function remove(CommandProcessorInterface $processor)
{
- $index = array_search($processor, $this->processors, true);
- if ($index !== false) {
+ if (false !== $index = array_search($processor, $this->processors, true)) {
unset($this[$index]);
}
}
@@ -56,8 +55,7 @@ public function remove(CommandProcessorInterface $processor)
*/
public function process(CommandInterface $command)
{
- $count = count($this->processors);
- for ($i = 0; $i < $count; $i++) {
+ for ($i = 0; $i < $count = count($this->processors); $i++) {
$this->processors[$i]->process($command);
}
}
View
3  lib/Predis/Command/ScriptedCommand.php
@@ -62,8 +62,7 @@ protected function filterArguments(Array $arguments)
{
if (false !== $numkeys = $this->getKeysCount()) {
$numkeys = $numkeys >= 0 ? $numkeys : count($arguments) + $numkeys;
- }
- else {
+ } else {
$numkeys = count($arguments);
}
View
6 lib/Predis/Command/ServerBackgroundSave.php
@@ -30,10 +30,6 @@ public function getId()
*/
public function parseResponse($data)
{
- if ($data == 'Background saving started') {
- return true;
- }
-
- return $data;
+ return $data === 'Background saving started' ? true : $data;
}
}
View
3  lib/Predis/Command/ServerClient.php
@@ -31,6 +31,7 @@ public function getId()
public function parseResponse($data)
{
$args = array_change_key_case($this->getArguments(), CASE_UPPER);
+
switch (strtoupper($args[0])) {
case 'LIST':
return $this->parseClientList($data);
@@ -54,10 +55,12 @@ protected function parseClientList($data)
foreach (explode("\n", $data, -1) as $clientData) {
$client = array();
+
foreach (explode(' ', $clientData) as $kv) {
@list($k, $v) = explode('=', $kv);
$client[$k] = $v;
}
+
$clients[] = $client;
}
View
1  lib/Predis/Command/ServerConfig.php
@@ -40,6 +40,7 @@ public function parseResponse($data)
if (is_array($data)) {
$result = array();
+
for ($i = 0; $i < count($data); $i++) {
$result[$data[$i]] = $data[++$i];
}
View
5 lib/Predis/Command/ServerInfo.php
@@ -45,9 +45,9 @@ public function parseResponse($data)
$info[$k] = $this->parseAllocationStats($v);
continue;
}
+
$info[$k] = $v;
- }
- else {
+ } else {
$info[$k] = $this->parseDatabaseStats($v);
}
}
@@ -91,6 +91,7 @@ protected function parseAllocationStats($str)
$size = ">=$objects";
$objects = $extra;
}
+
$stats[$size] = $objects;
}
View
4 lib/Predis/Command/ServerInfoV26x.php
@@ -48,9 +48,9 @@ public function parseResponse($data)
$current[$k] = $this->parseAllocationStats($v);
continue;
}
+
$current[$k] = $v;
- }
- else {
+ } else {
$current[$k] = $this->parseDatabaseStats($v);
}
}
View
1  lib/Predis/Command/ZSetAdd.php
@@ -34,6 +34,7 @@ protected function filterArguments(Array $arguments)
{
if (count($arguments) === 2 && is_array($arguments[1])) {
$flattened = array($arguments[0]);
+
foreach($arguments[1] as $member => $score) {
$flattened[] = $score;
$flattened[] = $member;
View
1  lib/Predis/Command/ZSetUnionStore.php
@@ -60,6 +60,7 @@ private function prepareOptions($options)
if (isset($opts['WEIGHTS']) && is_array($opts['WEIGHTS'])) {
$finalizedOpts[] = 'WEIGHTS';
+
foreach ($opts['WEIGHTS'] as $weight) {
$finalizedOpts[] = $weight;
}
View
7 lib/Predis/CommunicationException.php
@@ -28,11 +28,10 @@
* @param int $code Error code.
* @param \Exception $innerException Inner exception for wrapping the original error.
*/
- public function __construct(SingleConnectionInterface $connection,
- $message = null, $code = null, \Exception $innerException = null)
- {
+ public function __construct(
+ SingleConnectionInterface $connection, $message = null, $code = null, \Exception $innerException = null
+ ) {
parent::__construct($message, $code, $innerException);
-
$this->connection = $connection;
}
View
1  lib/Predis/Connection/AbstractConnection.php
@@ -92,6 +92,7 @@ public function connect()
if ($this->isConnected()) {
throw new ClientException('Connection already estabilished');
}
+
$this->resource = $this->createResource();
}
View
11 lib/Predis/Connection/ComposableStreamConnection.php
@@ -46,6 +46,7 @@ public function setProtocol(ProtocolInterface $protocol)
if ($protocol === null) {
throw new \InvalidArgumentException("The protocol instance cannot be a null value");
}
+
$this->protocol = $protocol;
}
@@ -79,12 +80,13 @@ public function readBytes($length)
do {
$chunk = fread($socket, $length);
+
if ($chunk === false || $chunk === '') {
$this->onConnectionError('Error while reading bytes from the server');
}
+
$value .= $chunk;
- }
- while (($length -= strlen($chunk)) > 0);
+ } while (($length -= strlen($chunk)) > 0);
return $value;
}
@@ -99,12 +101,13 @@ public function readLine()
do {
$chunk = fgets($socket);
+
if ($chunk === false || $chunk === '') {
$this->onConnectionError('Error while reading line from the server');
}
+
$value .= $chunk;
- }
- while (substr($value, -2) !== "\r\n");
+ } while (substr($value, -2) !== "\r\n");
return substr($value, 0, -2);
}
View
3  lib/Predis/Connection/ConnectionFactory.php
@@ -97,11 +97,13 @@ public function create($parameters, ServerProfileInterface $profile = null)
}
$scheme = $parameters->scheme;
+
if (!isset($this->schemes[$scheme])) {
throw new \InvalidArgumentException("Unknown connection scheme: $scheme");
}
$initializer = $this->schemes[$scheme];
+
if (!is_callable($initializer)) {
$connection = new $initializer($parameters);
$this->prepareConnection($connection, $profile ?: ServerProfile::getDefault());
@@ -110,6 +112,7 @@ public function create($parameters, ServerProfileInterface $profile = null)
}
$connection = call_user_func($initializer, $parameters, $profile);
+
if (!$connection instanceof SingleConnectionInterface) {
throw new \InvalidArgumentException(
'Objects returned by connection initializers must implement ' .
View
2  lib/Predis/Connection/ConnectionParameters.php
@@ -124,6 +124,7 @@ private function parseURI($uri)
@list($k, $v) = explode('=', $kv);
$parsed[$k] = $v;
}
+
unset($parsed['query']);
}
@@ -140,6 +141,7 @@ private function filter(Array $parameters)
{
if (count($parameters) > 0) {
$casters = array_intersect_key($this->getValueCasters(), $parameters);
+
foreach ($casters as $parameter => $caster) {
$parameters[$parameter] = call_user_func($caster, $parameters[$parameter]);
}
View
15 lib/Predis/Connection/MasterSlaveReplication.php
@@ -66,8 +66,7 @@ public function add(SingleConnectionInterface $connection)
if ($alias === 'master') {
$this->master = $connection;
- }
- else {
+ } else {
$this->slaves[$alias ?: count($this->slaves)] = $connection;
}
@@ -84,8 +83,7 @@ public function remove(SingleConnectionInterface $connection)
$this->reset();
return true;
- }
- else {
+ } else {
if (($id = array_search($connection, $this->slaves, true)) !== false) {
unset($this->slaves[$id]);
$this->reset();
@@ -108,7 +106,6 @@ public function getConnection(CommandInterface $command)
return $this->current;
}
-
if ($this->current === $this->master) {
return $this->current;
}
@@ -128,6 +125,7 @@ public function getConnectionById($connectionId)
if ($connectionId === 'master') {
return $this->master;
}
+
if (isset($this->slaves[$connectionId])) {
return $this->slaves[$connectionId];
}
@@ -215,6 +213,7 @@ public function disconnect()
if ($this->master) {
$this->master->disconnect();
}
+
foreach ($this->slaves as $connection) {
$connection->disconnect();
}
@@ -308,8 +307,7 @@ public function setCommandReadOnly($commandID, $readonly = true)
if ($readonly) {
$this->readonly[$commandID] = $readonly;
- }
- else {
+ } else {
unset($this->readonly[$commandID]);
}
}
@@ -330,8 +328,7 @@ public function setScriptReadOnly($script, $readonly = true)
if ($readonly) {
$this->readonlySHA1[$sha1] = $readonly;
- }
- else {
+ } else {
unset($this->readonlySHA1[$sha1]);
}
}
View
9 lib/Predis/Connection/PhpiredisConnection.php
@@ -120,7 +120,7 @@ private function initializeReader() {
*/
private function getStatusHandler()
{
- return function($payload) {
+ return function ($payload) {
switch ($payload) {
case 'OK':
return true;
@@ -142,7 +142,7 @@ private function getStatusHandler()
*/
private function getErrorHandler()
{
- return function($errorMessage) {
+ return function ($errorMessage) {
return new ResponseError($errorMessage);
};
}
@@ -294,6 +294,7 @@ public function connect()
parent::connect();
$this->connectWithTimeout($this->parameters);
+
if (count($this->initCmds) > 0) {
$this->sendInitializationCommands();
}
@@ -306,7 +307,6 @@ public function disconnect()
{
if ($this->isConnected()) {
socket_close($this->getResource());
-
parent::disconnect();
}
}
@@ -363,8 +363,7 @@ public function read()
if ($state === PHPIREDIS_READER_STATE_COMPLETE) {
return phpiredis_reader_get_reply($reader);
- }
- else {
+ } else {
$this->onProtocolError(phpiredis_reader_get_error($reader));
}
}
View
3  lib/Predis/Connection/PredisCluster.php
@@ -84,8 +84,7 @@ public function add(SingleConnectionInterface $connection)
if (isset($parameters->alias)) {
$this->pool[$parameters->alias] = $connection;
- }
- else {
+ } else {
$this->pool[] = $connection;
}
View
3  lib/Predis/Connection/RedisCluster.php
@@ -90,6 +90,7 @@ public function remove(SingleConnectionInterface $connection)
{
if (($id = array_search($connection, $this->pool, true)) !== false) {
unset($this->pool[$id]);
+
return true;
}
@@ -106,6 +107,7 @@ public function removeById($connectionId)
{
if (isset($this->pool[$connectionId])) {
unset($this->pool[$connectionId]);
+
return true;
}
@@ -126,6 +128,7 @@ public function getConnection(CommandInterface $command)
}
$slot = $hash & 0x0FFF;
+
if (isset($this->slots[$slot])) {
return $this->slots[$slot];
}
View
26 lib/Predis/Connection/StreamConnection.php
@@ -78,8 +78,8 @@ protected function createResource()
private function tcpStreamInitializer(ConnectionParametersInterface $parameters)
{
$uri = "tcp://{$parameters->host}:{$parameters->port}/";
-
$flags = STREAM_CLIENT_CONNECT;
+
if (isset($parameters->async_connect) && $parameters->async_connect === true) {
$flags |= STREAM_CLIENT_ASYNC_CONNECT;
}
@@ -87,9 +87,7 @@ private function tcpStreamInitializer(ConnectionParametersInterface $parameters)
$flags |= STREAM_CLIENT_PERSISTENT;
}
- $resource = @stream_socket_client(
- $uri, $errno, $errstr, $parameters->timeout, $flags
- );
+ $resource = @stream_socket_client($uri, $errno, $errstr, $parameters->timeout, $flags);
if (!$resource) {
$this->onConnectionError(trim($errstr), $errno);
@@ -115,15 +113,13 @@ private function tcpStreamInitializer(ConnectionParametersInterface $parameters)
private function unixStreamInitializer(ConnectionParametersInterface $parameters)
{
$uri = "unix://{$parameters->path}";
-
$flags = STREAM_CLIENT_CONNECT;
+
if ($parameters->persistent === true) {
$flags |= STREAM_CLIENT_PERSISTENT;
}
- $resource = @stream_socket_client(
- $uri, $errno, $errstr, $parameters->timeout, $flags
- );
+ $resource = @stream_socket_client($uri, $errno, $errstr, $parameters->timeout, $flags);
if (!$resource) {
$this->onConnectionError(trim($errstr), $errno);
@@ -151,7 +147,6 @@ public function disconnect()
{
if ($this->isConnected()) {
fclose($this->getResource());
-
parent::disconnect();
}
}
@@ -181,12 +176,14 @@ protected function writeBytes($buffer)
while (($length = strlen($buffer)) > 0) {
$written = fwrite($socket, $buffer);
+
if ($length === $written) {
return;
}
if ($written === false || $written === 0) {
$this->onConnectionError('Error while writing bytes to the server');
}
+
$buffer = substr($buffer, $written);
}
}
@@ -196,8 +193,8 @@ protected function writeBytes($buffer)
*/
public function read() {
$socket = $this->getResource();
-
$chunk = fgets($socket);
+
if ($chunk === false || $chunk === '') {
$this->onConnectionError('Error while reading line from the server');
}
@@ -229,11 +226,11 @@ public function read() {
do {
$chunk = fread($socket, min($bytesLeft, 4096));
+
if ($chunk === false || $chunk === '') {
- $this->onConnectionError(
- 'Error while reading bytes from the server'
- );
+ $this->onConnectionError('Error while reading bytes from the server');
}
+
$bulkData .= $chunk;
$bytesLeft = $size - strlen($bulkData);
} while ($bytesLeft > 0);
@@ -242,15 +239,16 @@ public function read() {
case '*': // multi bulk
$count = (int) $payload;
+
if ($count === -1) {
return null;
}
-
if ($this->mbiterable === true) {
return new MultiBulkResponseSimple($this, $count);
}
$multibulk = array();
+
for ($i = 0; $i < $count; $i++) {
$multibulk[$i] = $this->read();
}
View
19 lib/Predis/Connection/WebdisConnection.php
@@ -94,6 +94,7 @@ private function checkExtensions()
if (!function_exists('curl_init')) {
throw new NotSupportedException(sprintf(self::ERR_MSG_EXTENSION, 'curl'));
}
+
if (!function_exists('phpiredis_reader_create')) {
throw new NotSupportedException(sprintf(self::ERR_MSG_EXTENSION, 'phpiredis'));
}
@@ -120,8 +121,7 @@ private function initializeCurl(ConnectionParametersInterface $parameters)
$options[CURLOPT_USERPWD] = "{$parameters->user}:{$parameters->pass}";
}
- $resource = curl_init();
- curl_setopt_array($resource, $options);
+ curl_setopt_array($resource = curl_init(), $options);
return $resource;
}
@@ -149,7 +149,7 @@ private function initializeReader(ConnectionParametersInterface $parameters)
*/
protected function getStatusHandler()
{
- return function($payload) {
+ return function ($payload) {
return $payload === 'OK' ? true : $payload;
};
}
@@ -161,7 +161,7 @@ protected function getStatusHandler()
*/
protected function getErrorHandler()
{
- return function($errorMessage) {
+ return function ($errorMessage) {
return new ResponseError($errorMessage);
};
}
@@ -255,8 +255,7 @@ public function executeCommand(CommandInterface $command)
if ($arguments = $command->getArguments()) {
$arguments = implode('/', array_map('urlencode', $arguments));
$serializedCommand = "$commandId/$arguments.raw";
- }
- else {
+ } else {
$serializedCommand = "$commandId.raw";
}
@@ -272,14 +271,14 @@ public function executeCommand(CommandInterface $command)
if ($readerState === PHPIREDIS_READER_STATE_COMPLETE) {
$reply = phpiredis_reader_get_reply($this->reader);
+
if ($reply instanceof ResponseObjectInterface) {
return $reply;
}
+
return $command->parseResponse($reply);
- }
- else {
- $error = phpiredis_reader_get_error($this->reader);
- throw new ProtocolException($this, $error);
+ } else {
+ throw new ProtocolException($this, phpiredis_reader_get_error($this->reader));
}
}
View
14 lib/Predis/Distribution/HashRing.php
@@ -36,7 +36,7 @@ class HashRing implements DistributionStrategyInterface
public function __construct($replicas = self::DEFAULT_REPLICAS)
{
$this->replicas = $replicas;
- $this->nodes = array();
+ $this->nodes = array();
}
/**
@@ -101,6 +101,7 @@ private function isInitialized()
private function computeTotalWeight()
{
$totalWeight = 0;
+
foreach ($this->nodes as $node) {
$totalWeight += $node['weight'];
}
@@ -123,14 +124,14 @@ private function initialize()
$this->ring = array();
$totalWeight = $this->computeTotalWeight();
- $nodesCount = count($this->nodes);
+ $nodesCount = count($this->nodes);
foreach ($this->nodes as $node) {
$weightRatio = $node['weight'] / $totalWeight;
$this->addNodeToRing($this->ring, $node, $nodesCount, $this->replicas, $weightRatio);
}
- ksort($this->ring, SORT_NUMERIC);
+ ksort($this->ring, SORT_NUMERIC);
$this->ringKeys = array_keys($this->ring);
$this->ringKeysCount = count($this->ringKeys);
}
@@ -199,13 +200,12 @@ private function getNodeKey($key)
while ($lower <= $upper) {
$index = ($lower + $upper) >> 1;
$item = $ringKeys[$index];
+
if ($item > $key) {
$upper = $index - 1;
- }
- else if ($item < $key) {
+ } else if ($item < $key) {
$lower = $index + 1;
- }
- else {
+ } else {
return $item;
}
}
View
1  lib/Predis/Distribution/KetamaPureRing.php
@@ -42,6 +42,7 @@ protected function addNodeToRing(&$ring, $node, $totalNodes, $replicas, $weightR
for ($i = 0; $i < $replicas; $i++) {
$unpackedDigest = unpack('V4', md5("$nodeHash-$i", true));
+
foreach ($unpackedDigest as $key) {
$ring[$key] = $nodeObject;
}
View
1  lib/Predis/Helpers.php
@@ -32,6 +32,7 @@ public static function onCommunicationException(CommunicationException $exceptio
{
if ($exception->shouldResetConnection()) {
$connection = $exception->getConnection();
+
if ($connection->isConnected()) {
$connection->disconnect();
}
View
9 lib/Predis/Iterator/MultiBulkResponseSimple.php
@@ -29,9 +29,9 @@ class MultiBulkResponseSimple extends MultiBulkResponse
public function __construct(SingleConnectionInterface $connection, $size)
{
$this->connection = $connection;
- $this->position = 0;
- $this->current = $size > 0 ? $this->getValue() : null;
- $this->replySize = $size;
+ $this->position = 0;
+ $this->current = $size > 0 ? $this->getValue() : null;
+ $this->replySize = $size;
}
/**
@@ -59,8 +59,7 @@ public function sync($drop = false)
$this->position = $this->replySize;
$this->connection->disconnect();
}
- }
- else {
+ } else {
while ($this->valid()) {
$this->next();
}
View
5 lib/Predis/Monitor/MonitorContext.php
@@ -55,7 +55,6 @@ private function checkCapabilities(ClientInterface $client)
if ($client->getConnection() instanceof AggregatedConnectionInterface) {
throw new NotSupportedException('Cannot initialize a monitor context when using aggregated connections');
}
-
if ($client->getProfile()->supportsCommand('monitor') === false) {
throw new NotSupportedException('The current profile does not support the MONITOR command');
}
@@ -137,16 +136,18 @@ private function getValue()
$client = null;
$event = $this->client->getConnection()->read();
- $callback = function($matches) use (&$database, &$client) {
+ $callback = function ($matches) use (&$database, &$client) {
if (2 === $count = count($matches)) {
// Redis <= 2.4
$database = (int) $matches[1];
}
+
if (4 === $count) {
// Redis >= 2.6
$database = (int) $matches[2];
$client = $matches[3];
}
+
return ' ';
};
View
7 lib/Predis/Option/ClientCluster.php
@@ -45,6 +45,7 @@ public function filter(ClientOptionsInterface $options, $value)
if (is_callable($value)) {
return $this->checkInstance(call_user_func($value, $options));
}
+
$initializer = $this->getInitializer($options, $value);
return $this->checkInstance($initializer());
@@ -61,12 +62,12 @@ protected function getInitializer(ClientOptionsInterface $options, $fqnOrType)
{
switch ($fqnOrType) {
case 'predis':
- return function() {
+ return function () {
return new PredisCluster();
};
case 'redis':
- return function() use($options) {
+ return function () use ($options) {
$connectionFactory = $options->connections;
$cluster = new RedisCluster($connectionFactory);
@@ -78,7 +79,7 @@ protected function getInitializer(ClientOptionsInterface $options, $fqnOrType)
if (is_string($fqnOrType) && !class_exists($fqnOrType)) {
throw new \InvalidArgumentException("Class $fqnOrType does not exist");
}
- return function() use($fqnOrType) {
+ return function () use ($fqnOrType) {
return new $fqnOrType();
};
}
View
3  lib/Predis/Option/ClientConnectionFactory.php
@@ -31,15 +31,18 @@ public function filter(ClientOptionsInterface $options, $value)
}
if (is_array($value)) {
$factory = $this->getDefault($options);
+
foreach ($value as $scheme => $initializer) {
$factory->define($scheme, $initializer);
}
+
return $factory;
}
if (is_string($value) && class_exists($value)) {
if (!($factory = new $value()) && !$factory instanceof ConnectionFactoryInterface) {
throw new \InvalidArgumentException("Class $value must be an instance of Predis\Connection\ConnectionFactoryInterface");
}
+
return $factory;
}
View
5 lib/Predis/Option/ClientOptions.php
@@ -61,11 +61,10 @@ protected function initialize(Array $options)
foreach ($options as $option => $value) {
if (isset($handlers[$option])) {
$handler = $handlers[$option];
- $handlers[$option] = function($options) use($handler, $value) {
+ $handlers[$option] = function ($options) use ($handler, $value) {
return $handler->filter($options, $value);
};
- }
- else {
+ } else {
$this->options[$option] = $value;
}
}
View
2  lib/Predis/Option/ClientProfile.php
@@ -28,6 +28,7 @@ public function filter(ClientOptionsInterface $options, $value)
{
if (is_string($value)) {
$value = ServerProfile::get($value);
+
if (isset($options->prefix)) {
$value->setProcessor($options->prefix);
}
@@ -50,6 +51,7 @@ public function filter(ClientOptionsInterface $options, $value)
public function getDefault(ClientOptionsInterface $options)
{
$profile = ServerProfile::getDefault();
+
if (isset($options->prefix)) {
$profile->setProcessor($options->prefix);
}
View
4 lib/Predis/Option/ClientReplication.php
@@ -43,9 +43,11 @@ public function filter(ClientOptionsInterface $options, $value)
{
if (is_callable($value)) {
$connection = call_user_func($value, $options);
+
if (!$connection instanceof ReplicationConnectionInterface) {
throw new \InvalidArgumentException('Instance of Predis\Connection\ReplicationConnectionInterface expected');
}
+
return $connection;
}
@@ -53,9 +55,11 @@ public function filter(ClientOptionsInterface $options, $value)
if (!class_exists($value)) {
throw new \InvalidArgumentException("Class $value does not exist");
}
+
if (!($connection = new $value()) instanceof ReplicationConnectionInterface) {
throw new \InvalidArgumentException('Instance of Predis\Connection\ReplicationConnectionInterface expected');
}
+
return $connection;
}
View
11 lib/Predis/Option/CustomOption.php
@@ -27,7 +27,7 @@ class CustomOption implements OptionInterface
public function __construct(Array $options = array())
{
$this->filter = $this->ensureCallable($options, 'filter');
- $this->default = $this->ensureCallable($options, 'default');
+ $this->default = $this->ensureCallable($options, 'default');
}
/**
@@ -42,8 +42,7 @@ private function ensureCallable($options, $key)
return;
}
- $callable = $options[$key];
- if (is_callable($callable)) {
+ if (is_callable($callable = $options[$key])) {
return $callable;
}
@@ -59,9 +58,8 @@ public function filter(ClientOptionsInterface $options, $value)
if ($this->filter === null) {
return $value;
}
- $validator = $this->filter;
- return $validator($options, $value);
+ return call_user_func($this->filter, $options, $value);
}
}
@@ -73,9 +71,8 @@ public function getDefault(ClientOptionsInterface $options)
if (!isset($this->default)) {
return;
}
- $default = $this->default;
- return $default($options);
+ return call_user_func($this->default, $options);
}
/**
View
1  lib/Predis/Pipeline/MultiExecExecutor.php
@@ -98,7 +98,6 @@ public function execute(ConnectionInterface $connection, SplQueue $commands)
if ($response = $responses[$i] instanceof \Iterator) {
$response = iterator_to_array($response);
}
-
$values[$i] = $commands->dequeue()->parseResponse($responses[$i]);
unset($responses[$i]);
}
View
8 lib/Predis/Pipeline/PipelineContext.php
@@ -109,10 +109,8 @@ public function flushPipeline($send = true)
if ($send && !$this->pipeline->isEmpty()) {
$connection = $this->client->getConnection();
$replies = $this->executor->execute($connection, $this->pipeline);
-
$this->replies = array_merge($this->replies, $replies);
- }
- else {
+ } else {
$this->pipeline = new SplQueue();
}
@@ -130,6 +128,7 @@ private function setRunning($bool)
if ($bool === true && $this->running === true) {
throw new ClientException("This pipeline is already opened");
}
+
$this->running = $bool;
}
@@ -153,8 +152,7 @@ public function execute($callable = null)
call_user_func($callable, $this);
}
$this->flushPipeline();
- }
- catch (\Exception $exception) {
+ } catch (\Exception $exception) {
$pipelineBlockException = $exception;
}
View
6 lib/Predis/Pipeline/SafeClusterExecutor.php
@@ -42,8 +42,7 @@ public function execute(ConnectionInterface $connection, SplQueue $commands)
try {
$cmdConnection->writeCommand($command);
- }
- catch (CommunicationException $exception) {
+ } catch (CommunicationException $exception) {
$connectionExceptions[spl_object_hash($cmdConnection)] = $exception;
}
}
@@ -62,8 +61,7 @@ public function execute(ConnectionInterface $connection, SplQueue $commands)
try {
$response = $cmdConnection->readResponse($command);
$values[$i] = $response instanceof \Iterator ? iterator_to_array($response) : $response;
- }
- catch (CommunicationException $exception) {
+ } catch (CommunicationException $exception) {
$values[$i] = $exception;
$connectionExceptions[$connectionObjectHash] = $exception;
}
View
6 lib/Predis/Pipeline/SafeExecutor.php
@@ -35,8 +35,7 @@ public function execute(ConnectionInterface $connection, SplQueue $commands)
foreach ($commands as $command) {
try {
$connection->writeCommand($command);
- }
- catch (CommunicationException $exception) {
+ } catch (CommunicationException $exception) {
return array_fill(0, $size, $exception);
}
}
@@ -47,8 +46,7 @@ public function execute(ConnectionInterface $connection, SplQueue $commands)
try {
$response = $connection->readResponse($command);
$values[$i] = $response instanceof \Iterator ? iterator_to_array($response) : $response;
- }
- catch (CommunicationException $exception) {
+ } catch (CommunicationException $exception) {
$toAdd = count($commands) - count($values);
$values = array_merge($values, array_fill(0, $toAdd, $exception));
break;
View
4 lib/Predis/Profile/ServerProfile.php
@@ -114,6 +114,7 @@ public static function get($version)
if (!isset(self::$profiles)) {
self::$profiles = self::getDefaultProfiles();
}
+
if (!isset(self::$profiles[$version])) {
throw new ClientException("Unknown server profile: $version");
}
@@ -165,6 +166,7 @@ public function getCommandClass($command)
public function createCommand($method, $arguments = array())
{
$method = strtolower($method);
+
if (!isset($this->commands[$method])) {
throw new ClientException("'$method' is not a registered Redis command");
}
@@ -189,9 +191,11 @@ public function createCommand($method, $arguments = array())
public function defineCommand($alias, $command)
{
$commandReflection = new \ReflectionClass($command);
+
if (!$commandReflection->isSubclassOf('Predis\Command\CommandInterface')) {
throw new \InvalidArgumentException("Cannot register '$command' as it is not a valid Redis command");
}
+
$this->commands[strtolower($alias)] = $command;
}
View
3  lib/Predis/Profile/ServerVersionNext.php
@@ -31,7 +31,6 @@ public function getVersion()
*/
public function getSupportedCommands()
{
- return array_merge(parent::getSupportedCommands(), array(
- ));
+ return array_merge(parent::getSupportedCommands(), array());
}
}
View
3  lib/Predis/Protocol/Text/ResponseMultiBulkHandler.php
@@ -58,8 +58,7 @@ public function handle(ComposableConnectionInterface $connection, $lengthString)
if (isset($handlersCache[$prefix])) {
$handler = $handlersCache[$prefix];
- }
- else {
+ } else {
$handler = $reader->getHandler($prefix);
$handlersCache[$prefix] = $handler;
}
View
1  lib/Predis/Protocol/Text/TextProtocol.php
@@ -103,6 +103,7 @@ public function read(ComposableConnectionInterface $connection)
}
$multibulk = array();
+
for ($i = 0; $i < $count; $i++) {
$multibulk[$i] = $this->read($connection);
}
View
2  lib/Predis/Protocol/Text/TextResponseReader.php
@@ -83,11 +83,13 @@ public function getHandler($prefix)
public function read(ComposableConnectionInterface $connection)
{
$header = $connection->readLine();
+
if ($header === '') {
$this->protocolError($connection, 'Unexpected empty header');
}
$prefix = $header[0];
+
if (!isset($this->handlers[$prefix])) {
$this->protocolError($connection, "Unknown prefix '$prefix'");
}
View
3  lib/Predis/PubSub/AbstractPubSubContext.php
@@ -115,8 +115,7 @@ public function closeContext($force = false)
if ($force) {
$this->invalidate();
$this->disconnect();
- }
- else {
+ } else {
if ($this->isFlagSet(self::STATUS_SUBSCRIBED)) {
$this->unsubscribe();
}
View
6 lib/Predis/PubSub/DispatcherLoop.php
@@ -69,6 +69,7 @@ public function subscriptionCallback($callable = null)
if (isset($callable)) {
$this->validateCallback($callable);
}
+
$this->subscriptionCallback = $callable;
}
@@ -83,6 +84,7 @@ public function defaultCallback($callable = null)
if (isset($callable)) {
$this->validateCallback($callable);
}
+
$this->subscriptionCallback = $callable;
}
@@ -125,14 +127,14 @@ public function run()
$callback = $this->subscriptionCallback;
call_user_func($callback, $message);
}
+
continue;
}
if (isset($this->callbacks[$message->channel])) {
$callback = $this->callbacks[$message->channel];
call_user_func($callback, $message->payload);
- }
- else if (isset($this->defaultCallback)) {
+ } else if (isset($this->defaultCallback)) {
$callback = $this->defaultCallback;
call_user_func($callback, $message);
}
View
1  lib/Predis/PubSub/PubSubContext.php
@@ -54,6 +54,7 @@ private function checkCapabilities(ClientInterface $client)
}
$commands = array('publish', 'subscribe', 'unsubscribe', 'psubscribe', 'punsubscribe');
+
if ($client->getProfile()->supportsCommands($commands) === false) {
throw new NotSupportedException('The current profile does not support PUB/SUB related commands');
}
View
1  lib/Predis/ServerException.php
@@ -26,6 +26,7 @@ class ServerException extends PredisException implements ResponseErrorInterface
public function getErrorType()
{
list($errorType, ) = explode(' ', $this->getMessage(), 2);
+
return $errorType;
}
View
1  lib/Predis/Transaction/AbortedMultiExecException.php
@@ -30,7 +30,6 @@ class AbortedMultiExecException extends PredisException
public function __construct(MultiExecContext $transaction, $message, $code = null)
{
parent::__construct($message, $code);
-
$this->transaction = $transaction;
}
View
17 lib/Predis/Transaction/MultiExecContext.php
@@ -122,6 +122,7 @@ private function checkCapabilities(ClientInterface $client)
}
$profile = $client->getProfile();
+
if ($profile->supportsCommands(array('multi', 'exec', 'discard')) === false) {
throw new NotSupportedException('The current profile does not support MULTI, EXEC and DISCARD');
}
@@ -171,6 +172,7 @@ protected function initialize()
if (!$cas || ($cas && $discarded)) {
$this->client->multi();
+
if ($discarded) {
$this->unflagState(self::STATE_CAS);
}
@@ -204,12 +206,12 @@ public function __call($method, $arguments)
public function executeCommand(CommandInterface $command)
{
$this->initialize();
-
$response = $this->client->executeCommand($command);
if ($this->checkState(self::STATE_CAS)) {
return $response;
}
+
if (!$response instanceof ResponseQueued) {
$this->onProtocolError('The server did not respond with a QUEUED status reply');
}
@@ -249,8 +251,7 @@ public function multi()
if ($this->checkState(self::STATE_INITIALIZED | self::STATE_CAS)) {
$this->unflagState(self::STATE_CAS);
$this->client->multi();
- }
- else {
+ } else {
$this->initialize();
}
@@ -350,6 +351,7 @@ public function execute($callable = null)
if ($this->checkState(self::STATE_WATCH)) {
$this->discard();
}
+
return;
}
@@ -414,14 +416,11 @@ protected function executeTransactionBlock($callable)
try {
call_user_func($callable, $this);
- }
- catch (CommunicationException $exception) {
+ } catch (CommunicationException $exception) {
$blockException = $exception;
- }
- catch (ServerException $exception) {
+ } catch (ServerException $exception) {
$blockException = $exception;
- }
- catch (\Exception $exception) {
+ } catch (\Exception $exception) {
$blockException = $exception;
$this->discard();
}
View
8 tests/Predis/ClientTest.php
@@ -432,7 +432,7 @@ public function testGetConnectionFromClusterWithAlias()
/**
* @group disconnected
* @expectedException Predis\NotSupportedException
- * @expectedExceptionMessage Retrieving connections by alias is supported only with aggregated connections (cluster or replication)
+ * @expectedExceptionMessage Retrieving connections by alias is supported only with aggregated connections
*/
public function testGetConnectionWithAliasWorksOnlyWithCluster()
{
@@ -491,7 +491,7 @@ public function testPipelineWithArrayAndCallableExecutesPipelineWithOptions()
$options = array('executor' => $executor);
$test = $this;
- $mockCallback = function($pipeline) use($executor, $test) {
+ $mockCallback = function ($pipeline) use ($executor, $test) {
$reflection = new \ReflectionProperty($pipeline, 'executor');
$reflection->setAccessible(true);
@@ -602,7 +602,9 @@ public function testMultiExecWithArrayAndCallableExecutesMultiExec()
->method('executeCommand')
->will($this->returnValue(new ResponseQueued()));
- $txCallback = function($tx) { $tx->ping(); };
+ $txCallback = function ($tx) {
+ $tx->ping();
+ };
$callable = $this->getMock('stdClass', array('__invoke'));
$callable->expects($this->once())
View
2  tests/Predis/Command/Hash/CommandHashStrategyTest.php
@@ -314,7 +314,7 @@ protected function getExpectedCommands($type = null)
);
if (isset($type)) {
- $commands = array_filter($commands, function($expectedType) use($type) {
+ $commands = array_filter($commands, function ($expectedType) use ($type) {
return $expectedType === $type;
});
}
View
3  tests/Predis/CommunicationExceptionTest.php
@@ -72,8 +72,7 @@ protected function getMockedConnectionBase($parameters = null)
if ($parameters === null) {
$builder->disableOriginalConstructor();
- }
- else if (!$parameters instanceof ConnectionParametersInterface) {
+ } else if (!$parameters instanceof ConnectionParametersInterface) {
$parameters = new ConnectionParameters($parameters);
}
View
12 tests/Predis/Connection/ConnectionFactoryTest.php
@@ -133,9 +133,11 @@ public function testCreateConnectionWithInitializationCommands()
$password = 'foobar';
$commands = array();
- $createCommand = function($id, $arguments) use($test, &$commands) {
+ $createCommand = function ($id, $arguments) use ($test, &$commands) {
$commands[$id] = $arguments;
- return $test->getMock('Predis\Command\CommandInterface');
+ $command = $test->getMock('Predis\Command\CommandInterface');
+
+ return $command;
};
$profile = $this->getMock('Predis\Profile\ServerProfileInterface');
@@ -191,7 +193,7 @@ public function testDefineConnectionWithCallable()
$parameters = new ConnectionParameters(array('scheme' => 'foobar'));
- $initializer = function($parameters) use($connectionClass) {
+ $initializer = function ($parameters) use ($connectionClass) {
return new $connectionClass($parameters);
};
@@ -297,7 +299,7 @@ public function testAggregatedConnectionWithMixedParameters()
$factory = $this->getMock('Predis\Connection\ConnectionFactory', array('create'));
$factory->expects($this->exactly(3))
->method('create')
- ->will($this->returnCallback(function($_, $_) use($connectionClass) {
+ ->will($this->returnCallback(function ($_, $_) use ($connectionClass) {
return new $connectionClass;
}));
@@ -333,7 +335,7 @@ public function testAggregatedConnectionWithServerProfileArgument()
$factory->expects($this->exactly(2))
->method('create')
->with($this->anything(), $profile)
- ->will($this->returnCallback(function($_, $_) use($connectionClass) {
+ ->will($this->returnCallback(function ($_, $_) use ($connectionClass) {
return new $connectionClass();
}));
View
2  tests/Predis/Connection/MasterSlaveReplicationTest.php
@@ -493,7 +493,7 @@ public function testAcceptsCallableToOverrideReadOnlyFlagForCommands()
$replication->add($master);
$replication->add($slave1);
- $replication->setCommandReadOnly('exists', function($cmd) {
+ $replication->setCommandReadOnly('exists', function ($cmd) {
list($arg1) = $cmd->getArguments();
return $arg1 === 'foo';
});
View
4 tests/Predis/Option/ClientClusterTest.php
@@ -102,7 +102,9 @@ public function testValidationThrowsExceptionOnInvalidObjectReturnedByCallback()
{
$this->setExpectedException('InvalidArgumentException');
- $value = function($options) { return new \stdClass(); };
+ $value = function ($options) {
+ return new \stdClass();
+ };
$options = $this->getMock('Predis\Option\ClientOptionsInterface');
$option = new ClientCluster();
View
4 tests/Predis/Option/ClientProfileTest.php
@@ -199,7 +199,9 @@ public function testValidationDoesNotSetPrefixProcessorWhenValueIsProfileInstanc
*/
public function testValidationThrowsExceptionOnInvalidObjectReturnedByCallback()
{
- $value = function($options) { return new \stdClass(); };
+ $value = function ($options) {
+ return new \stdClass();
+ };
$options = $this->getMock('Predis\Option\ClientOptionsInterface');
$option = new ClientProfile();
View
30 tests/Predis/Pipeline/PipelineContextTest.php
@@ -178,7 +178,7 @@ public function testExecuteAcceptsCallableArgument()
$test = $this;
$pipeline = new PipelineContext(new Client());
- $callable = function($pipe) use($test, $pipeline) {
+ $callable = function ($pipe) use ($test, $pipeline) {
$test->assertSame($pipeline, $pipe);
$pipe->flushPipeline(false);
};
@@ -206,7 +206,7 @@ public function testExecuteInsideCallableArgumentThrowsException()
{
$pipeline = new PipelineContext(new Client());
- $pipeline->execute(function($pipe) {
+ $pipeline->execute(function ($pipe) {
$pipe->execute();
});
}
@@ -225,7 +225,7 @@ public function testExecuteWithCallableArgumentRunsPipelineInCallable()
$pipeline = new PipelineContext(new Client($connection));
- $replies = $pipeline->execute(function($pipe) {
+ $replies = $pipeline->execute(function ($pipe) {
$pipe->echo('one');
$pipe->echo('two');
$pipe->echo('three');
@@ -250,13 +250,12 @@ public function testExecuteWithCallableArgumentHandlesExceptions()