diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2018-01-16 20:44:51 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2018-01-16 21:58:20 +0100 |
commit | c5fcfb070991c94631a89480f66c97a1d18721d0 (patch) | |
tree | 7f4ca7f046cf99b3acfff9223b86735968461bac | |
parent | 2b70c708abc667c3e3c4fd9a97626012bf1ded25 (diff) | |
download | nextcloud-server-c5fcfb070991c94631a89480f66c97a1d18721d0.tar.gz nextcloud-server-c5fcfb070991c94631a89480f66c97a1d18721d0.zip |
Made the cache factory strict
* Return types
* Typehints
* made strict
* fix tests
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
-rw-r--r-- | lib/private/Memcache/Factory.php | 33 | ||||
-rw-r--r-- | lib/public/ICacheFactory.php | 19 | ||||
-rw-r--r-- | tests/lib/Memcache/FactoryTest.php | 9 |
3 files changed, 33 insertions, 28 deletions
diff --git a/lib/private/Memcache/Factory.php b/lib/private/Memcache/Factory.php index ff539e55420..b79f17ba8ea 100644 --- a/lib/private/Memcache/Factory.php +++ b/lib/private/Memcache/Factory.php @@ -31,8 +31,10 @@ namespace OC\Memcache; -use \OCP\ICacheFactory; -use \OCP\ILogger; +use OCP\ICache; +use OCP\ICacheFactory; +use OCP\ILogger; +use OCP\IMemcache; class Factory implements ICacheFactory { const NULL_CACHE = '\\OC\\Memcache\\NullCache'; @@ -69,7 +71,7 @@ class Factory implements ICacheFactory { * @param string|null $distributedCacheClass * @param string|null $lockingCacheClass */ - public function __construct($globalPrefix, ILogger $logger, + public function __construct(string $globalPrefix, ILogger $logger, $localCacheClass = null, $distributedCacheClass = null, $lockingCacheClass = null) { $this->logger = $logger; @@ -128,9 +130,9 @@ class Factory implements ICacheFactory { * create a cache instance for storing locks * * @param string $prefix - * @return \OCP\IMemcache + * @return IMemcache */ - public function createLocking($prefix = '') { + public function createLocking(string $prefix = ''): IMemcache { return new $this->lockingCacheClass($this->globalPrefix . '/' . $prefix); } @@ -138,9 +140,9 @@ class Factory implements ICacheFactory { * create a distributed cache instance * * @param string $prefix - * @return \OC\Memcache\Cache + * @return ICache */ - public function createDistributed($prefix = '') { + public function createDistributed(string $prefix = ''): ICache { return new $this->distributedCacheClass($this->globalPrefix . '/' . $prefix); } @@ -148,18 +150,19 @@ class Factory implements ICacheFactory { * create a local cache instance * * @param string $prefix - * @return \OC\Memcache\Cache + * @return ICache */ - public function createLocal($prefix = '') { + public function createLocal(string $prefix = ''): ICache { return new $this->localCacheClass($this->globalPrefix . '/' . $prefix); } /** * @see \OC\Memcache\Factory::createDistributed() * @param string $prefix - * @return \OC\Memcache\Cache + * @return ICache + * @deprecated 13.0.0 Use either createLocking, createDistributed or createLocal */ - public function create($prefix = '') { + public function create(string $prefix = ''): ICache { return $this->createDistributed($prefix); } @@ -168,16 +171,16 @@ class Factory implements ICacheFactory { * * @return bool */ - public function isAvailable() { + public function isAvailable(): bool { return ($this->distributedCacheClass !== self::NULL_CACHE); } /** * @see \OC\Memcache\Factory::createLocal() * @param string $prefix - * @return Cache + * @return ICache */ - public function createLowLatency($prefix = '') { + public function createLowLatency(string $prefix = ''): ICache { return $this->createLocal($prefix); } @@ -186,7 +189,7 @@ class Factory implements ICacheFactory { * * @return bool */ - public function isAvailableLowLatency() { + public function isAvailableLowLatency(): bool { return ($this->localCacheClass !== self::NULL_CACHE); } } diff --git a/lib/public/ICacheFactory.php b/lib/public/ICacheFactory.php index cc4d8fa3ec3..76145fe1f78 100644 --- a/lib/public/ICacheFactory.php +++ b/lib/public/ICacheFactory.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); /** * @copyright Copyright (c) 2016, ownCloud, Inc. * @@ -36,11 +37,11 @@ interface ICacheFactory{ * All entries added trough the cache instance will be namespaced by $prefix to prevent collisions between apps * * @param string $prefix - * @return \OCP\ICache + * @return ICache * @since 7.0.0 * @deprecated 13.0.0 Use either createLocking, createDistributed or createLocal */ - public function create($prefix = ''); + public function create(string $prefix = ''): ICache; /** * Check if any memory cache backend is available @@ -48,32 +49,32 @@ interface ICacheFactory{ * @return bool * @since 7.0.0 */ - public function isAvailable(); + public function isAvailable(): bool; /** * create a cache instance for storing locks * * @param string $prefix - * @return \OCP\IMemcache + * @return IMemcache * @since 13.0.0 */ - public function createLocking($prefix = ''); + public function createLocking(string $prefix = ''): IMemcache; /** * create a distributed cache instance * * @param string $prefix - * @return \OCP\ICache + * @return ICache * @since 13.0.0 */ - public function createDistributed($prefix = ''); + public function createDistributed(string $prefix = ''): ICache; /** * create a local cache instance * * @param string $prefix - * @return \OCP\ICache + * @return ICache * @since 13.0.0 */ - public function createLocal($prefix = ''); + public function createLocal(string $prefix = ''): ICache; } diff --git a/tests/lib/Memcache/FactoryTest.php b/tests/lib/Memcache/FactoryTest.php index ce6c25cd87f..1944b1bd35d 100644 --- a/tests/lib/Memcache/FactoryTest.php +++ b/tests/lib/Memcache/FactoryTest.php @@ -20,9 +20,10 @@ */ namespace Test\Memcache; +use OC\Memcache\NullCache; use OCP\ILogger; -class Test_Factory_Available_Cache1 { +class Test_Factory_Available_Cache1 extends NullCache { public function __construct($prefix = '') { } @@ -31,7 +32,7 @@ class Test_Factory_Available_Cache1 { } } -class Test_Factory_Available_Cache2 { +class Test_Factory_Available_Cache2 extends NullCache { public function __construct($prefix = '') { } @@ -40,7 +41,7 @@ class Test_Factory_Available_Cache2 { } } -class Test_Factory_Unavailable_Cache1 { +class Test_Factory_Unavailable_Cache1 extends NullCache { public function __construct($prefix = '') { } @@ -49,7 +50,7 @@ class Test_Factory_Unavailable_Cache1 { } } -class Test_Factory_Unavailable_Cache2 { +class Test_Factory_Unavailable_Cache2 extends NullCache { public function __construct($prefix = '') { } |