From 881ce11bb1772ace6ee84691b46415edcb2963a6 Mon Sep 17 00:00:00 2001 From: lyan <49744633+zds-s@users.noreply.github.com> Date: Sat, 11 Jan 2025 03:39:56 +0800 Subject: [PATCH] Updated phpstan 2.1 (#527) * refactor(container): simplify container initialization and update dependencies - Simplify container initialization in config/container.php - Update phpstan dependency from ^1.10 to ^2.1 in composer.json - Adjust AttachmentService to use Attachment instead of AttachmentRepository - Remove unnecessary ContainerInterface check * Revert --- app/Http/Common/Middleware/OperationMiddleware.php | 3 +-- app/Service/AttachmentService.php | 2 +- app/Service/IService.php | 5 +++-- app/Service/Permission/MenuService.php | 6 +++++- app/Service/Permission/UserService.php | 2 +- composer.json | 2 +- config/container.php | 9 ++------- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/Http/Common/Middleware/OperationMiddleware.php b/app/Http/Common/Middleware/OperationMiddleware.php index 1ee3baf2..76d43c92 100644 --- a/app/Http/Common/Middleware/OperationMiddleware.php +++ b/app/Http/Common/Middleware/OperationMiddleware.php @@ -26,7 +26,6 @@ use Mine\Support\Request; use Mine\Support\Traits\ParserRouterTrait; use OpenApi\Annotations\Operation; -use OpenApi\Generator; use Psr\Container\ContainerInterface; use Psr\EventDispatcher\EventDispatcherInterface; use Psr\Http\Message\ResponseInterface; @@ -61,7 +60,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface } [$controller,$method] = $parseResult; $operator = $this->getClassMethodPathAttribute($controller, $method); - if ($operator !== Generator::UNDEFINED) { + if ($operator !== null) { $this->dispatcher->dispatch(new RequestOperationEvent( $this->user->id(), $operator->summary, diff --git a/app/Service/AttachmentService.php b/app/Service/AttachmentService.php index 60e05d96..0a29cd4c 100644 --- a/app/Service/AttachmentService.php +++ b/app/Service/AttachmentService.php @@ -19,7 +19,7 @@ use Symfony\Component\Finder\SplFileInfo; /** - * @extends IService + * @extends IService */ final class AttachmentService extends IService { diff --git a/app/Service/IService.php b/app/Service/IService.php index 03015788..e798c066 100644 --- a/app/Service/IService.php +++ b/app/Service/IService.php @@ -14,10 +14,11 @@ use App\Repository\IRepository; use Hyperf\Collection\Collection; +use Hyperf\DbConnection\Model\Model; use Hyperf\DbConnection\Traits\HasContainer; /** - * @template T + * @template T of Model * @property IRepository $repository */ abstract class IService @@ -56,7 +57,7 @@ public function save(array $data): mixed } /** - * @return null|T + * @return null|mixed|T */ public function updateById(mixed $id, array $data): mixed { diff --git a/app/Service/Permission/MenuService.php b/app/Service/Permission/MenuService.php index 9e578ede..e9ec47bb 100644 --- a/app/Service/Permission/MenuService.php +++ b/app/Service/Permission/MenuService.php @@ -12,9 +12,13 @@ namespace App\Service\Permission; +use App\Model\Permission\Menu; use App\Repository\Permission\MenuRepository; use App\Service\IService; +/** + * @extends IService + */ final class MenuService extends IService { public function __construct( @@ -29,7 +33,7 @@ public function getRepository(): MenuRepository public function create(array $data): mixed { $model = parent::create($data); - if ($model && $data['meta']['type'] === 'M' && ! empty($data['btnPermission'])) { + if ($data['meta']['type'] === 'M' && ! empty($data['btnPermission'])) { foreach ($data['btnPermission'] as $item) { $this->repository->create([ 'pid' => $model->id, diff --git a/app/Service/Permission/UserService.php b/app/Service/Permission/UserService.php index 610fd880..211c3cb1 100644 --- a/app/Service/Permission/UserService.php +++ b/app/Service/Permission/UserService.php @@ -20,7 +20,7 @@ use Hyperf\Collection\Collection; /** - * @extends IService + * @extends IService */ final class UserService extends IService { diff --git a/composer.json b/composer.json index 47af79e9..11384e73 100644 --- a/composer.json +++ b/composer.json @@ -74,7 +74,7 @@ "hyperf/testing": "3.1.*", "hyperf/watcher": "3.1.*", "mockery/mockery": "^1.0", - "phpstan/phpstan": "^1.10", + "phpstan/phpstan": "^2.1", "swoole/ide-helper": "^6.0", "zircote/swagger-php": "4.10.6" }, diff --git a/config/container.php b/config/container.php index 4bab264a..65e6138d 100644 --- a/config/container.php +++ b/config/container.php @@ -1,4 +1,5 @@