From f372029cfcf3cb393de4480530576da0ddd9f948 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sun, 27 Jul 2014 20:13:24 +0200 Subject: [PATCH] Fix code smells. --- bin/create-pear | 2 ++ examples/custom_cluster_distributor.php | 4 +--- src/Client.php | 2 ++ src/Cluster/ClusterStrategy.php | 12 ++++++++++++ src/Cluster/Distributor/HashRing.php | 2 ++ src/Command/Command.php | 4 ++++ src/Command/RawCommand.php | 4 ++++ src/Configuration/ClusterOption.php | 2 ++ src/Configuration/Options.php | 4 ++++ src/Connection/Aggregate/RedisCluster.php | 4 ++++ src/Connection/Parameters.php | 2 ++ src/Connection/PhpiredisSocketConnection.php | 2 ++ src/Connection/PhpiredisStreamConnection.php | 2 ++ src/Connection/StreamConnection.php | 2 ++ src/Profile/RedisProfile.php | 2 ++ src/Protocol/Text/CompositeProtocolProcessor.php | 7 +++++++ src/Protocol/Text/Handler/BulkResponse.php | 3 +++ src/Protocol/Text/ProtocolProcessor.php | 2 ++ src/Protocol/Text/ResponseReader.php | 2 ++ 19 files changed, 61 insertions(+), 3 deletions(-) diff --git a/bin/create-pear b/bin/create-pear index d4e33f9f..054dd39a 100755 --- a/bin/create-pear +++ b/bin/create-pear @@ -78,6 +78,8 @@ function parseVersion($string) 'max' => $regs[2], ); } + + return null; } function addRolePath($pkg, $path, $role) diff --git a/examples/custom_cluster_distributor.php b/examples/custom_cluster_distributor.php index 4b180684..6ec35b20 100644 --- a/examples/custom_cluster_distributor.php +++ b/examples/custom_cluster_distributor.php @@ -53,9 +53,7 @@ class NaiveDistributor implements DistributorInterface, HashGeneratorInterface public function getBySlot($slot) { - if (isset($this->nodes[$slot])) { - return $this->nodes[$slot]; - } + return isset($this->nodes[$slot]) ? $this->nodes[$slot] : null; } public function getByHash($hash) diff --git a/src/Client.php b/src/Client.php index ebe97832..ea503f1f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -484,6 +484,8 @@ class Client implements ClientInterface $pubsub->stop(); } } + + return null; } /** diff --git a/src/Cluster/ClusterStrategy.php b/src/Cluster/ClusterStrategy.php index c6d4131b..2a9c19b0 100644 --- a/src/Cluster/ClusterStrategy.php +++ b/src/Cluster/ClusterStrategy.php @@ -232,6 +232,8 @@ abstract class ClusterStrategy implements StrategyInterface if ($this->checkSameSlotForKeys($arguments)) { return $arguments[0]; } + + return null; } /** @@ -253,6 +255,8 @@ abstract class ClusterStrategy implements StrategyInterface if ($this->checkSameSlotForKeys($keys)) { return $arguments[0]; } + + return null; } /** @@ -268,6 +272,8 @@ abstract class ClusterStrategy implements StrategyInterface if ($this->checkSameSlotForKeys(array_slice($arguments, 0, count($arguments) - 1))) { return $arguments[0]; } + + return null; } /** @@ -283,6 +289,8 @@ abstract class ClusterStrategy implements StrategyInterface if ($this->checkSameSlotForKeys(array_slice($arguments, 1, count($arguments)))) { return $arguments[1]; } + + return null; } /** @@ -299,6 +307,8 @@ abstract class ClusterStrategy implements StrategyInterface if ($this->checkSameSlotForKeys($keys)) { return $arguments[0]; } + + return null; } /** @@ -318,6 +328,8 @@ abstract class ClusterStrategy implements StrategyInterface if ($keys && $this->checkSameSlotForKeys($keys)) { return $keys[0]; } + + return null; } /** diff --git a/src/Cluster/Distributor/HashRing.php b/src/Cluster/Distributor/HashRing.php index 0210f6ee..198f334a 100644 --- a/src/Cluster/Distributor/HashRing.php +++ b/src/Cluster/Distributor/HashRing.php @@ -204,6 +204,8 @@ class HashRing implements DistributorInterface, HashGeneratorInterface if (isset($this->ring[$slot])) { return $this->ring[$slot]; } + + return null; } /** diff --git a/src/Command/Command.php b/src/Command/Command.php index d8dee427..b36343d1 100644 --- a/src/Command/Command.php +++ b/src/Command/Command.php @@ -66,6 +66,8 @@ abstract class Command implements CommandInterface if (isset($this->arguments[$index])) { return $this->arguments[$index]; } + + return null; } /** @@ -84,6 +86,8 @@ abstract class Command implements CommandInterface if (isset($this->slot)) { return $this->slot; } + + return null; } /** diff --git a/src/Command/RawCommand.php b/src/Command/RawCommand.php index b8c546e0..0fbb8d07 100644 --- a/src/Command/RawCommand.php +++ b/src/Command/RawCommand.php @@ -97,6 +97,8 @@ class RawCommand implements CommandInterface if (isset($this->arguments[$index])) { return $this->arguments[$index]; } + + return null; } /** @@ -115,6 +117,8 @@ class RawCommand implements CommandInterface if (isset($this->slot)) { return $this->slot; } + + return null; } /** diff --git a/src/Configuration/ClusterOption.php b/src/Configuration/ClusterOption.php index ebc1e0c1..415b4132 100644 --- a/src/Configuration/ClusterOption.php +++ b/src/Configuration/ClusterOption.php @@ -44,6 +44,8 @@ class ClusterOption implements OptionInterface return new RedisCluster($options->connections); } + + return null; } /** diff --git a/src/Configuration/Options.php b/src/Configuration/Options.php index 9108d862..04556258 100644 --- a/src/Configuration/Options.php +++ b/src/Configuration/Options.php @@ -63,6 +63,8 @@ class Options implements OptionsInterface return $handler->getDefault($this); } + + return null; } /** @@ -116,5 +118,7 @@ class Options implements OptionsInterface if (isset($this->handlers[$option])) { return $this->options[$option] = $this->getDefault($option); } + + return null; } } diff --git a/src/Connection/Aggregate/RedisCluster.php b/src/Connection/Aggregate/RedisCluster.php index a0b101d4..849263cc 100644 --- a/src/Connection/Aggregate/RedisCluster.php +++ b/src/Connection/Aggregate/RedisCluster.php @@ -341,6 +341,8 @@ class RedisCluster implements ClusterInterface, IteratorAggregate, Countable if (isset($this->pool[$connectionID])) { return $this->pool[$connectionID]; } + + return null; } /** @@ -353,6 +355,8 @@ class RedisCluster implements ClusterInterface, IteratorAggregate, Countable if ($this->pool) { return $this->pool[array_rand($this->pool)]; } + + return null; } /** diff --git a/src/Connection/Parameters.php b/src/Connection/Parameters.php index 737936e0..fa30a388 100644 --- a/src/Connection/Parameters.php +++ b/src/Connection/Parameters.php @@ -111,6 +111,8 @@ class Parameters implements ParametersInterface if (isset($this->parameters[$parameter])) { return $this->parameters[$parameter]; } + + return null; } /** diff --git a/src/Connection/PhpiredisSocketConnection.php b/src/Connection/PhpiredisSocketConnection.php index c3f4acd4..b6f3443e 100644 --- a/src/Connection/PhpiredisSocketConnection.php +++ b/src/Connection/PhpiredisSocketConnection.php @@ -364,6 +364,8 @@ class PhpiredisSocketConnection extends AbstractConnection } else { $this->onProtocolError(phpiredis_reader_get_error($reader)); } + + return null; } /** diff --git a/src/Connection/PhpiredisStreamConnection.php b/src/Connection/PhpiredisStreamConnection.php index 406601a9..692e31fe 100644 --- a/src/Connection/PhpiredisStreamConnection.php +++ b/src/Connection/PhpiredisStreamConnection.php @@ -201,6 +201,8 @@ class PhpiredisStreamConnection extends StreamConnection } else { $this->onProtocolError(phpiredis_reader_get_error($reader)); } + + return null; } /** diff --git a/src/Connection/StreamConnection.php b/src/Connection/StreamConnection.php index 5ae702c6..dc779d6e 100644 --- a/src/Connection/StreamConnection.php +++ b/src/Connection/StreamConnection.php @@ -238,6 +238,8 @@ class StreamConnection extends AbstractConnection default: $this->onProtocolError("Unknown response prefix: '$prefix'."); } + + return null; } /** diff --git a/src/Profile/RedisProfile.php b/src/Profile/RedisProfile.php index 456952f4..59a4744a 100644 --- a/src/Profile/RedisProfile.php +++ b/src/Profile/RedisProfile.php @@ -76,6 +76,8 @@ abstract class RedisProfile implements ProfileInterface if (isset($this->commands[$commandID = strtoupper($commandID)])) { return $this->commands[$commandID]; } + + return null; } /** diff --git a/src/Protocol/Text/CompositeProtocolProcessor.php b/src/Protocol/Text/CompositeProtocolProcessor.php index 269d2176..01ab3831 100644 --- a/src/Protocol/Text/CompositeProtocolProcessor.php +++ b/src/Protocol/Text/CompositeProtocolProcessor.php @@ -26,7 +26,14 @@ use Predis\Protocol\ResponseReaderInterface; */ class CompositeProtocolProcessor implements ProtocolProcessorInterface { + /* + * @var RequestSerializerInterface + */ protected $serializer; + + /* + * @var ResponseReaderInterface + */ protected $reader; /** diff --git a/src/Protocol/Text/Handler/BulkResponse.php b/src/Protocol/Text/Handler/BulkResponse.php index 410ded19..708573e7 100644 --- a/src/Protocol/Text/Handler/BulkResponse.php +++ b/src/Protocol/Text/Handler/BulkResponse.php @@ -44,5 +44,8 @@ class BulkResponse implements ResponseHandlerInterface if ($length == -1) { return null; } + + // TODO: we should probably check if < -1, just to make sure. + return null; } } diff --git a/src/Protocol/Text/ProtocolProcessor.php b/src/Protocol/Text/ProtocolProcessor.php index d59d0122..99af643c 100644 --- a/src/Protocol/Text/ProtocolProcessor.php +++ b/src/Protocol/Text/ProtocolProcessor.php @@ -98,6 +98,8 @@ class ProtocolProcessor implements ProtocolProcessorInterface CommunicationException::handle(new ProtocolException( $connection, "Unknown response prefix: '$prefix'." )); + + return null; } } diff --git a/src/Protocol/Text/ResponseReader.php b/src/Protocol/Text/ResponseReader.php index 90785e37..51264381 100644 --- a/src/Protocol/Text/ResponseReader.php +++ b/src/Protocol/Text/ResponseReader.php @@ -72,6 +72,8 @@ class ResponseReader implements ResponseReaderInterface if (isset($this->handlers[$prefix])) { return $this->handlers[$prefix]; } + + return null; } /**