Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 39 |
| CachedCurrencies | |
0.00% |
0 / 1 |
|
0.00% |
0 / 5 |
132 | |
0.00% |
0 / 39 |
| __construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| contains | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 11 |
|||
| subunitFor | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 11 |
|||
| getIterator | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
| anonymous function | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 8 |
|||
| <?php | |
| namespace Money\Currencies; | |
| use Cache\Taggable\TaggableItemInterface; | |
| use Money\Currencies; | |
| use Money\Currency; | |
| use Psr\Cache\CacheItemPoolInterface; | |
| /** | |
| * Cache the result of currency checking. | |
| * | |
| * @author Márk Sági-Kazár <mark.sagikazar@gmail.com> | |
| */ | |
| final class CachedCurrencies implements Currencies | |
| { | |
| /** | |
| * @var Currencies | |
| */ | |
| private $currencies; | |
| /** | |
| * @var CacheItemPoolInterface | |
| */ | |
| private $pool; | |
| /** | |
| * @param Currencies $currencies | |
| * @param CacheItemPoolInterface $pool | |
| */ | |
| public function __construct(Currencies $currencies, CacheItemPoolInterface $pool) | |
| { | |
| $this->currencies = $currencies; | |
| $this->pool = $pool; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function contains(Currency $currency) | |
| { | |
| $item = $this->pool->getItem('currency|availability|'.$currency->getCode()); | |
| if (false === $item->isHit()) { | |
| $item->set($this->currencies->contains($currency)); | |
| if ($item instanceof TaggableItemInterface) { | |
| $item->addTag('currency.availability'); | |
| } | |
| $this->pool->save($item); | |
| } | |
| return $item->get(); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function subunitFor(Currency $currency) | |
| { | |
| $item = $this->pool->getItem('currency|subunit|'.$currency->getCode()); | |
| if (false === $item->isHit()) { | |
| $item->set($this->currencies->subunitFor($currency)); | |
| if ($item instanceof TaggableItemInterface) { | |
| $item->addTag('currency.subunit'); | |
| } | |
| $this->pool->save($item); | |
| } | |
| return $item->get(); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function getIterator() | |
| { | |
| return new \CallbackFilterIterator( | |
| $this->currencies->getIterator(), | |
| function (Currency $currency) { | |
| $item = $this->pool->getItem('currency|availability|'.$currency->getCode()); | |
| $item->set(true); | |
| if ($item instanceof TaggableItemInterface) { | |
| $item->addTag('currency.availability'); | |
| } | |
| $this->pool->save($item); | |
| return true; | |
| } | |
| ); | |
| } | |
| } |