Total Complexity | 7 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | class IdRetriever |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * @var Repository |
||
19 | */ |
||
20 | private Repository $cache; |
||
21 | private $baseId; |
||
22 | private $tableName; |
||
23 | |||
24 | 8 | public function __construct(Repository $cache, $baseId, $tableName) |
|
25 | { |
||
26 | 8 | $this->cache = $cache; |
|
27 | 8 | $this->baseId = $baseId; |
|
28 | 8 | $this->tableName = $tableName; |
|
29 | 8 | } |
|
30 | |||
31 | 7 | public function ids(): Collection |
|
32 | { |
||
33 | 7 | return collect( |
|
34 | 7 | $this->cache->get($this->key()) |
|
35 | ); |
||
36 | } |
||
37 | |||
38 | 7 | public function saveIds($ids) |
|
39 | { |
||
40 | 7 | if($ids instanceof Collection) { |
|
41 | 4 | $ids = $ids->toArray(); |
|
42 | } |
||
43 | 7 | $this->cache->forever($this->key(), $ids); |
|
44 | 7 | } |
|
45 | |||
46 | 1 | public function pushIds(array $ids): void |
|
50 | 1 | } |
|
51 | |||
52 | 3 | public function pushId(string $id): void |
|
53 | { |
||
54 | 3 | $currentIds = $this->ids(); |
|
55 | 3 | $currentIds->push($id); |
|
56 | 3 | $this->saveIds($currentIds); |
|
57 | 3 | } |
|
58 | |||
59 | 8 | private function key() |
|
62 | } |
||
63 | |||
64 | } |