mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-05 12:40:52 +08:00
fix: resolve PHPStan static analysis warnings
This commit is contained in:
@@ -32,10 +32,11 @@ class Setting
|
||||
/**
|
||||
* 设置配置信息.
|
||||
*
|
||||
* @param array $data
|
||||
* @return $this
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return bool 设置是否成功
|
||||
*/
|
||||
public function set($key, $value = null): bool
|
||||
public function set(string $key, $value = null): bool
|
||||
{
|
||||
if (is_array($value)) {
|
||||
$value = json_encode($value);
|
||||
@@ -50,12 +51,12 @@ class Setting
|
||||
/**
|
||||
* 保存配置到数据库.
|
||||
*
|
||||
* @param array $data
|
||||
* @return $this
|
||||
* @param array $settings 要保存的设置数组
|
||||
* @return bool 保存是否成功
|
||||
*/
|
||||
public function save(array $data = []): bool
|
||||
public function save(array $settings): bool
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
foreach ($settings as $key => $value) {
|
||||
$this->set($key, $value);
|
||||
}
|
||||
|
||||
@@ -99,4 +100,22 @@ class Setting
|
||||
{
|
||||
return $this->fromDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新单个设置项
|
||||
*
|
||||
* @param string $key 设置键名
|
||||
* @param mixed $value 设置值
|
||||
* @return bool 更新是否成功
|
||||
*/
|
||||
public function update(string $key, $value): bool
|
||||
{
|
||||
if (is_array($value)) {
|
||||
$value = json_encode($value);
|
||||
}
|
||||
$key = strtolower($key);
|
||||
SettingModel::updateOrCreate(['name' => $key], ['value' => $value]);
|
||||
$this->cache->forget(self::CACHE_KEY);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user