Skip to content

Commit

Permalink
更新php-cs-fixer并优化开发环境依赖 (#505)
Browse files Browse the repository at this point in the history
* 更新 php-cs-fixer 版本

* 修复 phpstan 依赖关系

* 屏蔽警告

* fix phpstan

* 修复依赖关系

* fix style

* 修复依赖关系

* 声明版本
  • Loading branch information
NHZEX authored Apr 27, 2023
1 parent 494fa02 commit d2dc13f
Show file tree
Hide file tree
Showing 150 changed files with 320 additions and 62 deletions.
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
"yurunsoft/doctrine-annotations": "^1.73.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~3.13.0",
"composer/semver": "^3.3.2",
"php-cs-fixer/shim": "~3.15.1",
"phpstan/phpstan": "~1.8.0",
"phpunit/phpunit": "~9.6",
"rector/rector": "~0.13",
"symfony/polyfill-uuid": "^1.27",
"yurunsoft/ide-helper": "~1.0",
"yurunsoft/yurun-http": "^4.0.0",
"symfony/polyfill-uuid": "*"
"yurunsoft/yurun-http": "^4.0.0"
},
"replace": {
"symfony/polyfill-php71": "*",
Expand Down Expand Up @@ -135,4 +136,4 @@
]
}
}
}
}
23 changes: 20 additions & 3 deletions src/Util/File/FileFinder.php → dev/PHPStan/FileFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

declare(strict_types=1);

namespace Imi\Util\File;
namespace Imi\Dev\PHPStan;

use Composer\Autoload\ClassLoader;
use PHPStan\File\FileExcluder;
use PHPStan\File\FileFinderResult;
use PHPStan\File\FileHelper;
use PHPStan\File\PathNotFoundException;
use Symfony\Component\Finder\Finder;

class FileFinder extends \PHPStan\File\FileFinder
{
private FileExcluder $fileExcluder;
private FileHelper $fileHelper;
private array $fileExtensions;

private string $finderClass;

/**
* @param string[] $fileExtensions
*/
Expand All @@ -27,6 +29,21 @@ public function __construct(
$this->fileExcluder = $fileExcluder;
$this->fileHelper = $fileHelper;
$this->fileExtensions = $fileExtensions;

/** @var ClassLoader $composer */
$composer = require 'phar://phpstan.phar/vendor/autoload.php';

foreach ($composer->getPrefixesPsr4() as $name => $paths)
{
if (str_ends_with($name, 'Symfony\\Component\\Finder\\'))
{
$this->finderClass = $name . 'Finder';
}
}
if (!isset($this->finderClass))
{
throw new \RuntimeException('[Symfony\\Component\\Finder\\Finder] not found');
}
}

/**
Expand All @@ -48,7 +65,7 @@ public function findFiles(array $paths): FileFinderResult
}
else
{
$finder = new Finder();
$finder = new $this->finderClass();
// 此行注释,防止无限套娃
// $finder->followLinks();
foreach ($finder->files()->name('*.{' . implode(',', $this->fileExtensions) . '}')->in($path) as $fileInfo)
Expand Down
4 changes: 2 additions & 2 deletions phpstan-components.neon
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ parameters:

services:
fileFinderAnalyse:
class: Imi\Util\File\FileFinder
class: Imi\Dev\PHPStan\FileFinder
arguments:
fileExcluder: @fileExcluderAnalyse
fileExtensions: %fileExtensions%
autowired: false

fileFinderScan:
class: Imi\Util\File\FileFinder
class: Imi\Dev\PHPStan\FileFinder
arguments:
fileExcluder: @fileExcluderScan
fileExtensions: %fileExtensions%
Expand Down
8 changes: 6 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,20 @@ parameters:
message: '#Method \S+ has no return typehint specified.#'
paths:
- tests/unit/**Test.php
-
message: '#(Extending|Creating new|Calling) \S+ is not covered by backward compatibility promise\. The (class|method) might change in a minor PHPStan version\.#'
paths:
- dev/PHPStan/FileFinder.php
services:
fileFinderAnalyse:
class: Imi\Util\File\FileFinder
class: Imi\Dev\PHPStan\FileFinder
arguments:
fileExcluder: @fileExcluderAnalyse
fileExtensions: %fileExtensions%
autowired: false

fileFinderScan:
class: Imi\Util\File\FileFinder
class: Imi\Dev\PHPStan\FileFinder
arguments:
fileExcluder: @fileExcluderScan
fileExtensions: %fileExtensions%
Expand Down
1 change: 1 addition & 0 deletions src/Bean/Annotation/Bean.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @Annotation
*
* @Target("CLASS")
*
* @Parser("Imi\Bean\Parser\BeanParser")
*
* @property string|null $name Bean名称,留空则为当前类名(包含完整命名空间)
Expand Down
1 change: 1 addition & 0 deletions src/Bean/Annotation/ClassEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @Annotation
*
* @Target("CLASS")
*
* @Parser("Imi\Bean\Parser\ClassEventParser")
*
* @property string $className 类名
Expand Down
1 change: 1 addition & 0 deletions src/Bean/Annotation/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @Annotation
*
* @Target("CLASS")
*
* @Parser("Imi\Bean\Parser\ListenerParser")
*
* @property string $eventName 事件名
Expand Down
1 change: 1 addition & 0 deletions src/Bean/Annotation/Partial.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @Annotation
*
* @Target("CLASS")
*
* @Parser("Imi\Bean\Parser\PartialParser")
*
* @property string $class 注入类名
Expand Down
5 changes: 2 additions & 3 deletions src/Bean/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
use Imi\App;
use Imi\Config;
use Imi\Core\Component\ComponentManager;

use function Imi\env;

use Imi\Event\Event;
use Imi\Log\Log;
use Imi\Main\Helper;
Expand All @@ -18,6 +15,8 @@
use Imi\Util\File;
use Imi\Util\Imi;

use function Imi\env;

/**
* 扫描类.
*/
Expand Down
1 change: 1 addition & 0 deletions src/Cli/Annotation/Arg.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @Annotation
*
* @Target("METHOD")
*
* @Parser("Imi\Cli\Parser\ToolParser")
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
Expand Down
1 change: 1 addition & 0 deletions src/Cli/Annotation/Argument.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @Annotation
*
* @Target("METHOD")
*
* @Parser("Imi\Cli\Parser\ToolParser")
*
* @property string $name 参数名称
Expand Down
1 change: 1 addition & 0 deletions src/Cli/Annotation/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @Annotation
*
* @Target("CLASS")
*
* @Parser("Imi\Cli\Parser\ToolParser")
*
* @property string|null $name 命令行名称
Expand Down
1 change: 1 addition & 0 deletions src/Cli/Annotation/CommandAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @Annotation
*
* @Target("METHOD")
*
* @Parser("Imi\Cli\Parser\ToolParser")
*
* @property string|null $name 操作名称
Expand Down
1 change: 1 addition & 0 deletions src/Cli/Annotation/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @Annotation
*
* @Target("METHOD")
*
* @Parser("Imi\Cli\Parser\ToolParser")
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
Expand Down
1 change: 1 addition & 0 deletions src/Cli/Annotation/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @Annotation
*
* @Target("METHOD")
*
* @Parser("Imi\Cli\Parser\ToolParser")
*
* @property string $name 参数名称
Expand Down
1 change: 1 addition & 0 deletions src/Cli/Annotation/Tool.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @Annotation
*
* @Target("CLASS")
*
* @Parser("Imi\Cli\Parser\ToolParser")
*/
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
Expand Down
4 changes: 4 additions & 0 deletions src/Cli/Tools/Imi/Imi.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Imi extends BaseCommand
* 构建框架预加载缓存.
*
* @CommandAction(name="buildImiRuntime", description="构建框架预加载缓存")
*
* @Option(name="file", type=ArgType::STRING, default=null, comments="可以指定生成到目标文件")
* @Option(name="runtimeMode", type=ArgType::STRING, default=null, comments="指定运行时模式")
*/
Expand All @@ -43,6 +44,7 @@ public function buildImiRuntime(?string $file, ?string $runtimeMode = null): voi
* 清除框架预加载缓存.
*
* @CommandAction(name="clearImiRuntime", description="清除框架预加载缓存")
*
* @Option(name="runtimeMode", type=ArgType::STRING, default=null, comments="指定运行时模式")
*/
public function clearImiRuntime(?string $runtimeMode = null): void
Expand All @@ -64,6 +66,7 @@ public function clearImiRuntime(?string $runtimeMode = null): void
* @PoolClean
*
* @CommandAction(name="buildRuntime", description="构建项目预加载缓存")
*
* @Option(name="changedFilesFile", type=ArgType::STRING, default=null, comments="保存改变的文件列表的文件,一行一个")
* @Option(name="confirm", type=ArgType::BOOL, default=false, comments="是否等待输入y后再构建")
* @Option(name="runtimeMode", type=ArgType::STRING, default=null, comments="指定运行时模式")
Expand Down Expand Up @@ -102,6 +105,7 @@ public function buildRuntime(?string $changedFilesFile, bool $confirm, ?string $
* 清除项目预加载缓存.
*
* @CommandAction(name="clearRuntime", description="清除项目预加载缓存")
*
* @Option(name="runtimeMode", type=ArgType::STRING, default=null, comments="指定运行时模式")
*/
public function clearRuntime(?string $runtimeMode = null): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* @Entity
*
* @Table(name="ac_member_operation_relation", id={"member_id", "operation_id"})
*
* @DDL("CREATE TABLE `ac_member_operation_relation` ( `member_id` INT(10) UNSIGNED NOT NULL COMMENT '用户ID', `operation_id` INT(10) UNSIGNED NOT NULL COMMENT '操作ID', PRIMARY KEY(`member_id`, `operation_id`) USING BTREE) ENGINE=InnoDB DEFAULT CHARSET=utf8")
*
* @property int $memberId 用户ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* @Entity
*
* @Table(name="ac_member_role_relation", id={"member_id", "role_id"})
*
* @DDL("CREATE TABLE `ac_member_role_relation` ( `member_id` int(10) unsigned NOT NULL COMMENT '用户ID', `role_id` int(10) unsigned NOT NULL COMMENT '角色ID', PRIMARY KEY (`member_id`,`role_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8")
*
* @property int|null $memberId 用户ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* @Entity
*
* @Table(name="ac_operation", id={"id"})
*
* @DDL("CREATE TABLE `ac_operation` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `parent_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '父级ID,顶级为0', `index` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '排序,越小越靠前', `code` varchar(32) NOT NULL COMMENT '操作代码', `name` varchar(32) NOT NULL COMMENT '操作名称', `description` text NOT NULL COMMENT '操作介绍', PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8")
*
* @property int|null $id
Expand Down
1 change: 1 addition & 0 deletions src/Components/access-control/src/Model/Base/RoleBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* @Entity
*
* @Table(name="ac_role", id={"id"})
*
* @DDL("CREATE TABLE `ac_role` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `code` varchar(32) NOT NULL COMMENT '角色代码', `name` varchar(32) NOT NULL COMMENT '角色名称', `description` text NOT NULL COMMENT '角色介绍', PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8")
*
* @property int|null $id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* @Entity
*
* @Table(name="ac_role_operation_relation", id={"role_id", "operation_id"})
*
* @DDL("CREATE TABLE `ac_role_operation_relation` ( `role_id` int(10) unsigned NOT NULL COMMENT '角色ID', `operation_id` int(10) unsigned NOT NULL COMMENT '操作ID', PRIMARY KEY (`role_id`,`operation_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8")
*
* @property int|null $roleId 角色ID
Expand Down
2 changes: 2 additions & 0 deletions src/Components/amqp/example/AMQP/Test/TestConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
* 启动一个新连接消费.
*
* @Bean("TestConsumer")
*
* @Connection(host=AMQP_SERVER_HOST, port=5672, user="guest", password="guest")
*
* @Consumer(tag="tag-imi", queue="queue-imi-1", message=\AMQPApp\AMQP\Test\TestMessage::class)
*/
class TestConsumer extends BaseConsumer
Expand Down
4 changes: 4 additions & 0 deletions src/Components/amqp/example/AMQP/Test/TestPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@

/**
* @Bean("TestPublisher")
*
* @Connection(host=AMQP_SERVER_HOST, port=5672, user="guest", password="guest")
*
* @Publisher(tag="tag-imi", queue="queue-imi-1", exchange="exchange-imi", routingKey="imi-1")
*
* @Queue(name="queue-imi-1", routingKey="imi-1")
*
* @Exchange(name="exchange-imi")
*/
class TestPublisher extends BasePublisher
Expand Down
1 change: 1 addition & 0 deletions src/Components/amqp/example/AMQP/Test2/TestConsumer2.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* 使用连接池中的连接消费.
*
* @Bean("TestConsumer2")
*
* @Consumer(tag="tag-imi", queue="queue-imi-2", message=\AMQPApp\AMQP\Test2\TestMessage2::class)
*/
class TestConsumer2 extends BaseConsumer
Expand Down
3 changes: 3 additions & 0 deletions src/Components/amqp/example/AMQP/Test2/TestPublisher2.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@

/**
* @Bean("TestPublisher2")
*
* @Publisher(tag="tag-imi", queue="queue-imi-2", exchange="exchange-imi", routingKey="imi-2")
*
* @Queue(name="queue-imi-2", routingKey="imi-2")
*
* @Exchange(name="exchange-imi")
*/
class TestPublisher2 extends BasePublisher
Expand Down
4 changes: 2 additions & 2 deletions src/Components/amqp/example/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

use function Imi\env;

use Imi\Util\Imi;

use function Imi\env;

\defined('AMQP_SERVER_HOST') || \define('AMQP_SERVER_HOST', env('AMQP_SERVER_HOST', '127.0.0.1'));

return [
Expand Down
5 changes: 2 additions & 3 deletions src/Components/amqp/tests/PHPUnitHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@

use Imi\App;
use Imi\Cli\CliApp;

use function Imi\env;

use Imi\Swoole\SwooleApp;
use PHPUnit\Runner\AfterLastTestHook;
use PHPUnit\Runner\BeforeFirstTestHook;
use Swoole\Coroutine;
use Swoole\Coroutine\Channel;

use function Imi\env;

class PHPUnitHook implements BeforeFirstTestHook, AfterLastTestHook
{
private Channel $channel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

/**
* @OA\Info(title="My First API", version="0.1")
*
* @Controller("/")
*/
class IndexController extends HttpController
Expand Down Expand Up @@ -66,8 +67,10 @@ public function multiMethod2(int $id)
* @Action
*
* @Route("register")
*
* @OA\Get(
* path="/register",
*
* @OA\Response(response="200", description="An example resource")
* )
*
Expand Down
Loading

0 comments on commit d2dc13f

Please sign in to comment.