diff --git a/TaggablePSR6ItemAdapter.php b/TaggablePSR6ItemAdapter.php index 782a568..77d5b06 100644 --- a/TaggablePSR6ItemAdapter.php +++ b/TaggablePSR6ItemAdapter.php @@ -11,11 +11,7 @@ namespace Cache\Taggable; -use Cache\Taggable\TaggableItemInterface; -use Cache\Taggable\TaggablePoolInterface; -use Cache\Taggable\TaggablePoolTrait; use Psr\Cache\CacheItemInterface; -use Psr\Cache\CacheItemPoolInterface; /** * @internal @@ -31,7 +27,7 @@ class TaggablePSR6ItemAdapter implements TaggableItemInterface { /** - * @type boolean + * @type bool */ private $initialized = false; @@ -55,6 +51,7 @@ private function __construct(CacheItemInterface $cacheItem) /** * @param CacheItemInterface $cacheItem + * * @return TaggableItemInterface */ public static function makeTaggable(CacheItemInterface $cacheItem) @@ -88,8 +85,6 @@ public function get() if (is_array($rawItem) && isset($rawItem['value'])) { return $rawItem['value']; } - - return null; } /** @@ -109,7 +104,7 @@ public function set($value) $this->cacheItem->set([ 'value' => $value, - 'tags' => $this->tags, + 'tags' => $this->tags, ]); return $this; @@ -121,6 +116,7 @@ public function set($value) public function getTags() { $this->initializeTags(); + return $this->tags; } @@ -130,7 +126,7 @@ public function getTags() public function setTags(array $tags) { $this->initialized = true; - $this->tags = $tags; + $this->tags = $tags; $this->updateTags(); return $this; @@ -154,6 +150,7 @@ public function addTag($tag) public function expiresAt($expiration) { $this->cacheItem->expiresAt($expiration); + return $this; } @@ -163,6 +160,7 @@ public function expiresAt($expiration) public function expiresAfter($time) { $this->cacheItem->expiresAfter($time); + return $this; } @@ -170,7 +168,7 @@ private function updateTags() { $this->cacheItem->set([ 'value' => $this->get(), - 'tags' => $this->tags, + 'tags' => $this->tags, ]); } diff --git a/TaggablePSR6PoolAdapter.php b/TaggablePSR6PoolAdapter.php index 814ba2c..6697c63 100644 --- a/TaggablePSR6PoolAdapter.php +++ b/TaggablePSR6PoolAdapter.php @@ -11,9 +11,6 @@ namespace Cache\Taggable; -use Cache\Taggable\TaggableItemInterface; -use Cache\Taggable\TaggablePoolInterface; -use Cache\Taggable\TaggablePoolTrait; use Psr\Cache\CacheItemInterface; use Psr\Cache\CacheItemPoolInterface; @@ -67,14 +64,14 @@ private function __construct(CacheItemPoolInterface $cachePool, CacheItemPoolInt } /** - * @param CacheItemPoolInterface $cachePool The pool to which to add tagging capabilities. + * @param CacheItemPoolInterface $cachePool The pool to which to add tagging capabilities. * @param CacheItemPoolInterface|null $tagStorePool The pool to store tags in. If null is passed, the main pool is used. * * @return TaggablePoolInterface */ public static function makeTaggable(CacheItemPoolInterface $cachePool, CacheItemPoolInterface $tagStorePool = null) { - if ($cachePool instanceOf TaggablePoolInterface && $tagStorePool === null) { + if ($cachePool instanceof TaggablePoolInterface && $tagStorePool === null) { return $cachePool; } @@ -92,7 +89,7 @@ public function getItem($key) /** * {@inheritdoc} */ - public function getItems(array $keys = array()) + public function getItems(array $keys = []) { $items = $this->cachePool->getItems($keys); @@ -118,6 +115,7 @@ public function hasItem($key) public function clear() { $ret = $this->cachePool->clear(); + return $this->tagStorePool->clear() && $ret; // Is this acceptable? } @@ -127,6 +125,7 @@ public function clear() public function deleteItem($key) { $this->preRemoveItem($key); + return $this->cachePool->deleteItem($key); } @@ -148,6 +147,7 @@ public function deleteItems(array $keys) public function save(CacheItemInterface $item) { $this->saveTags($item); + return $this->cachePool->save($item->unwrap()); } @@ -157,6 +157,7 @@ public function save(CacheItemInterface $item) public function saveDeferred(CacheItemInterface $item) { $this->saveTags($item); + return $this->cachePool->saveDeferred($item->unwrap()); } diff --git a/TaggablePoolTrait.php b/TaggablePoolTrait.php index cedd1f4..e0af7ba 100644 --- a/TaggablePoolTrait.php +++ b/TaggablePoolTrait.php @@ -62,8 +62,7 @@ abstract protected function appendListItem($name, $key); abstract protected function removeListItem($name, $key); /** - * @param array $keys - + * @param array $keys * @throws InvalidArgumentException * * @return bool diff --git a/Tests/SameTagPoolTaggablePSR6AdapterTest.php b/Tests/SameTagPoolTaggablePSR6AdapterTest.php index c652fa5..9ced711 100644 --- a/Tests/SameTagPoolTaggablePSR6AdapterTest.php +++ b/Tests/SameTagPoolTaggablePSR6AdapterTest.php @@ -1,5 +1,14 @@ , Tobias Nyholm + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Cache\Taggable\Tests; use Cache\IntegrationTests\TaggableCachePoolTest; @@ -10,6 +19,6 @@ class SameTagPoolTaggablePSR6AdapterTest extends TaggableCachePoolTest { public function createCachePool() { - return TaggablePSR6PoolAdapter::makeTaggable(new SymfonyArrayAdapter); + return TaggablePSR6PoolAdapter::makeTaggable(new SymfonyArrayAdapter()); } } diff --git a/Tests/SeparateTagPoolPSR6AdapterTest.php b/Tests/SeparateTagPoolPSR6AdapterTest.php index d713071..5fc03b9 100644 --- a/Tests/SeparateTagPoolPSR6AdapterTest.php +++ b/Tests/SeparateTagPoolPSR6AdapterTest.php @@ -1,15 +1,24 @@ , Tobias Nyholm + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + namespace Cache\Taggable\Tests; use Cache\IntegrationTests\TaggableCachePoolTest; use Cache\Taggable\TaggablePSR6PoolAdapter; use Symfony\Component\Cache\Adapter\ArrayAdapter as SymfonyArrayAdapter; -class SeparateTagPoolTaggablePSR6AdapterTest extends TaggableCachePoolTest +class SeparateTagPoolPSR6AdapterTest extends TaggableCachePoolTest { public function createCachePool() { - return TaggablePSR6PoolAdapter::makeTaggable(new SymfonyArrayAdapter, new SymfonyArrayAdapter); + return TaggablePSR6PoolAdapter::makeTaggable(new SymfonyArrayAdapter(), new SymfonyArrayAdapter()); } }