Browse Source

Fix code smells.

Daniele Alessandri 10 năm trước cách đây
mục cha
commit
f372029cfc

+ 2 - 0
bin/create-pear

@@ -78,6 +78,8 @@ function parseVersion($string)
             'max' => $regs[2],
         );
     }
+
+    return null;
 }
 
 function addRolePath($pkg, $path, $role)

+ 1 - 3
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)

+ 2 - 0
src/Client.php

@@ -484,6 +484,8 @@ class Client implements ClientInterface
                 $pubsub->stop();
             }
         }
+
+        return null;
     }
 
     /**

+ 12 - 0
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;
     }
 
     /**

+ 2 - 0
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;
     }
 
     /**

+ 4 - 0
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;
     }
 
     /**

+ 4 - 0
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;
     }
 
     /**

+ 2 - 0
src/Configuration/ClusterOption.php

@@ -44,6 +44,8 @@ class ClusterOption implements OptionInterface
                 return new RedisCluster($options->connections);
 
         }
+
+        return null;
     }
 
     /**

+ 4 - 0
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;
     }
 }

+ 4 - 0
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;
     }
 
     /**

+ 2 - 0
src/Connection/Parameters.php

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

+ 2 - 0
src/Connection/PhpiredisSocketConnection.php

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

+ 2 - 0
src/Connection/PhpiredisStreamConnection.php

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

+ 2 - 0
src/Connection/StreamConnection.php

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

+ 2 - 0
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;
     }
 
     /**

+ 7 - 0
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;
 
     /**

+ 3 - 0
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;
     }
 }

+ 2 - 0
src/Protocol/Text/ProtocolProcessor.php

@@ -98,6 +98,8 @@ class ProtocolProcessor implements ProtocolProcessorInterface
                 CommunicationException::handle(new ProtocolException(
                     $connection, "Unknown response prefix: '$prefix'."
                 ));
+
+                return null;
         }
     }
 

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

@@ -72,6 +72,8 @@ class ResponseReader implements ResponseReaderInterface
         if (isset($this->handlers[$prefix])) {
             return $this->handlers[$prefix];
         }
+
+        return null;
     }
 
     /**