From 9c3c1cfd82aac30b6dff8e6cffde73272cc0c4b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Tue, 24 Oct 2023 17:22:32 +0800 Subject: [PATCH] eee --- ReturnTypeWillChange.php | 23 ++++++++++---------- composer.json | 2 ++ kiri-engine/Abstracts/BaseApplication.php | 6 +---- kiri-engine/Abstracts/Component.php | 3 ++- kiri-engine/Core/DateFormat.php | 4 ++-- kiri-engine/Core/HashMap.php | 7 +++++- kiri-engine/Core/Help.php | 21 +++++++++--------- kiri-engine/Core/Str.php | 21 +++++++----------- kiri-engine/Error/ErrorHandler.php | 6 ----- kiri-engine/Events/OnAfterCommandExecute.php | 6 ++--- kiri-engine/Redis/Redis.php | 1 - 11 files changed, 45 insertions(+), 55 deletions(-) diff --git a/ReturnTypeWillChange.php b/ReturnTypeWillChange.php index 784267e0..3f034cf8 100644 --- a/ReturnTypeWillChange.php +++ b/ReturnTypeWillChange.php @@ -1,16 +1,15 @@ container = Kiri::getContainer(); + $this->container = Kiri::getContainer(); $this->localService = $this->container->get(LocalService::class); $this->provider = $this->container->get(EventProvider::class); @@ -82,8 +80,6 @@ abstract class BaseApplication extends Component } - const LOGGER_LEVELS = [Logger::EMERGENCY, Logger::ALERT, Logger::CRITICAL, Logger::ERROR, Logger::WARNING, Logger::NOTICE, Logger::INFO, Logger::DEBUG]; - /** * @param ConfigProvider $config * @return void diff --git a/kiri-engine/Abstracts/Component.php b/kiri-engine/Abstracts/Component.php index 507a3888..a5a7ef7f 100644 --- a/kiri-engine/Abstracts/Component.php +++ b/kiri-engine/Abstracts/Component.php @@ -13,6 +13,7 @@ namespace Kiri\Abstracts; use Exception; use JetBrains\PhpStorm\Pure; use Kiri; +use ReflectionException; /** * Class Component @@ -49,7 +50,7 @@ class Component implements Configure /** * @return Kiri\Error\StdoutLogger - * @throws \ReflectionException + * @throws ReflectionException */ public function getLogger(): Kiri\Error\StdoutLogger { diff --git a/kiri-engine/Core/DateFormat.php b/kiri-engine/Core/DateFormat.php index 923f8af0..63ff394c 100644 --- a/kiri-engine/Core/DateFormat.php +++ b/kiri-engine/Core/DateFormat.php @@ -94,8 +94,8 @@ class DateFormat * @param null $endTime * @return string */ - public static function mtime($startTime, $endTime = null) - { + public static function mtime($startTime, $endTime = null): string + { if ($endTime === null) { $endTime = microtime(true); } diff --git a/kiri-engine/Core/HashMap.php b/kiri-engine/Core/HashMap.php index 5db7ec2b..8aa9bd0c 100644 --- a/kiri-engine/Core/HashMap.php +++ b/kiri-engine/Core/HashMap.php @@ -138,7 +138,12 @@ class HashMap implements \ArrayAccess, \IteratorAggregate } - public static function Tree(HashMap $root, string $leaf) + /** + * @param HashMap $root + * @param string $leaf + * @return HashMap + */ + public static function Tree(HashMap $root, string $leaf): HashMap { if ($root->has($leaf)) { $hashMap = $root->get($leaf); diff --git a/kiri-engine/Core/Help.php b/kiri-engine/Core/Help.php index 7d4696c9..19009048 100644 --- a/kiri-engine/Core/Help.php +++ b/kiri-engine/Core/Help.php @@ -6,6 +6,8 @@ namespace Kiri\Core; use Exception; +use Swift_Message; +use Swift_SmtpTransport; /** @@ -114,11 +116,8 @@ class Help public static function toString($parameter): bool|array|string { if (!is_string($parameter)) { - $parameter = ArrayAccess::toArray($parameter); - if (is_array($parameter)) { - $parameter = Json::encode($parameter); - } - } + $parameter = Json::encode(ArrayAccess::toArray($parameter)); + } return $parameter; } @@ -152,7 +151,7 @@ class Help * * 随机字符串 */ - public static function random($length = 20): string + public static function random(int $length = 20): string { $res = []; $str = 'abcdefghijklmnopqrstuvwxyz'; @@ -162,7 +161,7 @@ class Help if (empty($rand)) { $rand = substr($str, strlen($str) - 3, 1); } - array_push($res, $rand); + $res[] = $rand; } return implode($res); @@ -199,14 +198,14 @@ class Help * @param string $Subject * @param $messageContent */ - public static function sendEmail($email, string $Subject, $messageContent) - { + public static function sendEmail($email, string $Subject, $messageContent): void + { if (!class_exists('\Swift_Mailer')) { return; } - $mailer = new \Swift_Mailer((new \Swift_SmtpTransport($email['host'], $email['port'])) + $mailer = new \Swift_Mailer((new Swift_SmtpTransport($email['host'], $email['port'])) ->setUsername($email['username'])->setPassword($email['password'])); - $message = (new \Swift_Message($Subject)) + $message = (new Swift_Message($Subject)) ->setFrom([$email['send']['address'] => $email['send']['nickname']]) ->setBody('Here is the message itself'); diff --git a/kiri-engine/Core/Str.php b/kiri-engine/Core/Str.php index b9dbb5f6..6e3ea2c8 100644 --- a/kiri-engine/Core/Str.php +++ b/kiri-engine/Core/Str.php @@ -45,7 +45,7 @@ class Str */ public static function random(int $length = 20): int|string { - $number = ''; + $number = ''; $default = str_split(self::NUMBER); if ($length < 1) $length = 1; for ($i = 0; $i < $length; $i++) { @@ -157,7 +157,7 @@ class Str asort($array); $str = implode('', $array); for ($i = 0; $i < $number; $i++) { - $_tmp = md5($key) . md5($str) . mb_substr($add, $len, $len + 5, 'utf-8'); + $_tmp = md5($key) . md5($str) . mb_substr($add, $len, $len + 5, 'utf-8'); $res[] = md5($_tmp); } sort($res, SORT_STRING); @@ -171,17 +171,12 @@ class Str */ public static function filename($file, $type): string { - switch ($type) { - case 'image/png': - return md5_file($file) . '.png'; - case 'image/jpeg': - case 'image/jpg': - return md5_file($file) . '.jpg'; - case 'image/gif': - return md5_file($file) . '.gif'; - break; - } - return md5_file($file); + return match ($type) { + 'image/png' => md5_file($file) . '.png', + 'image/jpeg', 'image/jpg' => md5_file($file) . '.jpg', + 'image/gif' => md5_file($file) . '.gif', + default => md5_file($file), + }; } /** diff --git a/kiri-engine/Error/ErrorHandler.php b/kiri-engine/Error/ErrorHandler.php index 84b8b125..99090291 100644 --- a/kiri-engine/Error/ErrorHandler.php +++ b/kiri-engine/Error/ErrorHandler.php @@ -95,8 +95,6 @@ class ErrorHandler extends Component implements ErrorInterface /** * @return void - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface * @throws ReflectionException * @throws Exception */ @@ -114,8 +112,6 @@ class ErrorHandler extends Component implements ErrorInterface /** * @param Throwable $exception * - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface * @throws Exception */ public function exceptionHandler(Throwable $exception): void @@ -130,8 +126,6 @@ class ErrorHandler extends Component implements ErrorInterface /** * @throws ErrorException - * @throws ContainerExceptionInterface - * @throws NotFoundExceptionInterface * @throws ReflectionException */ public function errorHandler() diff --git a/kiri-engine/Events/OnAfterCommandExecute.php b/kiri-engine/Events/OnAfterCommandExecute.php index 17fa3b79..9d12fc10 100644 --- a/kiri-engine/Events/OnAfterCommandExecute.php +++ b/kiri-engine/Events/OnAfterCommandExecute.php @@ -8,9 +8,9 @@ class OnAfterCommandExecute { - /** - * - */ + /** + * @param Command $command + */ public function __construct(public Command $command) { } diff --git a/kiri-engine/Redis/Redis.php b/kiri-engine/Redis/Redis.php index 39ce4978..1462dcc5 100644 --- a/kiri-engine/Redis/Redis.php +++ b/kiri-engine/Redis/Redis.php @@ -13,7 +13,6 @@ use Exception; use Kiri; use Kiri\Exception\RedisConnectException; use Kiri\Pool\Pool; -use Kiri\Server\Events\OnWorkerExit; /** * Class Redis