Browse Source

Minor code styling and phpdoc changes.

Daniele Alessandri 11 years ago
parent
commit
df653a7c00

+ 2 - 4
src/Client.php

@@ -477,7 +477,7 @@ class Client implements ClientInterface
      *
      *
      * @param mixed ... Array of options, a callable for execution, or both.
      * @param mixed ... Array of options, a callable for execution, or both.
      *
      *
-     * @return PubSubConsumer|NULL
+     * @return PubSubConsumer|null
      */
      */
     public function pubSubLoop(/* arguments */)
     public function pubSubLoop(/* arguments */)
     {
     {
@@ -490,7 +490,7 @@ class Client implements ClientInterface
      * @param array $options  Options for the context.
      * @param array $options  Options for the context.
      * @param mixed $callable Optional callable used to execute the context.
      * @param mixed $callable Optional callable used to execute the context.
      *
      *
-     * @return PubSubConsumer|NULL
+     * @return PubSubConsumer|null
      */
      */
     protected function createPubSub(array $options = null, $callable = null)
     protected function createPubSub(array $options = null, $callable = null)
     {
     {
@@ -505,8 +505,6 @@ class Client implements ClientInterface
                 $pubsub->stop();
                 $pubsub->stop();
             }
             }
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**

+ 6 - 18
src/Cluster/ClusterStrategy.php

@@ -225,7 +225,7 @@ abstract class ClusterStrategy implements StrategyInterface
      *
      *
      * @param CommandInterface $command Command instance.
      * @param CommandInterface $command Command instance.
      *
      *
-     * @return string
+     * @return string|null
      */
      */
     protected function getKeyFromAllArguments(CommandInterface $command)
     protected function getKeyFromAllArguments(CommandInterface $command)
     {
     {
@@ -234,8 +234,6 @@ abstract class ClusterStrategy implements StrategyInterface
         if ($this->checkSameSlotForKeys($arguments)) {
         if ($this->checkSameSlotForKeys($arguments)) {
             return $arguments[0];
             return $arguments[0];
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**
@@ -244,7 +242,7 @@ abstract class ClusterStrategy implements StrategyInterface
      *
      *
      * @param CommandInterface $command Command instance.
      * @param CommandInterface $command Command instance.
      *
      *
-     * @return string
+     * @return string|null
      */
      */
     protected function getKeyFromInterleavedArguments(CommandInterface $command)
     protected function getKeyFromInterleavedArguments(CommandInterface $command)
     {
     {
@@ -258,8 +256,6 @@ abstract class ClusterStrategy implements StrategyInterface
         if ($this->checkSameSlotForKeys($keys)) {
         if ($this->checkSameSlotForKeys($keys)) {
             return $arguments[0];
             return $arguments[0];
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**
@@ -267,7 +263,7 @@ abstract class ClusterStrategy implements StrategyInterface
      *
      *
      * @param CommandInterface $command Command instance.
      * @param CommandInterface $command Command instance.
      *
      *
-     * @return string
+     * @return string|null
      */
      */
     protected function getKeyFromBlockingListCommands(CommandInterface $command)
     protected function getKeyFromBlockingListCommands(CommandInterface $command)
     {
     {
@@ -276,8 +272,6 @@ abstract class ClusterStrategy implements StrategyInterface
         if ($this->checkSameSlotForKeys(array_slice($arguments, 0, count($arguments) - 1))) {
         if ($this->checkSameSlotForKeys(array_slice($arguments, 0, count($arguments) - 1))) {
             return $arguments[0];
             return $arguments[0];
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**
@@ -285,7 +279,7 @@ abstract class ClusterStrategy implements StrategyInterface
      *
      *
      * @param CommandInterface $command Command instance.
      * @param CommandInterface $command Command instance.
      *
      *
-     * @return string
+     * @return string|null
      */
      */
     protected function getKeyFromBitOp(CommandInterface $command)
     protected function getKeyFromBitOp(CommandInterface $command)
     {
     {
@@ -294,8 +288,6 @@ abstract class ClusterStrategy implements StrategyInterface
         if ($this->checkSameSlotForKeys(array_slice($arguments, 1, count($arguments)))) {
         if ($this->checkSameSlotForKeys(array_slice($arguments, 1, count($arguments)))) {
             return $arguments[1];
             return $arguments[1];
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**
@@ -303,7 +295,7 @@ abstract class ClusterStrategy implements StrategyInterface
      *
      *
      * @param CommandInterface $command Command instance.
      * @param CommandInterface $command Command instance.
      *
      *
-     * @return string
+     * @return string|null
      */
      */
     protected function getKeyFromZsetAggregationCommands(CommandInterface $command)
     protected function getKeyFromZsetAggregationCommands(CommandInterface $command)
     {
     {
@@ -313,8 +305,6 @@ abstract class ClusterStrategy implements StrategyInterface
         if ($this->checkSameSlotForKeys($keys)) {
         if ($this->checkSameSlotForKeys($keys)) {
             return $arguments[0];
             return $arguments[0];
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**
@@ -322,7 +312,7 @@ abstract class ClusterStrategy implements StrategyInterface
      *
      *
      * @param CommandInterface $command Command instance.
      * @param CommandInterface $command Command instance.
      *
      *
-     * @return string
+     * @return string|null
      */
      */
     protected function getKeyFromScriptingCommands(CommandInterface $command)
     protected function getKeyFromScriptingCommands(CommandInterface $command)
     {
     {
@@ -335,8 +325,6 @@ abstract class ClusterStrategy implements StrategyInterface
         if ($keys && $this->checkSameSlotForKeys($keys)) {
         if ($keys && $this->checkSameSlotForKeys($keys)) {
             return $keys[0];
             return $keys[0];
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**

+ 1 - 1
src/Cluster/Distributor/DistributorInterface.php

@@ -51,7 +51,7 @@ interface DistributorInterface
      *
      *
      * @param mixed $slot
      * @param mixed $slot
      *
      *
-     * @return mixed
+     * @return mixed|null
      */
      */
     public function getBySlot($slot);
     public function getBySlot($slot);
 
 

+ 0 - 2
src/Cluster/Distributor/HashRing.php

@@ -204,8 +204,6 @@ class HashRing implements DistributorInterface, HashGeneratorInterface
         if (isset($this->ring[$slot])) {
         if (isset($this->ring[$slot])) {
             return $this->ring[$slot];
             return $this->ring[$slot];
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**

+ 0 - 4
src/Command/Command.php

@@ -67,8 +67,6 @@ abstract class Command implements CommandInterface
         if (isset($this->arguments[$index])) {
         if (isset($this->arguments[$index])) {
             return $this->arguments[$index];
             return $this->arguments[$index];
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**
@@ -87,8 +85,6 @@ abstract class Command implements CommandInterface
         if (isset($this->slot)) {
         if (isset($this->slot)) {
             return $this->slot;
             return $this->slot;
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**

+ 2 - 2
src/Command/CommandInterface.php

@@ -36,7 +36,7 @@ interface CommandInterface
     /**
     /**
      * Returns the assigned slot of the command for clustering distribution.
      * Returns the assigned slot of the command for clustering distribution.
      *
      *
-     * @return int
+     * @return int|null
      */
      */
     public function getSlot();
     public function getSlot();
 
 
@@ -66,7 +66,7 @@ interface CommandInterface
      *
      *
      * @param int $index Index of the desired argument.
      * @param int $index Index of the desired argument.
      *
      *
-     * @return mixed
+     * @return mixed|null
      */
      */
     public function getArgument($index);
     public function getArgument($index);
 
 

+ 0 - 4
src/Command/RawCommand.php

@@ -101,8 +101,6 @@ class RawCommand implements CommandInterface
         if (isset($this->arguments[$index])) {
         if (isset($this->arguments[$index])) {
             return $this->arguments[$index];
             return $this->arguments[$index];
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**
@@ -121,8 +119,6 @@ class RawCommand implements CommandInterface
         if (isset($this->slot)) {
         if (isset($this->slot)) {
             return $this->slot;
             return $this->slot;
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**

+ 3 - 3
src/Configuration/ClusterOption.php

@@ -31,7 +31,7 @@ class ClusterOption implements OptionInterface
      * @param OptionsInterface $options Instance of the client options.
      * @param OptionsInterface $options Instance of the client options.
      * @param string           $id      Descriptive identifier of the cluster type (`predis`, `redis-cluster`)
      * @param string           $id      Descriptive identifier of the cluster type (`predis`, `redis-cluster`)
      *
      *
-     * @return ClusterInterface
+     * @return ClusterInterface|null
      */
      */
     protected function createByDescription(OptionsInterface $options, $id)
     protected function createByDescription(OptionsInterface $options, $id)
     {
     {
@@ -44,9 +44,9 @@ class ClusterOption implements OptionInterface
             case 'redis-cluster':
             case 'redis-cluster':
                 return new RedisCluster($options->connections);
                 return new RedisCluster($options->connections);
 
 
+            default:
+                return;
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**

+ 0 - 2
src/Configuration/Options.php

@@ -63,8 +63,6 @@ class Options implements OptionsInterface
 
 
             return $handler->getDefault($this);
             return $handler->getDefault($this);
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**

+ 2 - 2
src/Configuration/OptionsInterface.php

@@ -31,7 +31,7 @@ interface OptionsInterface
      *
      *
      * @param string $option Name of the option.
      * @param string $option Name of the option.
      *
      *
-     * @return mixed
+     * @return mixed|null
      */
      */
     public function getDefault($option);
     public function getDefault($option);
 
 
@@ -58,7 +58,7 @@ interface OptionsInterface
      *
      *
      * @param string $option Name of the option.
      * @param string $option Name of the option.
      *
      *
-     * @return mixed
+     * @return mixed|null
      */
      */
     public function __get($option);
     public function __get($option);
 }
 }

+ 1 - 5
src/Connection/Aggregate/RedisCluster.php

@@ -345,22 +345,18 @@ class RedisCluster implements ClusterInterface, IteratorAggregate, Countable
         if (isset($this->pool[$connectionID])) {
         if (isset($this->pool[$connectionID])) {
             return $this->pool[$connectionID];
             return $this->pool[$connectionID];
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**
      * Returns a random connection from the pool.
      * Returns a random connection from the pool.
      *
      *
-     * @return NodeConnectionInterface
+     * @return NodeConnectionInterface|null
      */
      */
     protected function getRandomConnection()
     protected function getRandomConnection()
     {
     {
         if ($this->pool) {
         if ($this->pool) {
             return $this->pool[array_rand($this->pool)];
             return $this->pool[array_rand($this->pool)];
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**

+ 1 - 1
src/Connection/AggregateConnectionInterface.php

@@ -51,7 +51,7 @@ interface AggregateConnectionInterface extends ConnectionInterface
      *
      *
      * @param string $connectionID Connection alias.
      * @param string $connectionID Connection alias.
      *
      *
-     * @return NodeConnectionInterface
+     * @return NodeConnectionInterface|null
      */
      */
     public function getConnectionById($connectionID);
     public function getConnectionById($connectionID);
 }
 }

+ 0 - 2
src/Connection/Parameters.php

@@ -114,8 +114,6 @@ class Parameters implements ParametersInterface
         if (isset($this->parameters[$parameter])) {
         if (isset($this->parameters[$parameter])) {
             return $this->parameters[$parameter];
             return $this->parameters[$parameter];
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**

+ 1 - 1
src/Connection/ParametersInterface.php

@@ -49,7 +49,7 @@ interface ParametersInterface
      *
      *
      * @param string $parameter Name of the parameter.
      * @param string $parameter Name of the parameter.
      *
      *
-     * @return mixed
+     * @return mixed|null
      */
      */
     public function __get($parameter);
     public function __get($parameter);
 
 

+ 2 - 2
src/Connection/PhpiredisSocketConnection.php

@@ -365,9 +365,9 @@ class PhpiredisSocketConnection extends AbstractConnection
             return phpiredis_reader_get_reply($reader);
             return phpiredis_reader_get_reply($reader);
         } else {
         } else {
             $this->onProtocolError(phpiredis_reader_get_error($reader));
             $this->onProtocolError(phpiredis_reader_get_error($reader));
-        }
 
 
-        return null;
+            return;
+        }
     }
     }
 
 
     /**
     /**

+ 2 - 2
src/Connection/PhpiredisStreamConnection.php

@@ -200,9 +200,9 @@ class PhpiredisStreamConnection extends StreamConnection
             return phpiredis_reader_get_reply($reader);
             return phpiredis_reader_get_reply($reader);
         } else {
         } else {
             $this->onProtocolError(phpiredis_reader_get_error($reader));
             $this->onProtocolError(phpiredis_reader_get_error($reader));
-        }
 
 
-        return null;
+            return;
+        }
     }
     }
 
 
     /**
     /**

+ 2 - 2
src/Connection/StreamConnection.php

@@ -239,9 +239,9 @@ class StreamConnection extends AbstractConnection
 
 
             default:
             default:
                 $this->onProtocolError("Unknown response prefix: '$prefix'.");
                 $this->onProtocolError("Unknown response prefix: '$prefix'.");
-        }
 
 
-        return null;
+                return;
+        }
     }
     }
 
 
     /**
     /**

+ 1 - 3
src/Profile/RedisProfile.php

@@ -70,15 +70,13 @@ abstract class RedisProfile implements ProfileInterface
      *
      *
      * @param string $commandID Command ID.
      * @param string $commandID Command ID.
      *
      *
-     * @return string
+     * @return string|null
      */
      */
     public function getCommandClass($commandID)
     public function getCommandClass($commandID)
     {
     {
         if (isset($this->commands[$commandID = strtoupper($commandID)])) {
         if (isset($this->commands[$commandID = strtoupper($commandID)])) {
             return $this->commands[$commandID];
             return $this->commands[$commandID];
         }
         }
-
-        return null;
     }
     }
 
 
     /**
     /**

+ 5 - 2
src/Protocol/Text/Handler/BulkResponse.php

@@ -45,7 +45,10 @@ class BulkResponse implements ResponseHandlerInterface
             return null;
             return null;
         }
         }
 
 
-        // TODO: we should probably check if < -1, just to make sure.
-        return null;
+        CommunicationException::handle(new ProtocolException(
+            $connection, "Value '$payload' is not a valid length for a bulk response."
+        ));
+
+        return;
     }
     }
 }
 }

+ 1 - 1
src/Protocol/Text/ProtocolProcessor.php

@@ -99,7 +99,7 @@ class ProtocolProcessor implements ProtocolProcessorInterface
                     $connection, "Unknown response prefix: '$prefix'."
                     $connection, "Unknown response prefix: '$prefix'."
                 ));
                 ));
 
 
-                return null;
+                return;
         }
         }
     }
     }
 
 

+ 2 - 2
src/Protocol/Text/ResponseReader.php

@@ -94,9 +94,9 @@ class ResponseReader implements ResponseReaderInterface
             $this->onProtocolError($connection, "Unknown response prefix: '$prefix'.");
             $this->onProtocolError($connection, "Unknown response prefix: '$prefix'.");
         }
         }
 
 
-        $handler = $this->handlers[$prefix];
+        $payload = $this->handlers[$prefix]->handle($connection, substr($header, 1));
 
 
-        return $handler->handle($connection, substr($header, 1));
+        return $payload;
     }
     }
 
 
     /**
     /**