add cs fixer and PHPStan and activate it (build 436)

This commit is contained in:
crazywhalecc
2022-03-15 18:05:33 +08:00
parent d01bd69aa5
commit 1706afbcd0
163 changed files with 4572 additions and 3588 deletions

View File

@@ -1,9 +1,9 @@
<?php
declare(strict_types=1);
namespace ZM\Store;
use Exception;
use Swoole\Table;
use ZM\Exception\LightCacheException;
@@ -11,15 +11,16 @@ use ZM\Exception\ZMException;
class LightCacheInside
{
/** @var Table[]|null */
/** @var null|Table[] */
private static $kv_table = [];
public static function init(): bool {
public static function init(): bool
{
try {
self::createTable("wait_api", 3, 65536);
self::createTable("connect", 3, 64); //用于存单机器人模式下的机器人fd的
self::createTable("static_route", 64, 256);//用于存储
self::createTable("light_array", 8, 512, 0.6);
self::createTable('wait_api', 3, 65536);
self::createTable('connect', 3, 64); //用于存单机器人模式下的机器人fd的
self::createTable('static_route', 64, 256); //用于存储
self::createTable('light_array', 8, 512, 0.6);
} catch (ZMException $e) {
return false;
} //用于存协程等待的状态内容的
@@ -28,32 +29,31 @@ class LightCacheInside
}
/**
* @param string $table
* @param string $key
* @return mixed|null
* @return null|mixed
*/
public static function get(string $table, string $key) {
public static function get(string $table, string $key)
{
$r = self::$kv_table[$table]->get($key);
return $r === false ? null : json_decode($r["value"], true);
return $r === false ? null : json_decode($r['value'], true);
}
/**
* @param string $table
* @param string $key
* @param string|array|int $value
* @param array|int|string $value
* @return mixed
*/
public static function set(string $table, string $key, $value): bool {
public static function set(string $table, string $key, $value): bool
{
try {
return self::$kv_table[$table]->set($key, [
"value" => json_encode($value, 256)
'value' => json_encode($value, 256),
]);
} catch (Exception $e) {
return false;
}
}
public static function unset(string $table, string $key) {
public static function unset(string $table, string $key)
{
return self::$kv_table[$table]->del($key);
}
@@ -61,13 +61,16 @@ class LightCacheInside
* @param $name
* @param $size
* @param $str_size
* @param int $conflict_proportion
* @param int $conflict_proportion
* @throws ZMException
*/
private static function createTable($name, $size, $str_size, $conflict_proportion = 0) {
private static function createTable($name, $size, $str_size, $conflict_proportion = 0)
{
self::$kv_table[$name] = new Table($size, $conflict_proportion);
self::$kv_table[$name]->column("value", Table::TYPE_STRING, $str_size);
self::$kv_table[$name]->column('value', Table::TYPE_STRING, $str_size);
$r = self::$kv_table[$name]->create();
if ($r === false) throw new LightCacheException("E00050", "内存不足,创建静态表失败!");
if ($r === false) {
throw new LightCacheException('E00050', '内存不足,创建静态表失败!');
}
}
}