5
5
use Illuminate \Support \Collection ;
6
6
use Illuminate \Support \Facades \Log ;
7
7
use InvalidArgumentException ;
8
+ use JsonException ;
8
9
use Step2Dev \LazySetting \Models \Setting ;
9
10
use Throwable ;
10
11
@@ -41,7 +42,7 @@ public static function getCacheKey(): string
41
42
return config ('lazy-setting.cache_prefix ' ).'settings ' ;
42
43
}
43
44
44
- public static function getCacheTtl (): int
45
+ public static function getCacheTtl (): int | null
45
46
{
46
47
return config ('lazy-setting.cache_ttl ' );
47
48
}
@@ -93,12 +94,12 @@ public function getKeyAndGroup(string $key): array
93
94
return compact ('key ' , 'group ' );
94
95
}
95
96
96
- public function get (string $ key , mixed $ default = null ): ? string
97
+ public function get (string $ key , mixed $ default = null ): string | null
97
98
{
98
99
return $ this ->getConfig ($ key )?->value ?? $ default ;
99
100
}
100
101
101
- public function getConfig (string $ key ): ? Setting
102
+ public function getConfig (string $ key ): Setting | null
102
103
{
103
104
try {
104
105
['group ' => $ group , 'key ' => $ key ] = $ this ->getKeyAndGroup ($ key );
@@ -116,7 +117,7 @@ public function getConfig(string $key): ?Setting
116
117
/**
117
118
* @throws Throwable
118
119
*/
119
- public function set (string $ key , mixed $ data , ? string $ type = null ): Setting
120
+ public function set (string $ key , mixed $ data , string | null $ type = null ): Setting
120
121
{
121
122
if ($ setting = $ this ->getConfig ($ key )) {
122
123
$ this ->update ($ setting , $ data );
@@ -132,6 +133,9 @@ public function all(): Collection
132
133
return $ this ->getSettings ();
133
134
}
134
135
136
+ /**
137
+ * @throws JsonException
138
+ */
135
139
public function update (Setting $ setting , mixed $ data ): Setting
136
140
{
137
141
$ setting ->update ($ this ->formatData ($ data , $ setting ->type ));
@@ -144,7 +148,7 @@ public function update(Setting $setting, mixed $data): Setting
144
148
/**
145
149
* @throws Throwable
146
150
*/
147
- public function createIfNotExists (string $ key , mixed $ data , ? string $ type = null ): Setting
151
+ public function createIfNotExists (string $ key , mixed $ data , string | null $ type = null ): Setting
148
152
{
149
153
$ setting = Setting::firstOrCreate ($ this ->getKeyAndGroup ($ key ), $ this ->formatData ($ data , $ type ));
150
154
@@ -169,7 +173,10 @@ public function getFieldType(string $type = ''): string
169
173
};
170
174
}
171
175
172
- final protected function formatData (array |string $ data , ?string $ type = null , ?array $ options = []): array
176
+ /**
177
+ * @throws JsonException
178
+ */
179
+ final protected function formatData (array |string $ data , string |null $ type = null , array |null $ options = []): array
173
180
{
174
181
$ type = $ this ->getFieldType ($ type );
175
182
$ result = compact ('type ' );
0 commit comments