From cf70d2f20e96c87c03ca7b3caa3f6fdb9c7f478d Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Mon, 2 Dec 2013 15:56:53 +0100 Subject: [PATCH] Minor code styling changes in Predis\Connection. --- lib/Predis/Connection/AbstractConnection.php | 12 ++++++++++-- lib/Predis/Connection/ConnectionFactory.php | 12 +++++++----- lib/Predis/Connection/MasterSlaveReplication.php | 6 ++++-- lib/Predis/Connection/PredisCluster.php | 6 ++++-- lib/Predis/Connection/RedisCluster.php | 6 ++++-- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/lib/Predis/Connection/AbstractConnection.php b/lib/Predis/Connection/AbstractConnection.php index f857be7e..ed2f0805 100644 --- a/lib/Predis/Connection/AbstractConnection.php +++ b/lib/Predis/Connection/AbstractConnection.php @@ -136,7 +136,11 @@ abstract class AbstractConnection implements SingleConnectionInterface */ protected function onConnectionError($message, $code = null) { - CommunicationException::handle(new ConnectionException($this, "$message [{$this->parameters->scheme}://{$this->getIdentifier()}]", $code)); + CommunicationException::handle( + new ConnectionException( + $this, "$message [{$this->parameters->scheme}://{$this->getIdentifier()}]", $code + ) + ); } /** @@ -146,7 +150,11 @@ abstract class AbstractConnection implements SingleConnectionInterface */ protected function onProtocolError($message) { - CommunicationException::handle(new ProtocolException($this, "$message [{$this->parameters->scheme}://{$this->getIdentifier()}]")); + CommunicationException::handle( + new ProtocolException( + $this, "$message [{$this->parameters->scheme}://{$this->getIdentifier()}]" + ) + ); } /** diff --git a/lib/Predis/Connection/ConnectionFactory.php b/lib/Predis/Connection/ConnectionFactory.php index 5f1b1734..a874a8be 100644 --- a/lib/Predis/Connection/ConnectionFactory.php +++ b/lib/Predis/Connection/ConnectionFactory.php @@ -11,6 +11,8 @@ namespace Predis\Connection; +use InvalidArgumentException; +use ReflectionClass; use Predis\Command; /** @@ -41,10 +43,10 @@ class ConnectionFactory implements ConnectionFactoryInterface return $initializer; } - $initializerReflection = new \ReflectionClass($initializer); + $class = new ReflectionClass($initializer); - if (!$initializerReflection->isSubclassOf('Predis\Connection\SingleConnectionInterface')) { - throw new \InvalidArgumentException( + if (!$class->isSubclassOf('Predis\Connection\SingleConnectionInterface')) { + throw new InvalidArgumentException( 'A connection initializer must be a valid connection class or a callable object' ); } @@ -80,7 +82,7 @@ class ConnectionFactory implements ConnectionFactoryInterface $scheme = $parameters->scheme; if (!isset($this->schemes[$scheme])) { - throw new \InvalidArgumentException("Unknown connection scheme: $scheme"); + throw new InvalidArgumentException("Unknown connection scheme: $scheme"); } $initializer = $this->schemes[$scheme]; @@ -93,7 +95,7 @@ class ConnectionFactory implements ConnectionFactoryInterface } if (!$connection instanceof SingleConnectionInterface) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Objects returned by connection initializers must implement ' . 'Predis\Connection\SingleConnectionInterface' ); diff --git a/lib/Predis/Connection/MasterSlaveReplication.php b/lib/Predis/Connection/MasterSlaveReplication.php index 804ffc6f..24aac493 100644 --- a/lib/Predis/Connection/MasterSlaveReplication.php +++ b/lib/Predis/Connection/MasterSlaveReplication.php @@ -11,6 +11,8 @@ namespace Predis\Connection; +use InvalidArgumentException; +use RuntimeException; use Predis\Command\CommandInterface; use Predis\Replication\ReplicationStrategy; @@ -42,7 +44,7 @@ class MasterSlaveReplication implements ReplicationConnectionInterface protected function check() { if (!isset($this->master) || !$this->slaves) { - throw new \RuntimeException('Replication needs a master and at least one slave.'); + throw new RuntimeException('Replication needs a master and at least one slave.'); } } @@ -142,7 +144,7 @@ class MasterSlaveReplication implements ReplicationConnectionInterface $connection = $this->getConnectionById($connection); } if ($connection !== $this->master && !in_array($connection, $this->slaves, true)) { - throw new \InvalidArgumentException('The specified connection is not valid.'); + throw new InvalidArgumentException('The specified connection is not valid.'); } $this->current = $connection; diff --git a/lib/Predis/Connection/PredisCluster.php b/lib/Predis/Connection/PredisCluster.php index aeefb29f..73dd6e6b 100644 --- a/lib/Predis/Connection/PredisCluster.php +++ b/lib/Predis/Connection/PredisCluster.php @@ -32,7 +32,7 @@ class PredisCluster implements ClusterConnectionInterface, IteratorAggregate, Co private $distributor; /** - * @param Distributor\DistributorInterface $distributor Distribution strategy used by the cluster. + * @param Distributor\DistributorInterface $distributor Distribution strategy used by cluster. */ public function __construct(Distributor\DistributorInterface $distributor = null) { @@ -132,7 +132,9 @@ class PredisCluster implements ClusterConnectionInterface, IteratorAggregate, Co $hash = $this->strategy->getHash($command); if (!isset($hash)) { - throw new NotSupportedException("Cannot use {$command->getId()} with a cluster of connections"); + throw new NotSupportedException( + "Cannot use {$command->getId()} with a cluster of connections" + ); } $node = $this->distributor->get($hash); diff --git a/lib/Predis/Connection/RedisCluster.php b/lib/Predis/Connection/RedisCluster.php index 5cef6316..6cc08bca 100644 --- a/lib/Predis/Connection/RedisCluster.php +++ b/lib/Predis/Connection/RedisCluster.php @@ -11,6 +11,8 @@ namespace Predis\Connection; +use ArrayIterator; +use OutOfBoundsException; use Predis\ClientException; use Predis\NotSupportedException; use Predis\Cluster; @@ -178,7 +180,7 @@ class RedisCluster implements ClusterConnectionInterface, \IteratorAggregate, \C public function setSlots($first, $last, $connection) { if ($first < 0x0000 || $first > 0x3FFF || $last < 0x0000 || $last > 0x3FFF || $last < $first) { - throw new \OutOfBoundsException("Invalid slot values for $connection: [$first-$last]"); + throw new OutOfBoundsException("Invalid slot values for $connection: [$first-$last]"); } $this->slotsMap = $this->getSlotsMap() + array_fill($first, $last - $first + 1, (string) $connection); @@ -325,7 +327,7 @@ class RedisCluster implements ClusterConnectionInterface, \IteratorAggregate, \C */ public function getIterator() { - return new \ArrayIterator(array_values($this->pool)); + return new ArrayIterator(array_values($this->pool)); } /**