From c3cafaa9a6c021cbf903ab955aee24c2a510b68e Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Wed, 25 Jul 2012 21:18:58 +0200 Subject: [PATCH] Remove useless helpers. --- lib/Predis/Client.php | 8 +++++--- lib/Predis/Helpers.php | 22 --------------------- lib/Predis/Monitor/MonitorContext.php | 4 ++-- lib/Predis/PubSub/PubSubContext.php | 3 ++- lib/Predis/Transaction/MultiExecContext.php | 16 +++++++-------- tests/Predis/HelpersTest.php | 12 ----------- 6 files changed, 17 insertions(+), 48 deletions(-) diff --git a/lib/Predis/Client.php b/lib/Predis/Client.php index 7d292826..6d850905 100644 --- a/lib/Predis/Client.php +++ b/lib/Predis/Client.php @@ -14,6 +14,7 @@ namespace Predis; use Predis\Command\CommandInterface; use Predis\Option\ClientOptionsInterface; use Predis\Connection\ConnectionInterface; +use Predis\Connection\AggregatedConnectionInterface; use Predis\Profile\ServerProfileInterface; use Predis\Option\ClientOptions; use Predis\Profile\ServerProfile; @@ -187,9 +188,10 @@ class Client implements ClientInterface public function getConnection($id = null) { if (isset($id)) { - if (!Helpers::isAggregated($this->connection)) { - $message = 'Retrieving connections by alias is supported only with aggregated connections (cluster or replication)'; - throw new NotSupportedException($message); + if (!$this->connection instanceof AggregatedConnectionInterface) { + throw new NotSupportedException( + 'Retrieving connections by alias is supported only with aggregated connections (cluster or replication)' + ); } return $this->connection->getConnectionById($id); } diff --git a/lib/Predis/Helpers.php b/lib/Predis/Helpers.php index c9be0e6b..65cbfb8a 100644 --- a/lib/Predis/Helpers.php +++ b/lib/Predis/Helpers.php @@ -22,28 +22,6 @@ use Predis\Connection\AggregatedConnectionInterface; */ class Helpers { - /** - * Checks if the specified connection represents an aggregation of connections. - * - * @param ConnectionInterface $connection Connection object. - * @return Boolean - */ - public static function isAggregated(ConnectionInterface $connection) - { - return $connection instanceof AggregatedConnectionInterface; - } - - /** - * Checks if the specified connection represents a cluster. - * - * @param ConnectionInterface $connection Connection object. - * @return Boolean - */ - public static function isCluster(ConnectionInterface $connection) - { - return $connection instanceof ClusterConnectionInterface; - } - /** * Offers a generic and reusable method to handle exceptions generated by * a connection object. diff --git a/lib/Predis/Monitor/MonitorContext.php b/lib/Predis/Monitor/MonitorContext.php index 438214ca..0cd40104 100644 --- a/lib/Predis/Monitor/MonitorContext.php +++ b/lib/Predis/Monitor/MonitorContext.php @@ -12,8 +12,8 @@ namespace Predis\Monitor; use Predis\ClientInterface; -use Predis\Helpers; use Predis\NotSupportedException; +use Predis\Connection\AggregatedConnectionInterface; /** * Client-side abstraction of a Redis MONITOR context. @@ -52,7 +52,7 @@ class MonitorContext implements \Iterator */ private function checkCapabilities(ClientInterface $client) { - if (Helpers::isCluster($client->getConnection())) { + if ($client->getConnection() instanceof AggregatedConnectionInterface) { throw new NotSupportedException('Cannot initialize a monitor context over a cluster of connections'); } diff --git a/lib/Predis/PubSub/PubSubContext.php b/lib/Predis/PubSub/PubSubContext.php index 55c091d2..fe84bb8c 100644 --- a/lib/Predis/PubSub/PubSubContext.php +++ b/lib/Predis/PubSub/PubSubContext.php @@ -15,6 +15,7 @@ use Predis\ClientInterface; use Predis\Helpers; use Predis\ClientException; use Predis\NotSupportedException; +use Predis\Connection\AggregatedConnectionInterface; /** * Client-side abstraction of a Publish / Subscribe context. @@ -48,7 +49,7 @@ class PubSubContext extends AbstractPubSubContext */ private function checkCapabilities(ClientInterface $client) { - if (Helpers::isCluster($client->getConnection())) { + if ($client->getConnection() instanceof AggregatedConnectionInterface) { throw new NotSupportedException('Cannot initialize a PUB/SUB context over a cluster of connections'); } diff --git a/lib/Predis/Transaction/MultiExecContext.php b/lib/Predis/Transaction/MultiExecContext.php index df8db57f..e428c960 100644 --- a/lib/Predis/Transaction/MultiExecContext.php +++ b/lib/Predis/Transaction/MultiExecContext.php @@ -17,7 +17,7 @@ use Predis\BasicClientInterface; use Predis\ExecutableContextInterface; use Predis\ResponseErrorInterface; use Predis\Command\CommandInterface; -use Predis\Helpers; +use Predis\Connection\AggregatedConnectionInterface; use Predis\ResponseQueued; use Predis\ClientException; use Predis\ServerException; @@ -32,12 +32,12 @@ use Predis\Protocol\ProtocolException; */ class MultiExecContext implements BasicClientInterface, ExecutableContextInterface { - const STATE_RESET = 0; // 0b00000 - const STATE_INITIALIZED = 1; // 0b00001 - const STATE_INSIDEBLOCK = 2; // 0b00010 - const STATE_DISCARDED = 4; // 0b00100 - const STATE_CAS = 8; // 0b01000 - const STATE_WATCH = 16; // 0b10000 + const STATE_RESET = 0; // 0b00000 + const STATE_INITIALIZED = 1; // 0b00001 + const STATE_INSIDEBLOCK = 2; // 0b00010 + const STATE_DISCARDED = 4; // 0b00100 + const STATE_CAS = 8; // 0b01000 + const STATE_WATCH = 16; // 0b10000 private $state; private $canWatch; @@ -117,7 +117,7 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa */ private function checkCapabilities(ClientInterface $client) { - if (Helpers::isCluster($client->getConnection())) { + if ($client->getConnection() instanceof AggregatedConnectionInterface) { throw new NotSupportedException('Cannot initialize a MULTI/EXEC context over a cluster of connections'); } diff --git a/tests/Predis/HelpersTest.php b/tests/Predis/HelpersTest.php index db5a131d..dbceb67e 100644 --- a/tests/Predis/HelpersTest.php +++ b/tests/Predis/HelpersTest.php @@ -18,18 +18,6 @@ use \PHPUnit_Framework_TestCase as StandardTestCase; */ class HelpersTest extends StandardTestCase { - /** - * @group disconnected - */ - public function testConnectionIsCluster() - { - $single = $this->getMock('Predis\Connection\SingleConnectionInterface'); - $cluster = $this->getMock('Predis\Connection\ClusterConnectionInterface'); - - $this->assertFalse(Helpers::isCluster($single)); - $this->assertTrue(Helpers::isCluster($cluster)); - } - /** * @group disconnected */