Passed
Push — develop ( 9b8c4e...79e7ae )
by Andrea Marco
03:34 queued 14s
created

SessionKey::missing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

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
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cerbero\LaravelEnum\Capsules;
6
7
use Closure;
8
use Illuminate\Support\Facades\Session;
9
10
/**
11
 * The key dealing with the Laravel session.
12
 */
13
final class SessionKey
14
{
15
    /**
16
     * Instantiate the class.
17
     */
18 17
    public function __construct(private readonly string $key) {}
19
20
    /**
21
     * Determine whether the key exists.
22
     */
23 2
    public function exists(): bool
24
    {
25 2
        return Session::exists($this->key);
26
    }
27
28
    /**
29
     * Determine whether the key is missing from the session.
30
     */
31 1
    public function missing(): bool
32
    {
33 1
        return Session::missing($this->key);
34
    }
35
36
    /**
37
     * Determine whether the key is present and not null.
38
     */
39 1
    public function hasValue(): bool
40
    {
41 1
        return Session::has($this->key);
42
    }
43
44
    /**
45
     * Retrieve the value of the key from the session.
46
     */
47 1
    public function get(mixed $default = null): mixed
48
    {
49 1
        return Session::get($this->key, $default);
50
    }
51
52
    /**
53
     * Retrieve the value of the key and then forget it.
54
     */
55 1
    public function pull(mixed $default = null): mixed
56
    {
57 1
        return Session::pull($this->key, $default);
58
    }
59
60
    /**
61
     * Determine whether the session contains old input for the key.
62
     */
63 1
    public function hasOldInput(): bool
64
    {
65 1
        return Session::hasOldInput($this->key);
66
    }
67
68
    /**
69
     * Retrieve the value from the flashed input.
70
     */
71 1
    public function getOldInput(mixed $default = null): mixed
72
    {
73 1
        return Session::getOldInput($this->key, $default);
74
    }
75
76
    /**
77
     * Put the value of the key in the session.
78
     */
79 1
    public function put(mixed $value = null): self
80
    {
81 1
        Session::put($this->key, $value);
82
83 1
        return $this;
84
    }
85
86
    /**
87
     * Retrieve or store the value of the key.
88
     */
89 1
    public function remember(Closure $callback): mixed
90
    {
91 1
        return Session::remember($this->key, $callback);
92
    }
93
94
    /**
95
     * Push a value onto the array of the key.
96
     */
97 1
    public function push(mixed $value): self
98
    {
99 1
        Session::push($this->key, $value);
100
101 1
        return $this;
102
    }
103
104
    /**
105
     * Increment the value of the key.
106
     */
107 1
    public function increment(float|int $amount = 1): float|int
108
    {
109
        /** @var float|int @phpstan-ignore argument.type */
110 1
        return Session::increment($this->key, $amount);
0 ignored issues
show
Bug introduced by
It seems like $amount can also be of type double; however, parameter $amount of Illuminate\Support\Facades\Session::increment() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

110
        return Session::increment($this->key, /** @scrutinizer ignore-type */ $amount);
Loading history...
111
    }
112
113
    /**
114
     * Decrement the value of the key.
115
     */
116 1
    public function decrement(float|int $amount = 1): float|int
117
    {
118
        /** @var float|int @phpstan-ignore argument.type */
119 1
        return Session::decrement($this->key, $amount);
0 ignored issues
show
Bug introduced by
It seems like $amount can also be of type double; however, parameter $amount of Illuminate\Support\Facades\Session::decrement() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

119
        return Session::decrement($this->key, /** @scrutinizer ignore-type */ $amount);
Loading history...
120
    }
121
122
    /**
123
     * Flash the value of the key to the session.
124
     */
125 1
    public function flash(mixed $value = true): self
126
    {
127 1
        Session::flash($this->key, $value);
128
129 1
        return $this;
130
    }
131
132
    /**
133
     * Flash the value of the key to the session for immediate use.
134
     */
135 1
    public function now(mixed $value): self
136
    {
137 1
        Session::now($this->key, $value);
138
139 1
        return $this;
140
    }
141
142
    /**
143
     * Remove the key from the session and retrieve its value.
144
     */
145 1
    public function remove(): mixed
146
    {
147 1
        return Session::remove($this->key);
148
    }
149
150
    /**
151
     * Remove the key from the session.
152
     */
153 1
    public function forget(): self
154
    {
155 1
        Session::forget($this->key);
156
157 1
        return $this;
158
    }
159
}
160