Skip to content

Commit

Permalink
added phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
mp3000mp committed Oct 12, 2020
1 parent b241046 commit 60b9956
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ before_script:
script:
- composer install
- composer run cs
- composer run ps
- composer run tuc

after_success:
Expand Down
22 changes: 14 additions & 8 deletions src/RedisClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@ class RedisClient
*/
private $client;

/**
* @var string
*/
private $host;

/**
* @var int
*/
private $port;

/**
* @var string|null
*/
private $auth;

/**
Expand All @@ -30,9 +39,11 @@ class RedisClient
public function __construct(string $host = 'localhost', int $port = 6379, ?string $auth = null)
{
// test extension
// @codeCoverageIgnoreStart
if (!extension_loaded('redis')) {
throw new RedisClientException('Redis extension missing', 1000);
}
// @codeCoverageIgnoreEnd

$this->host = $host;
$this->port = $port;
Expand All @@ -45,21 +56,16 @@ public function __construct(string $host = 'localhost', int $port = 6379, ?strin
/**
* @throws RedisClientException
*/
private function tryConnect()
private function tryConnect(): void
{
if (!$this->client->isConnected()) {
try {
$this->client->connect($this->host, $this->port);
} catch (\RedisException $e) {
throw new RedisClientException($e->getMessage(), 2001);
}
if (null !== $this->auth) {
$this->client->auth($this->auth);
}

// test connection
if (!$this->client->isConnected()) {
throw new RedisClientException('Connection failed', 2002);
if (null !== $this->auth && !$this->client->auth($this->auth)) {
throw new RedisClientException('Connection auth failed', 2002);
}
}
}
Expand Down

0 comments on commit 60b9956

Please sign in to comment.