Permalink
Browse files

More code styling changes.

  • Loading branch information...
nrk committed Jul 27, 2012
1 parent 6c732c7 commit 55a3fd65a2ec48e9f5c68d076643ce9727a2d417
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
@@ -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
@@ -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
@@ -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;
@@ -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;
},
);
@@ -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();
}
@@ -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);
@@ -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)) {
@@ -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);
@@ -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";
}
@@ -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
@@ -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;
@@ -110,6 +110,7 @@ protected function toStringArgumentReducer($accumulator, $argument)
if (strlen($argument) > 32) {
$argument = substr($argument, 0, 32) . '[...]';
}
+
$accumulator .= " $argument";
return $accumulator;
@@ -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);
}
}
@@ -37,6 +37,7 @@ public function parseResponse($data)
}
$result = array();
+
for ($i = 0; $i < count($data); $i++) {
$result[$data[$i]] = $data[++$i];
}
@@ -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];
@@ -34,6 +34,7 @@ protected function filterArguments(Array $arguments)
list($arguments, $timeout) = $arguments;
array_push($arguments, $timeout);
}
+
return $arguments;
}
@@ -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);
}
}
@@ -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);
}
@@ -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;
}
}
@@ -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;
}
@@ -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];
}
@@ -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;
}
Oops, something went wrong.

0 comments on commit 55a3fd6

Please sign in to comment.