Skip to content

Commit

Permalink
Applied style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusnordlander committed Feb 28, 2016
1 parent bfd1927 commit ad9276e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 21 deletions.
18 changes: 8 additions & 10 deletions TaggablePSR6ItemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,7 +27,7 @@
class TaggablePSR6ItemAdapter implements TaggableItemInterface
{
/**
* @type boolean
* @type bool
*/
private $initialized = false;

Expand All @@ -55,6 +51,7 @@ private function __construct(CacheItemInterface $cacheItem)

/**
* @param CacheItemInterface $cacheItem
*
* @return TaggableItemInterface
*/
public static function makeTaggable(CacheItemInterface $cacheItem)
Expand Down Expand Up @@ -88,8 +85,6 @@ public function get()
if (is_array($rawItem) && isset($rawItem['value'])) {
return $rawItem['value'];
}

return null;
}

/**
Expand All @@ -109,7 +104,7 @@ public function set($value)

$this->cacheItem->set([
'value' => $value,
'tags' => $this->tags,
'tags' => $this->tags,
]);

return $this;
Expand All @@ -121,6 +116,7 @@ public function set($value)
public function getTags()
{
$this->initializeTags();

return $this->tags;
}

Expand All @@ -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;
Expand All @@ -154,6 +150,7 @@ public function addTag($tag)
public function expiresAt($expiration)
{
$this->cacheItem->expiresAt($expiration);

return $this;
}

Expand All @@ -163,14 +160,15 @@ public function expiresAt($expiration)
public function expiresAfter($time)
{
$this->cacheItem->expiresAfter($time);

return $this;
}

private function updateTags()
{
$this->cacheItem->set([
'value' => $this->get(),
'tags' => $this->tags,
'tags' => $this->tags,
]);
}

Expand Down
13 changes: 7 additions & 6 deletions TaggablePSR6PoolAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand All @@ -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);

Expand All @@ -118,6 +115,7 @@ public function hasItem($key)
public function clear()
{
$ret = $this->cachePool->clear();

return $this->tagStorePool->clear() && $ret; // Is this acceptable?
}

Expand All @@ -127,6 +125,7 @@ public function clear()
public function deleteItem($key)
{
$this->preRemoveItem($key);

return $this->cachePool->deleteItem($key);
}

Expand All @@ -148,6 +147,7 @@ public function deleteItems(array $keys)
public function save(CacheItemInterface $item)
{
$this->saveTags($item);

return $this->cachePool->save($item->unwrap());
}

Expand All @@ -157,6 +157,7 @@ public function save(CacheItemInterface $item)
public function saveDeferred(CacheItemInterface $item)
{
$this->saveTags($item);

return $this->cachePool->saveDeferred($item->unwrap());
}

Expand Down
3 changes: 1 addition & 2 deletions TaggablePoolTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion Tests/SameTagPoolTaggablePSR6AdapterTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of php-cache organization.
*
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
*
* 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;
Expand All @@ -10,6 +19,6 @@ class SameTagPoolTaggablePSR6AdapterTest extends TaggableCachePoolTest
{
public function createCachePool()
{
return TaggablePSR6PoolAdapter::makeTaggable(new SymfonyArrayAdapter);
return TaggablePSR6PoolAdapter::makeTaggable(new SymfonyArrayAdapter());
}
}
13 changes: 11 additions & 2 deletions Tests/SeparateTagPoolPSR6AdapterTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
<?php

/*
* This file is part of php-cache organization.
*
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
*
* 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());
}
}

0 comments on commit ad9276e

Please sign in to comment.