Skip to content

[Cache] Allow covariant returns and optimize code #4635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions system/Cache/Handlers/DummyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class DummyHandler extends BaseHandler
*/
public function initialize()
{
// Nothing to see here...
}

//--------------------------------------------------------------------
Expand All @@ -33,7 +32,7 @@ public function initialize()
*
* @param string $key Cache item name
*
* @return mixed
* @return null
*/
public function get(string $key)
{
Expand All @@ -49,7 +48,7 @@ public function get(string $key)
* @param integer $ttl Time to live
* @param Closure $callback Callback return value
*
* @return mixed
* @return null
*/
public function remember(string $key, int $ttl, Closure $callback)
{
Expand Down Expand Up @@ -108,7 +107,7 @@ public function deleteMatching(string $pattern)
* @param string $key Cache ID
* @param integer $offset Step/value to increase by
*
* @return mixed
* @return boolean
*/
public function increment(string $key, int $offset = 1)
{
Expand All @@ -123,7 +122,7 @@ public function increment(string $key, int $offset = 1)
* @param string $key Cache ID
* @param integer $offset Step/value to increase by
*
* @return mixed
* @return boolean
*/
public function decrement(string $key, int $offset = 1)
{
Expand All @@ -150,7 +149,7 @@ public function clean()
* The information returned and the structure of the data
* varies depending on the handler.
*
* @return mixed
* @return null
*/
public function getCacheInfo()
{
Expand All @@ -164,7 +163,7 @@ public function getCacheInfo()
*
* @param string $key Cache item name.
*
* @return mixed
* @return null
*/
public function getMetaData(string $key)
{
Expand All @@ -182,6 +181,4 @@ public function isSupported(): bool
{
return true;
}

//--------------------------------------------------------------------
}
15 changes: 7 additions & 8 deletions system/Cache/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct(Cache $config)
}

$this->mode = $config->file['mode'] ?? 0640;
$this->prefix = (string) $config->prefix;
$this->prefix = $config->prefix;
}

//--------------------------------------------------------------------
Expand All @@ -81,7 +81,6 @@ public function __construct(Cache $config)
*/
public function initialize()
{
// Not to see here...
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -190,7 +189,7 @@ public function deleteMatching(string $pattern)
* @param string $key Cache ID
* @param integer $offset Step/value to increase by
*
* @return mixed
* @return boolean
*/
public function increment(string $key, int $offset = 1)
{
Expand Down Expand Up @@ -223,7 +222,7 @@ public function increment(string $key, int $offset = 1)
* @param string $key Cache ID
* @param integer $offset Step/value to increase by
*
* @return mixed
* @return bool
*/
public function decrement(string $key, int $offset = 1)
{
Expand Down Expand Up @@ -268,7 +267,7 @@ public function clean()
* The information returned and the structure of the data
* varies depending on the handler.
*
* @return mixed
* @return array|false
*/
public function getCacheInfo()
{
Expand Down Expand Up @@ -534,6 +533,8 @@ protected function getFileInfo(string $file, $returnedValues = ['name', 'server_
$returnedValues = explode(',', $returnedValues);
}

$fileInfo = [];

foreach ($returnedValues as $key)
{
switch ($key)
Expand Down Expand Up @@ -565,8 +566,6 @@ protected function getFileInfo(string $file, $returnedValues = ['name', 'server_
}
}

return $fileInfo; // @phpstan-ignore-line
return $fileInfo;
}

//--------------------------------------------------------------------
}
10 changes: 5 additions & 5 deletions system/Cache/Handlers/MemcachedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MemcachedHandler extends BaseHandler
*/
public function __construct(Cache $config)
{
$this->prefix = (string) $config->prefix;
$this->prefix = $config->prefix;

if (! empty($config))
{
Expand Down Expand Up @@ -269,7 +269,7 @@ public function deleteMatching(string $pattern)
* @param string $key Cache ID
* @param integer $offset Step/value to increase by
*
* @return mixed
* @return integer|false
*/
public function increment(string $key, int $offset = 1)
{
Expand All @@ -292,7 +292,7 @@ public function increment(string $key, int $offset = 1)
* @param string $key Cache ID
* @param integer $offset Step/value to increase by
*
* @return mixed
* @return integer|false
*/
public function decrement(string $key, int $offset = 1)
{
Expand Down Expand Up @@ -328,7 +328,7 @@ public function clean()
* The information returned and the structure of the data
* varies depending on the handler.
*
* @return mixed
* @return array|false
*/
public function getCacheInfo()
{
Expand Down Expand Up @@ -380,6 +380,6 @@ public function getMetaData(string $key)
*/
public function isSupported(): bool
{
return (extension_loaded('memcached') || extension_loaded('memcache'));
return extension_loaded('memcached') || extension_loaded('memcache');
}
}
18 changes: 8 additions & 10 deletions system/Cache/Handlers/PredisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class PredisHandler extends BaseHandler
*/
public function __construct(Cache $config)
{
$this->prefix = (string) $config->prefix;
$this->prefix = $config->prefix;

if (isset($config->redis))
{
Expand Down Expand Up @@ -101,10 +101,9 @@ public function initialize()
*/
public function get(string $key)
{
$data = array_combine([
'__ci_type',
'__ci_value',
], $this->redis->hmget($key, ['__ci_type', '__ci_value'])
$data = array_combine(
['__ci_type', '__ci_value'],
$this->redis->hmget($key, ['__ci_type', '__ci_value'])
);

if (! isset($data['__ci_type'], $data['__ci_value']) || $data['__ci_value'] === false)
Expand Down Expand Up @@ -180,7 +179,7 @@ public function save(string $key, $value, int $ttl = 60)
*/
public function delete(string $key)
{
return ($this->redis->del($key) === 1);
return $this->redis->del($key) === 1;
}

//--------------------------------------------------------------------
Expand All @@ -194,7 +193,6 @@ public function delete(string $key)
*/
public function deleteMatching(string $pattern)
{
$deleted = 0;
$matchedKeys = [];

foreach (new Keyspace($this->redis, $pattern) as $key)
Expand All @@ -213,7 +211,7 @@ public function deleteMatching(string $pattern)
* @param string $key Cache ID
* @param integer $offset Step/value to increase by
*
* @return mixed
* @return integer
*/
public function increment(string $key, int $offset = 1)
{
Expand All @@ -228,7 +226,7 @@ public function increment(string $key, int $offset = 1)
* @param string $key Cache ID
* @param integer $offset Step/value to increase by
*
* @return mixed
* @return integer
*/
public function decrement(string $key, int $offset = 1)
{
Expand All @@ -255,7 +253,7 @@ public function clean()
* The information returned and the structure of the data
* varies depending on the handler.
*
* @return mixed
* @return array
*/
public function getCacheInfo()
{
Expand Down
14 changes: 6 additions & 8 deletions system/Cache/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class RedisHandler extends BaseHandler
*/
public function __construct(Cache $config)
{
$this->prefix = (string) $config->prefix;
$this->prefix = $config->prefix;

if (! empty($config))
{
Expand All @@ -72,7 +72,7 @@ public function __construct(Cache $config)
*/
public function __destruct()
{
if ($this->redis) // @phpstan-ignore-line
if (isset($this->redis))
{
$this->redis->close();
}
Expand Down Expand Up @@ -218,7 +218,7 @@ public function delete(string $key)
{
$key = $this->prefix . $key;

return ($this->redis->del($key) === 1);
return $this->redis->del($key) === 1;
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -262,7 +262,7 @@ public function deleteMatching(string $pattern)
* @param string $key Cache ID
* @param integer $offset Step/value to increase by
*
* @return mixed
* @return integer
*/
public function increment(string $key, int $offset = 1)
{
Expand All @@ -279,7 +279,7 @@ public function increment(string $key, int $offset = 1)
* @param string $key Cache ID
* @param integer $offset Step/value to increase by
*
* @return mixed
* @return integer
*/
public function decrement(string $key, int $offset = 1)
{
Expand Down Expand Up @@ -308,7 +308,7 @@ public function clean()
* The information returned and the structure of the data
* varies depending on the handler.
*
* @return mixed
* @return array
*/
public function getCacheInfo()
{
Expand Down Expand Up @@ -358,6 +358,4 @@ public function isSupported(): bool
{
return extension_loaded('redis');
}

//--------------------------------------------------------------------
}
Loading