| Total Complexity | 8 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | trait InteractsWithCache |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var \Psr\SimpleCache\CacheInterface |
||
| 27 | */ |
||
| 28 | protected $cache; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Get cache instance. |
||
| 32 | * |
||
| 33 | * @return \Psr\SimpleCache\CacheInterface |
||
| 34 | */ |
||
| 35 | 2 | public function getCache() |
|
| 36 | { |
||
| 37 | 2 | if ($this->cache) { |
|
| 38 | 1 | return $this->cache; |
|
| 39 | } |
||
| 40 | |||
| 41 | 2 | if (property_exists($this, 'app') && $this->app instanceof ServiceContainer |
|
| 42 | 2 | && isset($this->app['cache']) && $this->app['cache'] instanceof CacheInterface) { |
|
| 43 | 1 | return $this->cache = $this->app['cache']; |
|
| 44 | } |
||
| 45 | |||
| 46 | 2 | return $this->cache = $this->createDefaultCache(); |
|
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Set cache instance. |
||
| 51 | * |
||
| 52 | * @param \Psr\SimpleCache\CacheInterface $cache |
||
| 53 | * |
||
| 54 | * @return $this |
||
| 55 | */ |
||
| 56 | 1 | public function setCache(CacheInterface $cache) |
|
| 57 | { |
||
| 58 | 1 | $this->cache = $cache; |
|
| 59 | |||
| 60 | 1 | return $this; |
|
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @return \Symfony\Component\Cache\Simple\FilesystemCache |
||
| 65 | */ |
||
| 66 | 2 | protected function createDefaultCache() |
|
| 69 | } |
||
| 70 | } |
||
| 71 |