RequestCache::getRepositoryCacheCollection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Shamaseen\Repository\Utility\Models;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Support\Facades\Cache;
7
use Psr\SimpleCache\InvalidArgumentException;
8
9
class RequestCache
10
{
11
    public string $key;
12
13
    public function __construct($key)
14
    {
15
        $this->key = $key;
16
    }
17
18
    /**
19
     * @throws InvalidArgumentException
20
     */
21
    private function getRepositoryCacheCollection(): Collection
22
    {
23
        return Cache::store('array')->get($this->key, collect([]));
0 ignored issues
show
Bug introduced by
array() of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
        return Cache::store('array')->get($this->key, collect(/** @scrutinizer ignore-type */ []));
Loading history...
24
    }
25
26
    /**
27
     * @throws InvalidArgumentException
28
     */
29
    public function get($key, $default = null)
30
    {
31
        return $this->getRepositoryCacheCollection()->get($key, $default);
32
    }
33
34
    /**
35
     * @throws InvalidArgumentException
36
     */
37
    public function set($key, $value): bool
38
    {
39
        return Cache::store('array')->set(
40
            $this->key,
41
            $this->getRepositoryCacheCollection()->put($key, $value)
42
        );
43
    }
44
45
    /**
46
     * @throws InvalidArgumentException
47
     */
48
    public function delete(array|string|int $key): bool
49
    {
50
        return Cache::store('array')->set(
51
            $this->key,
52
            $this->getRepositoryCacheCollection()->forget($key)
53
        );
54
    }
55
56
    /**
57
     * @throws InvalidArgumentException
58
     */
59
    public function clear(): bool
60
    {
61
        return Cache::store('array')->set(
62
            $this->key,
63
            collect([])
0 ignored issues
show
Bug introduced by
array() of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

63
            collect(/** @scrutinizer ignore-type */ [])
Loading history...
64
        );
65
    }
66
67
    public function all(): array
68
    {
69
        return $this->getRepositoryCacheCollection()->all();
70
    }
71
}
72