| Total Complexity | 9 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Coverage | 95.45% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | final class SimpleCacheSchemaProvider implements SchemaProviderInterface |
||
| 11 | { |
||
| 12 | public const DEFAULT_KEY = 'Cycle-ORM-Schema'; |
||
| 13 | private CacheInterface $cache; |
||
| 14 | private string $key = self::DEFAULT_KEY; |
||
| 15 | |||
| 16 | 5 | public function __construct(CacheInterface $cache) |
|
| 17 | { |
||
| 18 | 5 | $this->cache = $cache; |
|
| 19 | 5 | } |
|
| 20 | |||
| 21 | 3 | public function withConfig(array $config): self |
|
| 22 | { |
||
| 23 | 3 | $new = clone $this; |
|
| 24 | 3 | $new->key = $config['key'] ?? self::DEFAULT_KEY; |
|
| 25 | 3 | return $new; |
|
| 26 | } |
||
| 27 | |||
| 28 | 3 | public function read(?SchemaProviderInterface $nextProvider = null): ?array |
|
| 29 | { |
||
| 30 | 3 | $schema = $this->cache->get($this->key); |
|
| 31 | |||
| 32 | 3 | if ($schema !== null || $nextProvider === null) { |
|
| 33 | 2 | return $schema; |
|
| 34 | } |
||
| 35 | |||
| 36 | 1 | $schema = $nextProvider->read(); |
|
| 37 | 1 | if ($schema !== null) { |
|
| 38 | 1 | $this->write($schema); |
|
| 39 | } |
||
| 40 | 1 | return $schema; |
|
| 41 | } |
||
| 42 | |||
| 43 | 2 | public function clear(): bool |
|
| 50 | } |
||
| 51 | |||
| 52 | 1 | private function write(array $schema): bool |
|
| 55 | } |
||
| 56 | } |
||
| 57 |