diff --git a/.php_cs b/.php_cs index 9c552f9e..e6077b74 100644 --- a/.php_cs +++ b/.php_cs @@ -14,17 +14,20 @@ return PhpCsFixer\Config::create() ->setRules([ '@PSR2' => true, 'header_comment' => [ - 'commentType' => 'PHPDoc', - 'header' => $header, - 'separate' => 'none' + 'comment_type' => 'PHPDoc', + 'header' => $header, + 'separate' => 'bottom' ], 'array_syntax' => [ 'syntax' => 'short' ], + 'encoding' => true, // MUST use only UTF-8 without BOM 'single_quote' => true, 'class_attributes_separation' => true, 'no_unused_imports' => true, + 'global_namespace_import' => true, 'standardize_not_equals' => true, + 'declare_strict_types' => true, ]) ->setFinder( PhpCsFixer\Finder::create() diff --git a/.travis.yml b/.travis.yml index 88baa188..99b79dc5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ install: - | echo "no" | pecl install -f redis - | - wget https://github.com/swoole/swoole-src/archive/v4.4.15.tar.gz -O swoole.tar.gz && mkdir -p swoole && tar -xf swoole.tar.gz -C swoole --strip-components=1 && rm swoole.tar.gz && cd swoole && phpize && ./configure && make -j$(nproc) && make install && cd - && rm -rf swoole + wget https://github.com/swoole/swoole-src/archive/v4.4.17.tar.gz -O swoole.tar.gz && mkdir -p swoole && tar -xf swoole.tar.gz -C swoole --strip-components=1 && rm swoole.tar.gz && cd swoole && phpize && ./configure && make -j$(nproc) && make install && cd - && rm -rf swoole echo "extension = swoole.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - | wget -O bin/php-cs-fixer "https://cs.symfony.com/download/php-cs-fixer-v2.phar" @@ -21,10 +21,11 @@ install: before_script: - phpenv config-rm xdebug.ini + - bin/php-cs-fixer -V - composer config -g process-timeout 900 && composer update - composer require --dev phpstan/phpstan script: - - composer cs-fix + - composer check-cs - composer test # - php bin/swoft dinfo:env diff --git a/app/Annotation/Parser/AlphaDashParser.php b/app/Annotation/Parser/AlphaDashParser.php index a4d91280..fbd4d1a7 100644 --- a/app/Annotation/Parser/AlphaDashParser.php +++ b/app/Annotation/Parser/AlphaDashParser.php @@ -10,10 +10,10 @@ namespace App\Annotation\Parser; +use App\Annotation\Mapping\AlphaDash; use ReflectionException; use Swoft\Annotation\Annotation\Mapping\AnnotationParser; use Swoft\Annotation\Annotation\Parser\Parser; -use App\Annotation\Mapping\AlphaDash; use Swoft\Validator\Exception\ValidatorException; use Swoft\Validator\ValidatorRegister; @@ -25,7 +25,7 @@ class AlphaDashParser extends Parser { /** - * @param int $type + * @param int $type * @param object $annotationObject * * @return array diff --git a/app/Aspect/BeanAspect.php b/app/Aspect/BeanAspect.php index bffadecf..69ec0120 100644 --- a/app/Aspect/BeanAspect.php +++ b/app/Aspect/BeanAspect.php @@ -10,10 +10,10 @@ namespace App\Aspect; +use App\Common\MyBean; use Swoft\Aop\Annotation\Mapping\Aspect; use Swoft\Aop\Annotation\Mapping\Before; use Swoft\Aop\Annotation\Mapping\PointBean; -use App\Common\MyBean; use function vdump; /** diff --git a/app/Common/MyBean.php b/app/Common/MyBean.php index a6cd49b7..0a1c0e10 100644 --- a/app/Common/MyBean.php +++ b/app/Common/MyBean.php @@ -1,4 +1,12 @@ getConfig(); + return bean(GoodsData::class)->getConfig(); } } diff --git a/app/Http/Controller/SessionController.php b/app/Http/Controller/SessionController.php index 4feab237..bd38c278 100644 --- a/app/Http/Controller/SessionController.php +++ b/app/Http/Controller/SessionController.php @@ -89,7 +89,7 @@ public function get(): array public function del(): array { $sess = HttpSession::current(); - $ok = $sess->delete('testKey'); + $ok = $sess->delete('testKey'); return ['delete' => $ok]; } diff --git a/app/Http/Controller/TimerController.php b/app/Http/Controller/TimerController.php index 881d26a6..260099c1 100644 --- a/app/Http/Controller/TimerController.php +++ b/app/Http/Controller/TimerController.php @@ -12,13 +12,13 @@ use App\Model\Entity\User; use Exception; -use function random_int; use Swoft\Http\Server\Annotation\Mapping\Controller; use Swoft\Http\Server\Annotation\Mapping\RequestMapping; use Swoft\Log\Helper\Log; use Swoft\Redis\Redis; use Swoft\Stdlib\Helper\JsonHelper; use Swoft\Timer; +use function random_int; /** * Class TimerController diff --git a/app/Listener/RegisterServiceListener.php b/app/Listener/RegisterServiceListener.php index fdf7a71a..61d0d14a 100644 --- a/app/Listener/RegisterServiceListener.php +++ b/app/Listener/RegisterServiceListener.php @@ -16,7 +16,6 @@ use Swoft\Event\EventHandlerInterface; use Swoft\Event\EventInterface; use Swoft\Http\Server\HttpServer; -use Swoft\Log\Helper\CLog; use Swoft\Server\SwooleEvent; /** @@ -63,7 +62,7 @@ public function handle(EventInterface $event): void // Register -// $this->agent->registerService($service); -// CLog::info('Swoft http register service success by consul!'); + // $this->agent->registerService($service); + // CLog::info('Swoft http register service success by consul!'); } } diff --git a/app/Model/Data/GoodsData.php b/app/Model/Data/GoodsData.php index 7ada0517..f8ed89dd 100644 --- a/app/Model/Data/GoodsData.php +++ b/app/Model/Data/GoodsData.php @@ -1,4 +1,12 @@ toArray(); - CLog::info('user='.json_encode($user)); + CLog::info('user=' . json_encode($user)); // Redis Redis::set('test', 'ok'); - CLog::info('test='.Redis::get('test')); + CLog::info('test=' . Redis::get('test')); Coroutine::sleep(3); } diff --git a/app/Model/Logic/RequestBean.php b/app/Model/Logic/RequestBean.php index 47ec47f6..3f573570 100644 --- a/app/Model/Logic/RequestBean.php +++ b/app/Model/Logic/RequestBean.php @@ -21,6 +21,9 @@ */ class RequestBean { + /** + * @var array + */ public $temp = []; /** @@ -36,7 +39,7 @@ public function getData(): array * * @return string */ - public function getName(string $type):string + public function getName(string $type): string { return 'name'; } diff --git a/app/Process/Worker2Process.php b/app/Process/Worker2Process.php index 78aa45e5..68708222 100644 --- a/app/Process/Worker2Process.php +++ b/app/Process/Worker2Process.php @@ -40,13 +40,13 @@ public function run(Pool $pool, int $workerId): void // Database $user = User::find(1)->toArray(); - CLog::info('user='.json_encode($user)); + CLog::info('user=' . json_encode($user)); // Redis Redis::set('test', 'ok'); - CLog::info('test='.Redis::get('test')); + CLog::info('test=' . Redis::get('test')); - CLog::info('worker-' . $workerId.' context='.context()->getWorkerId()); + CLog::info('worker-' . $workerId . ' context=' . context()->getWorkerId()); Coroutine::sleep(3); } diff --git a/app/Rpc/Lib/UserInterface.php b/app/Rpc/Lib/UserInterface.php index f4a27948..7b4d4db0 100644 --- a/app/Rpc/Lib/UserInterface.php +++ b/app/Rpc/Lib/UserInterface.php @@ -41,7 +41,7 @@ public function getBigContent(): string; /** * @return void */ - public function returnNull():void ; + public function returnNull(): void; /** * Exception diff --git a/app/Rpc/Service/UserService.php b/app/Rpc/Service/UserService.php index 10123836..2c98f2f1 100644 --- a/app/Rpc/Service/UserService.php +++ b/app/Rpc/Service/UserService.php @@ -12,6 +12,7 @@ use App\Rpc\Lib\UserInterface; use Exception; +use RuntimeException; use Swoft\Co; use Swoft\Rpc\Server\Annotation\Mapping\Service; @@ -51,7 +52,6 @@ public function delete(int $id): bool */ public function returnNull(): void { - return; } /** @@ -59,17 +59,17 @@ public function returnNull(): void */ public function getBigContent(): string { - $content = Co::readFile(__DIR__ . '/big.data'); - return $content; + return Co::readFile(__DIR__ . '/big.data'); } /** * Exception + * * @throws Exception */ public function exception(): void { - throw new Exception('exception version'); + throw new RuntimeException('exception version'); } /** diff --git a/app/Rpc/Service/UserServiceV2.php b/app/Rpc/Service/UserServiceV2.php index 561db6c1..3b068d61 100644 --- a/app/Rpc/Service/UserServiceV2.php +++ b/app/Rpc/Service/UserServiceV2.php @@ -68,6 +68,7 @@ public function getBigContent(): string /** * Exception + * * @throws Exception */ public function exception(): void diff --git a/app/Task/Listener/FinishListener.php b/app/Task/Listener/FinishListener.php index 40fbb356..2e9a8ff6 100644 --- a/app/Task/Listener/FinishListener.php +++ b/app/Task/Listener/FinishListener.php @@ -10,12 +10,12 @@ namespace App\Task\Listener; -use function context; use Swoft\Event\Annotation\Mapping\Listener; use Swoft\Event\EventHandlerInterface; use Swoft\Event\EventInterface; use Swoft\Log\Helper\CLog; use Swoft\Task\TaskEvent; +use function context; /** * Class FinishListener diff --git a/app/Tcp/Middleware/DemoMiddleware.php b/app/Tcp/Middleware/DemoMiddleware.php index df76cba3..8e1ff42c 100644 --- a/app/Tcp/Middleware/DemoMiddleware.php +++ b/app/Tcp/Middleware/DemoMiddleware.php @@ -12,8 +12,8 @@ use Swoft\Bean\Annotation\Mapping\Bean; use Swoft\Log\Helper\CLog; -use Swoft\Tcp\Server\Contract\RequestHandlerInterface; use Swoft\Tcp\Server\Contract\MiddlewareInterface; +use Swoft\Tcp\Server\Contract\RequestHandlerInterface; use Swoft\Tcp\Server\Contract\RequestInterface; use Swoft\Tcp\Server\Contract\ResponseInterface; diff --git a/app/Tcp/Middleware/GlobalTcpMiddleware.php b/app/Tcp/Middleware/GlobalTcpMiddleware.php index 06df847b..8823e250 100644 --- a/app/Tcp/Middleware/GlobalTcpMiddleware.php +++ b/app/Tcp/Middleware/GlobalTcpMiddleware.php @@ -12,8 +12,8 @@ use Swoft\Bean\Annotation\Mapping\Bean; use Swoft\Log\Helper\CLog; -use Swoft\Tcp\Server\Contract\RequestHandlerInterface; use Swoft\Tcp\Server\Contract\MiddlewareInterface; +use Swoft\Tcp\Server\Contract\RequestHandlerInterface; use Swoft\Tcp\Server\Contract\RequestInterface; use Swoft\Tcp\Server\Contract\ResponseInterface; diff --git a/app/Validator/CustomerValidator.php b/app/Validator/CustomerValidator.php index 576e2cf4..fd30a923 100644 --- a/app/Validator/CustomerValidator.php +++ b/app/Validator/CustomerValidator.php @@ -33,7 +33,7 @@ class CustomerValidator implements ValidatorInterface public function validate(array $data, array $params): array { $start = $data['start'] ?? null; - $end = $data['end'] ?? null; + $end = $data['end'] ?? null; if ($start === null && $end === null) { throw new ValidatorException('Start time and end time cannot be empty'); } diff --git a/app/WebSocket/EchoModule.php b/app/WebSocket/EchoModule.php index 1c97cf0b..834102be 100644 --- a/app/WebSocket/EchoModule.php +++ b/app/WebSocket/EchoModule.php @@ -17,7 +17,6 @@ use Swoft\WebSocket\Server\Annotation\Mapping\WsModule; use Swoole\WebSocket\Frame; use Swoole\WebSocket\Server; -use function server; /** * Class EchoModule diff --git a/app/WebSocket/Test/TestController.php b/app/WebSocket/Test/TestController.php index fd7d7b6f..734c279f 100644 --- a/app/WebSocket/Test/TestController.php +++ b/app/WebSocket/Test/TestController.php @@ -42,6 +42,7 @@ public function index(): void /** * Message command is: 'test.index' + * * @param Message $msg * * @return void diff --git a/app/bean.php b/app/bean.php index 293ba200..5c498433 100644 --- a/app/bean.php +++ b/app/bean.php @@ -1,4 +1,4 @@ - [ @@ -31,12 +28,12 @@ 'applicationHandler' => [ 'logFile' => '@runtime/logs/error-%d{Y-m-d}.log', ], - 'logger' => [ + 'logger' => [ 'flushRequest' => false, 'enable' => false, 'json' => false, ], - 'httpServer' => [ + 'httpServer' => [ 'class' => HttpServer::class, 'port' => 18306, 'listener' => [ @@ -44,16 +41,16 @@ // 'tcp' => bean('tcpServer'), ], 'process' => [ -// 'monitor' => bean(MonitorProcess::class) -// 'crontab' => bean(CrontabProcess::class) + // 'monitor' => bean(MonitorProcess::class) + // 'crontab' => bean(CrontabProcess::class) ], 'on' => [ -// SwooleEvent::TASK => bean(SyncTaskListener::class), // Enable sync task + // SwooleEvent::TASK => bean(SyncTaskListener::class), // Enable sync task SwooleEvent::TASK => bean(TaskListener::class), // Enable task must task and finish event SwooleEvent::FINISH => bean(FinishListener::class) ], /* @see HttpServer::$setting */ - 'setting' => [ + 'setting' => [ 'task_worker_num' => 12, 'task_enable_coroutine' => true, 'worker_num' => 6, @@ -62,7 +59,7 @@ // 'document_root' => dirname(__DIR__) . '/public', ] ], - 'httpDispatcher' => [ + 'httpDispatcher' => [ // Add global http middleware 'middlewares' => [ \App\Http\Middleware\FavIconMiddleware::class, @@ -75,38 +72,38 @@ \Swoft\Http\Server\Middleware\ValidatorMiddleware::class ] ], - 'db' => [ + 'db' => [ 'class' => Database::class, 'dsn' => 'mysql:dbname=test;host=127.0.0.1', 'username' => 'root', 'password' => 'swoft123456', - 'charset' => 'utf8mb4', + 'charset' => 'utf8mb4', ], - 'db2' => [ - 'class' => Database::class, - 'dsn' => 'mysql:dbname=test2;host=127.0.0.1', - 'username' => 'root', - 'password' => 'swoft123456', -// 'dbSelector' => bean(DbSelector::class) + 'db2' => [ + 'class' => Database::class, + 'dsn' => 'mysql:dbname=test2;host=127.0.0.1', + 'username' => 'root', + 'password' => 'swoft123456', + // 'dbSelector' => bean(DbSelector::class) ], - 'db2.pool' => [ + 'db2.pool' => [ 'class' => Pool::class, 'database' => bean('db2'), ], - 'db3' => [ + 'db3' => [ 'class' => Database::class, 'dsn' => 'mysql:dbname=test2;host=127.0.0.1', 'username' => 'root', 'password' => 'swoft123456' ], - 'db3.pool' => [ + 'db3.pool' => [ 'class' => Pool::class, 'database' => bean('db3') ], - 'migrationManager' => [ + 'migrationManager' => [ 'migrationPath' => '@database/Migration', ], - 'redis' => [ + 'redis' => [ 'class' => RedisDb::class, 'host' => '127.0.0.1', 'port' => 6379, @@ -115,7 +112,7 @@ 'prefix' => 'swoft:' ] ], - 'user' => [ + 'user' => [ 'class' => ServiceClient::class, 'host' => '127.0.0.1', 'port' => 18307, @@ -127,35 +124,36 @@ ], 'packet' => bean('rpcClientPacket') ], - 'user.pool' => [ + 'user.pool' => [ 'class' => ServicePool::class, 'client' => bean('user'), ], - 'rpcServer' => [ + 'rpcServer' => [ 'class' => ServiceServer::class, ], - 'wsServer' => [ - 'class' => WebSocketServer::class, - 'port' => 18308, + 'wsServer' => [ + 'class' => WebSocketServer::class, + 'port' => 18308, 'listener' => [ 'rpc' => bean('rpcServer'), // 'tcp' => bean('tcpServer'), ], - 'on' => [ + 'on' => [ // Enable http handle SwooleEvent::REQUEST => bean(RequestListener::class), // Enable task must add task and finish event - SwooleEvent::TASK => bean(TaskListener::class), - SwooleEvent::FINISH => bean(FinishListener::class) + SwooleEvent::TASK => bean(TaskListener::class), + SwooleEvent::FINISH => bean(FinishListener::class) ], - 'debug' => 1, + 'debug' => 1, // 'debug' => env('SWOFT_DEBUG', 0), /* @see WebSocketServer::$setting */ - 'setting' => [ + 'setting' => [ 'task_worker_num' => 6, 'task_enable_coroutine' => true, 'worker_num' => 6, - 'log_file' => alias('@runtime/swoole.log'), + 'log_file' => alias('@runtime/swoole.log'), + // 'open_websocket_close_frame' => true, ], ], // 'wsConnectionManager' => [ @@ -165,29 +163,28 @@ // 'class' => \Swoft\Session\SwooleStorage::class, // ], /** @see \Swoft\WebSocket\Server\WsMessageDispatcher */ - 'wsMsgDispatcher' => [ + 'wsMsgDispatcher' => [ 'middlewares' => [ \App\WebSocket\Middleware\GlobalWsMiddleware::class ], ], /** @see \Swoft\Tcp\Server\TcpServer */ - 'tcpServer' => [ + 'tcpServer' => [ 'port' => 18309, 'debug' => 1, ], /** @see \Swoft\Tcp\Protocol */ - 'tcpServerProtocol' => [ + 'tcpServerProtocol' => [ // 'type' => \Swoft\Tcp\Packer\JsonPacker::TYPE, 'type' => \Swoft\Tcp\Packer\SimpleTokenPacker::TYPE, // 'openLengthCheck' => true, ], /** @see \Swoft\Tcp\Server\TcpDispatcher */ - 'tcpDispatcher' => [ + 'tcpDispatcher' => [ 'middlewares' => [ \App\Tcp\Middleware\GlobalTcpMiddleware::class ], ], - 'cliRouter' => [ - // 'disabledGroups' => ['demo', 'test'], + 'cliRouter' => [// 'disabledGroups' => ['demo', 'test'], ], ]; diff --git a/bin/bootstrap.php b/bin/bootstrap.php index e246bf47..23ef91ab 100644 --- a/bin/bootstrap.php +++ b/bin/bootstrap.php @@ -1,4 +1,4 @@ -addPsr4('SwoftTest\\Testing\\', $vendor . '/swoft/framework/test/testing/'); -$application = new TestApplication([ - 'basePath' => $baseDir, -]); +$application = new TestApplication($baseDir); $application->setBeanFile($baseDir . '/app/bean.php'); $application->run(); diff --git a/test/run.php b/test/run.php index 057ec7a4..631c2ab0 100755 --- a/test/run.php +++ b/test/run.php @@ -1,4 +1,4 @@ -