Skip to content

Commit

Permalink
Updated phpstan 2.1 (#527)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
zds-s authored Jan 10, 2025
1 parent ccd7dbb commit 881ce11
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 15 deletions.
3 changes: 1 addition & 2 deletions app/Http/Common/Middleware/OperationMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/Service/AttachmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Symfony\Component\Finder\SplFileInfo;

/**
* @extends IService<AttachmentRepository>
* @extends IService<Attachment>
*/
final class AttachmentService extends IService
{
Expand Down
5 changes: 3 additions & 2 deletions app/Service/IService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> $repository
*/
abstract class IService
Expand Down Expand Up @@ -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
{
Expand Down
6 changes: 5 additions & 1 deletion app/Service/Permission/MenuService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@

namespace App\Service\Permission;

use App\Model\Permission\Menu;
use App\Repository\Permission\MenuRepository;
use App\Service\IService;

/**
* @extends IService<Menu>
*/
final class MenuService extends IService
{
public function __construct(
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/Service/Permission/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Hyperf\Collection\Collection;

/**
* @extends IService<UserRepository>
* @extends IService<User>
*/
final class UserService extends IService
{
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
9 changes: 2 additions & 7 deletions config/container.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Initialize a dependency injection container that implemented PSR-11 and return the container.
*/
Expand All @@ -15,11 +16,5 @@
use Hyperf\Context\ApplicationContext;
use Hyperf\Di\Container;
use Hyperf\Di\Definition\DefinitionSourceFactory;
use Psr\Container\ContainerInterface;

$container = new Container((new DefinitionSourceFactory())());

if (! $container instanceof ContainerInterface) {
throw new RuntimeException('The dependency injection container is invalid.');
}
return ApplicationContext::setContainer($container);
return ApplicationContext::setContainer(new Container((new DefinitionSourceFactory())()));

0 comments on commit 881ce11

Please sign in to comment.