diff --git a/HttpServer/Events/OnTask.php b/HttpServer/Events/OnTask.php index b1cb3e06..2313450d 100644 --- a/HttpServer/Events/OnTask.php +++ b/HttpServer/Events/OnTask.php @@ -41,10 +41,10 @@ class OnTask extends Callback * @param int $from_id * @param string $data * - * @return mixed|void + * @return mixed * @throws Exception 异步任务 */ - public function onTask(Server $server, int $task_id, int $from_id, string $data) + public function onTask(Server $server, int $task_id, int $from_id, string $data): mixed { $time = microtime(TRUE); if (empty($data)) { @@ -59,17 +59,16 @@ class OnTask extends Callback 'runTime' => microtime(TRUE) - $time, 'endTime' => microtime(TRUE), ]; - $server->finish(json_encode($finish)); + return $server->finish(json_encode($finish)); } /** * @param Server $server * @param Server\Task $task - * @return mixed|void - * @throws Exception - * 异步任务 + * @return mixed + * @throws Exception 异步任务 */ - public function onContinueTask(Server $server, Server\Task $task) + public function onContinueTask(Server $server, Server\Task $task): mixed { $time = microtime(TRUE); if (empty($task->data)) { @@ -84,7 +83,7 @@ class OnTask extends Callback 'runTime' => microtime(TRUE) - $time, 'endTime' => microtime(TRUE), ]; - $task->finish(json_encode($finish)); + return $task->finish(json_encode($finish)); } /** @@ -92,7 +91,7 @@ class OnTask extends Callback * @return array|null * @throws Exception */ - private function runTaskHandler($data) + private function runTaskHandler($data): ?array { $serialize = $this->before($data); try { @@ -135,7 +134,7 @@ class OnTask extends Callback * @param $exception * @return string */ - private function format($exception) + private function format($exception): string { return $exception->getMessage() . " on line " . $exception->getLine() . " at file " . $exception->getFile(); } diff --git a/HttpServer/IInterface/After.php b/HttpServer/IInterface/After.php index 3b281325..9ad5e7c6 100644 --- a/HttpServer/IInterface/After.php +++ b/HttpServer/IInterface/After.php @@ -17,6 +17,6 @@ interface After * @param $params * @return mixed */ - public function onHandler(Request $request, $params); + public function onHandler(Request $request, $params): mixed; } diff --git a/HttpServer/IInterface/IFormatter.php b/HttpServer/IInterface/IFormatter.php index 6efd894c..30ebd2ff 100644 --- a/HttpServer/IInterface/IFormatter.php +++ b/HttpServer/IInterface/IFormatter.php @@ -21,9 +21,13 @@ interface IFormatter * @param $context * @return static */ - public function send($context); + public function send($context): static; - public function getData(); - public function clear(); + /** + * @return mixed + */ + public function getData(): mixed; + + public function clear(): void; } diff --git a/HttpServer/IInterface/Interceptor.php b/HttpServer/IInterface/Interceptor.php index 3f7fe08f..332c14da 100644 --- a/HttpServer/IInterface/Interceptor.php +++ b/HttpServer/IInterface/Interceptor.php @@ -12,6 +12,11 @@ interface Interceptor { - public function Interceptor(Request $request, Closure $closure); + /** + * @param Request $request + * @param Closure $closure + * @return mixed + */ + public function Interceptor(Request $request, Closure $closure): mixed; } diff --git a/HttpServer/IInterface/Limits.php b/HttpServer/IInterface/Limits.php index 6b26475d..7705f433 100644 --- a/HttpServer/IInterface/Limits.php +++ b/HttpServer/IInterface/Limits.php @@ -11,6 +11,11 @@ use Closure; interface Limits { - public function next(Request $request, Closure $closure); + /** + * @param Request $request + * @param Closure $closure + * @return mixed + */ + public function next(Request $request, Closure $closure): mixed; } diff --git a/HttpServer/IInterface/Middleware.php b/HttpServer/IInterface/Middleware.php index 145f7dee..a6c6c58e 100644 --- a/HttpServer/IInterface/Middleware.php +++ b/HttpServer/IInterface/Middleware.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace HttpServer\IInterface; +use Closure; use HttpServer\Http\Request; /** @@ -14,6 +15,12 @@ use HttpServer\Http\Request; interface Middleware { - public function handler(Request $request,\Closure $next); + + /** + * @param Request $request + * @param Closure $next + * @return mixed + */ + public function handler(Request $request, Closure $next): mixed; } diff --git a/HttpServer/IInterface/Task.php b/HttpServer/IInterface/Task.php index 749d49d0..bcf665d4 100644 --- a/HttpServer/IInterface/Task.php +++ b/HttpServer/IInterface/Task.php @@ -21,8 +21,8 @@ interface Task /** - * @return void + * @return mixed */ - public function onHandler(): void; + public function onHandler(): mixed; }