| Total Complexity | 8 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Coverage | 95.24% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | class Memory implements ICache |
||
| 15 | { |
||
| 16 | /** @var resource|null */ |
||
| 17 | protected $resource = null; |
||
| 18 | |||
| 19 | 2 | public function init(array $what): void |
|
| 20 | { |
||
| 21 | 2 | } |
|
| 22 | |||
| 23 | 2 | public function exists(): bool |
|
| 24 | { |
||
| 25 | 2 | return !is_null($this->resource); |
|
| 26 | } |
||
| 27 | |||
| 28 | 2 | public function set(string $content): bool |
|
| 29 | { |
||
| 30 | 2 | $this->clear(); |
|
| 31 | 2 | $resource = fopen('php://temp', 'rb+'); |
|
| 32 | 2 | if (false === $resource) { |
|
| 33 | // @codeCoverageIgnoreStart |
||
| 34 | return false; |
||
| 35 | } |
||
| 36 | // @codeCoverageIgnoreEnd |
||
| 37 | 2 | fwrite($resource, $content); |
|
| 38 | 2 | $this->resource = $resource; |
|
| 39 | 2 | return true; |
|
| 40 | } |
||
| 41 | |||
| 42 | 2 | public function get(): string |
|
| 43 | { |
||
| 44 | 2 | if ($this->exists()) { |
|
| 45 | 2 | rewind($this->resource); |
|
| 46 | 2 | return strval(stream_get_contents($this->resource, -1, 0)); |
|
| 47 | } else { |
||
| 48 | 2 | return ''; |
|
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | 2 | public function clear(): void |
|
| 58 | 2 | } |
|
| 59 | } |
||
| 60 |