Skip to content

Commit

Permalink
Minor code quality changes and upgrade composer to php 7.1 minimum
Browse files Browse the repository at this point in the history
Signed-off-by: Lasse Mammen <[email protected]>
  • Loading branch information
lkm committed Jan 21, 2019
1 parent 1a24474 commit 3893682
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": ">=5.6",
"php": ">=7.1",
"ext-curl": "*",
"ext-json" : "*",
"league/oauth2-client": "~2.3"
Expand Down
1 change: 1 addition & 0 deletions src/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function get($key);
*
* @param string $key
* @param $data
* @param int|null $ttl
* @return bool if successful
*/
public function save($key, $data, ?int $ttl = null);
Expand Down
6 changes: 1 addition & 5 deletions src/Cache/HashTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ public function hash($url, $id, array $headers)
*/
public function isCachable($url, $httpMethod)
{
if ($httpMethod === Client::HTTP_GET && $this->isInitialized()) {
return true;
}

return false;
return $httpMethod === Client::HTTP_GET && $this->isInitialized();
}

/**
Expand Down
40 changes: 31 additions & 9 deletions src/Cache/RedisCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,58 @@ public function __construct($server = 'localhost', $port = 6379, $ttl = 600, $ti
}
}

/**
* Get a cached object.
*
* @param $key
*
* @return mixed False is not found
*/
public function get($key)
{
return $this->redis !== null ? $this->redis->get($key) : false;
}

/**
* Save in cache
*
* @param string $key
* @param $data
* @param int|null $ttl
* @return bool if successful
*/
public function save($key, $data, ?int $ttl = null)
{
$ttl = $ttl ?? $this->ttl;

return $this->redis !== null ? $this->redis->setex($key, $ttl, $data) : false;
}

/**
* Delete a cached object.
*
* @param $key
*
* @return bool if successful true
*/
public function delete($key)
{
return $this->redis->delete($key) === 1;
}

/**
* @return bool
*/
public function isInitialized()
{
return $this->redis !== null;
}

protected function getSerializerValue()
{
if (defined('HHVM_VERSION')) {
return \Redis::SERIALIZER_PHP;
}
return defined('Redis::SERIALIZER_IGBINARY') ? \Redis::SERIALIZER_IGBINARY : \Redis::SERIALIZER_PHP;
}

/**
* @return bool
*/
public function isInitialized()
{
return $this->redis != null;
}
}
}
2 changes: 1 addition & 1 deletion src/Client/RequestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public function makeRequest($relativeUrl, array $variables = array(), $httpMetho
$postVariables = $variables;
}

if ($this->getCache() !== null && $this->getCache()->isCachable($queryUrl, $httpMethod) && $shouldCache) {

if ($this->getCache() != null && $this->getCache()->isCachable($queryUrl, $httpMethod) && $shouldCache) {
$result = $this->getFromCache($queryUrl);

if ($result === false) {
Expand Down

0 comments on commit 3893682

Please sign in to comment.