fix: resolve PHPStan static analysis warnings

This commit is contained in:
xboard
2025-04-14 02:12:42 +08:00
parent 3d254c02c1
commit 2d3e4b4a95
84 changed files with 2330 additions and 1190 deletions

View File

@@ -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;
}
}