From c0b339f159bda31bc418444f3ed27e7e1ee0e861 Mon Sep 17 00:00:00 2001 From: sergiu Date: Wed, 25 Jun 2025 15:20:27 +0300 Subject: [PATCH 1/2] updated workflow files and fixed phpcs errors Signed-off-by: sergiu --- .github/workflows/create-project.yml | 37 ---------- .../workflows/release-on-milestone-closed.yml | 71 ------------------- 2 files changed, 108 deletions(-) delete mode 100644 .github/workflows/create-project.yml delete mode 100644 .github/workflows/release-on-milestone-closed.yml diff --git a/.github/workflows/create-project.yml b/.github/workflows/create-project.yml deleted file mode 100644 index b766742..0000000 --- a/.github/workflows/create-project.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: "Create Project" - -on: - pull_request: - push: - branches: - - '[0-9]+.[0-9]+.x' - - 'refs/pull/*' - tags: - -jobs: - build: - strategy: - matrix: - php_version: - - '@latest' - - '@lowest' - runs-on: ubuntu-latest - timeout-minutes: 3 - steps: - - name: Checkout CI environment - uses: laminas/laminas-continuous-integration-action@v1 - with: - php: ${{ matrix.php_version }} - - name: Checkout sourcecode - uses: actions/checkout@v4 - - name: Test create-project - run: | - rm composer.lock - cd .. - yes 1 | composer create-project mezzio/mezzio-skeleton test-new-project \ - --repository='{"type": "path", "url": "./mezzio-skeleton"}' --stability=dev - ls -la test-new-project - cd test-new-project - test -f config/container.php - test -f config/routes.php - echo "Successfully created project" diff --git a/.github/workflows/release-on-milestone-closed.yml b/.github/workflows/release-on-milestone-closed.yml deleted file mode 100644 index 87cabfb..0000000 --- a/.github/workflows/release-on-milestone-closed.yml +++ /dev/null @@ -1,71 +0,0 @@ -# Alternate workflow example. -# This one is identical to the one in release-on-milestone.yml, with one change: -# the Release step uses the ORGANIZATION_ADMIN_TOKEN instead, to allow it to -# trigger a release workflow event. This is useful if you have other actions -# that intercept that event. - -name: "Automatic Releases" - -on: - milestone: - types: - - "closed" - -jobs: - release: - name: "GIT tag, release & create merge-up PR" - runs-on: ubuntu-latest - - steps: - - name: "Checkout" - uses: "actions/checkout@v4" - - - name: "Release" - uses: "laminas/automatic-releases@v1" - with: - command-name: "laminas:automatic-releases:release" - env: - "GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }} - "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} - "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} - "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} - - - name: "Create Merge-Up Pull Request" - uses: "laminas/automatic-releases@v1" - with: - command-name: "laminas:automatic-releases:create-merge-up-pull-request" - env: - "GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} - "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} - "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} - "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} - - - name: "Create and/or Switch to new Release Branch" - uses: "laminas/automatic-releases@v1" - with: - command-name: "laminas:automatic-releases:switch-default-branch-to-next-minor" - env: - "GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }} - "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} - "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} - "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} - - - name: "Bump Changelog Version On Originating Release Branch" - uses: "laminas/automatic-releases@v1" - with: - command-name: "laminas:automatic-releases:bump-changelog" - env: - "GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} - "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} - "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} - "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} - - - name: "Create new milestones" - uses: "laminas/automatic-releases@v1" - with: - command-name: "laminas:automatic-releases:create-milestones" - env: - "GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} - "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} - "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} - "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} From 9df684968f5c1f72234cf25051add902525047ff Mon Sep 17 00:00:00 2001 From: sergiu Date: Wed, 25 Jun 2025 15:22:34 +0300 Subject: [PATCH 2/2] new workflow files and phpcs errors Signed-off-by: sergiu --- .github/workflows/codecov.yml | 56 +++++++++++++++++++ .github/workflows/continuous-integration.yml | 26 +-------- .github/workflows/qodana_code_quality.yml | 48 ++++++++++++++++ composer.json | 32 ++--------- config/autoload/cli.global.php | 16 ++++-- config/pipeline.php | 3 - src/App/ConfigProvider.php | 36 ++++++------ src/App/Message/ExampleMessage.php | 8 +-- src/App/Message/ExampleMessageHandler.php | 6 +- .../Message/ExampleMessageHandlerFactory.php | 7 ++- .../Command/Factory/StartCommandFactory.php | 5 +- .../Command/Factory/StopCommandFactory.php | 4 +- src/Swoole/Command/IsRunningTrait.php | 7 ++- src/Swoole/Command/StartCommand.php | 26 ++++----- src/Swoole/Command/StopCommand.php | 32 +++++------ src/Swoole/ConfigProvider.php | 12 ++-- src/Swoole/Delegators/TCPServerDelegator.php | 18 +++--- src/Swoole/PidManager.php | 13 ++++- src/Swoole/PidManagerFactory.php | 6 +- src/Swoole/ServerFactory.php | 9 ++- 20 files changed, 229 insertions(+), 141 deletions(-) create mode 100644 .github/workflows/codecov.yml create mode 100644 .github/workflows/qodana_code_quality.yml diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 0000000..704f224 --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,56 @@ +on: + - push + +name: Run Codecov checks + +jobs: + code-coverage: + name: Code Coverage + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: + - ubuntu-latest + + php: + - "8.2" + - "8.3" + - "8.4" + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "${{ matrix.php }}" + coverage: pcov + ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On + tools: composer:v2, cs2pr + + - name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - name: Cache dependencies installed with composer + uses: actions/cache@v4 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer- + + - name: Install dependencies with composer + env: + COMPOSER_DEV_MODE: 1 + run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Collect code coverage with PHPUnit + run: vendor/bin/phpunit --colors=always --coverage-clover clover.xml + + - name: Send code coverage report to Codecov.io + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index fe5f1b4..26c5802 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -4,30 +4,8 @@ on: pull_request: push: branches: - - '[0-9]+.[0-9]+.x' - - 'refs/pull/*' tags: jobs: - matrix: - name: Generate job matrix - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.matrix.outputs.matrix }} - steps: - - name: Gather CI configuration - id: matrix - uses: laminas/laminas-ci-matrix-action@v1 - - qa: - name: QA Checks - needs: [matrix] - runs-on: ${{ matrix.operatingSystem }} - strategy: - fail-fast: false - matrix: ${{ fromJSON(needs.matrix.outputs.matrix) }} - steps: - - name: ${{ matrix.name }} - uses: laminas/laminas-continuous-integration-action@v1 - with: - job: ${{ matrix.job }} \ No newline at end of file + ci: + uses: laminas/workflow-continuous-integration/.github/workflows/continuous-integration.yml@1.x diff --git a/.github/workflows/qodana_code_quality.yml b/.github/workflows/qodana_code_quality.yml new file mode 100644 index 0000000..3cd2eb2 --- /dev/null +++ b/.github/workflows/qodana_code_quality.yml @@ -0,0 +1,48 @@ +name: Qodana +on: + workflow_dispatch: + pull_request: + push: + branches: + - 'main' + +jobs: + qodana: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + checks: write + strategy: + matrix: + php-versions: [ '8.2', '8.3', '8.4'] + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit + fetch-depth: 0 # a full history is required for pull request analysis + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + coverage: pcov + ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On + tools: composer:v2, cs2pr + + - name: Determine composer cache directory + run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + + - name: Cache dependencies installed with composer + uses: actions/cache@v4 + with: + path: ${{ env.COMPOSER_CACHE_DIR }} + key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: | + php${{ matrix.php }}-composer- + + - name: Install dependencies with composer + run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + - name: 'Qodana Scan' + uses: JetBrains/qodana-action@v2025.1 + env: + QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} diff --git a/composer.json b/composer.json index 7dad9bc..1289d56 100644 --- a/composer.json +++ b/composer.json @@ -53,6 +53,7 @@ "symfony/redis-messenger": "^v7.2.3" }, "require-dev": { + "laminas/laminas-coding-standard": "^3.0", "phpunit/phpunit": "^10.5.45", "psalm/plugin-phpunit": "^0.19.2", "roave/security-advisories": "dev-master", @@ -66,39 +67,18 @@ }, "autoload-dev": { "psr-4": { + "DotTest\\Mail\\": "test/" } }, "scripts": { - "development-disable": "laminas-development-mode disable", - "development-enable": "laminas-development-mode enable", - "development-status": "laminas-development-mode status", - "mezzio": "laminas --ansi", "check": [ "@cs-check", "@test" ], - "clear-config-cache": "php bin/clear-config-cache.php", - "enable-codestandard": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run", - "cs-check": [ - "@enable-codestandard", - "phpcs -s" - ], - "cs-fix": [ - "@enable-codestandard", - "phpcbf" - ], - "serve": [ - "Composer\\Config::disableProcessTimeout", - "php -S 0.0.0.0:8080 -t public/" - ], - "static-analysis": "psalm --stats", - "static-analysis-update-baseline": "psalm --stats --update-baseline", + "cs-check": "phpcs", + "cs-fix": "phpcbf", "test": "phpunit --colors=always", - "test-coverage": "phpunit --colors=always --coverage-clover clover.xml" - }, - "scripts-descriptions": { - "clear-config-cache": "Clears merged config cache. Required for config changes to be applied.", - "static-analysis": "Run static analysis tool Psalm.", - "static-analysis-update-baseline": "Run static analysis tool Psalm and update baseline." + "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", + "static-analysis": "psalm --shepherd --stats" } } diff --git a/config/autoload/cli.global.php b/config/autoload/cli.global.php index 6b4697a..08644ea 100644 --- a/config/autoload/cli.global.php +++ b/config/autoload/cli.global.php @@ -1,20 +1,26 @@ [ 'version' => '1.0.0', 'name' => 'DotKernel CLI', 'commands' => [ - "swoole:start" => \Queue\Swoole\Command\StartCommand::class, - "swoole:stop" => \Queue\Swoole\Command\StopCommand::class, - "messenger:start" => \Symfony\Component\Messenger\Command\ConsumeMessagesCommand::class, - "messenger:debug" => \Symfony\Component\Messenger\Command\DebugCommand::class + "swoole:start" => StartCommand::class, + "swoole:stop" => StopCommand::class, + "messenger:start" => ConsumeMessagesCommand::class, + "messenger:debug" => DebugCommand::class, ], ], FileLockerInterface::class => [ 'enabled' => false, 'dirPath' => getcwd() . '/data/lock', ], -]; \ No newline at end of file +]; diff --git a/config/pipeline.php b/config/pipeline.php index 591f78d..2ea0a65 100644 --- a/config/pipeline.php +++ b/config/pipeline.php @@ -34,7 +34,6 @@ // - $app->pipe('/docs', $apiDocMiddleware); // - $app->pipe('/files', $filesMiddleware); - // The following handle routing failures for common conditions: // - HEAD request but no routes answer that method // - OPTIONS request but no routes answer that method @@ -53,9 +52,7 @@ // Register the dispatch middleware in the middleware pipeline - // At this point, if no Response is returned by any middleware, the // NotFoundHandler kicks in; alternately, you can provide other fallback // middleware to execute. - }; diff --git a/src/App/ConfigProvider.php b/src/App/ConfigProvider.php index 13bab83..2cc0d51 100644 --- a/src/App/ConfigProvider.php +++ b/src/App/ConfigProvider.php @@ -1,8 +1,9 @@ $this->getDependencies(), - 'symfony' => [ + 'symfony' => [ 'messenger' => [ 'buses' => $this->busConfig(), ], @@ -27,28 +28,28 @@ public function __invoke() ]; } - - private function getDependencies() + private function getDependencies(): array { return [ "factories" => [ - "message_bus" => [MessageBusStaticFactory::class, "message_bus"], - "message_bus_stamp_middleware" => [BusNameStampMiddlewareStaticFactory::class, "message_bus"], - "message_bus_sender_middleware" => [MessageSenderMiddlewareStaticFactory::class, "message_bus"], + "message_bus" => [MessageBusStaticFactory::class, "message_bus"], + "message_bus_stamp_middleware" => [BusNameStampMiddlewareStaticFactory::class, "message_bus"], + "message_bus_sender_middleware" => [MessageSenderMiddlewareStaticFactory::class, "message_bus"], "message_bus_handler_middleware" => [MessageHandlerMiddlewareStaticFactory::class, "message_bus"], - ExampleMessageHandler::class => ExampleMessageHandlerFactory::class + ExampleMessageHandler::class => ExampleMessageHandlerFactory::class, + ], + "aliases" => [ + MessageBusInterface::class => "message_bus", ], - "aliases" => [ - MessageBusInterface::class => "message_bus" - ] ]; } - private function busConfig() + private function busConfig(): array { return [ "message_bus" => [ - 'allows_zero_handlers' => false, // Means that it's an error if no handlers are defined for a given message + // Means that it's an error if no handlers are defined for a given message + 'allows_zero_handlers' => false, /** * Each bus needs middleware to do anything useful. @@ -67,10 +68,9 @@ private function busConfig() * * Two locators are shipped, 1 message type to 1 handler and 1 message type to many handlers. * Both locators operate on the basis that handlers are available in the container. - * */ 'handler_locator' => OneToManyFqcnContainerHandlerLocator::class, - 'handlers' => [ + 'handlers' => [ ExampleMessage::class => [ExampleMessageHandler::class], ], @@ -89,7 +89,7 @@ private function busConfig() 'routes' => [ ExampleMessage::class => ["redis_transport"], ], - ] + ], ]; } -} \ No newline at end of file +} diff --git a/src/App/Message/ExampleMessage.php b/src/App/Message/ExampleMessage.php index ef8e66d..d094f4d 100644 --- a/src/App/Message/ExampleMessage.php +++ b/src/App/Message/ExampleMessage.php @@ -1,18 +1,18 @@ payload; } - -} \ No newline at end of file +} diff --git a/src/App/Message/ExampleMessageHandler.php b/src/App/Message/ExampleMessageHandler.php index 65392a1..12804cb 100644 --- a/src/App/Message/ExampleMessageHandler.php +++ b/src/App/Message/ExampleMessageHandler.php @@ -1,9 +1,12 @@ container->get("dot-log.queue-log"); $logger->info("message: " . $message->getPayload()['foo'] ?? null); } -} \ No newline at end of file +} diff --git a/src/App/Message/ExampleMessageHandlerFactory.php b/src/App/Message/ExampleMessageHandlerFactory.php index f7704f1..900ae44 100644 --- a/src/App/Message/ExampleMessageHandlerFactory.php +++ b/src/App/Message/ExampleMessageHandlerFactory.php @@ -1,14 +1,15 @@ get(PidManager::class)); } -} \ No newline at end of file +} diff --git a/src/Swoole/Command/IsRunningTrait.php b/src/Swoole/Command/IsRunningTrait.php index a7e8306..17c6e92 100644 --- a/src/Swoole/Command/IsRunningTrait.php +++ b/src/Swoole/Command/IsRunningTrait.php @@ -1,5 +1,7 @@ pidManager->read(); @@ -27,5 +29,4 @@ public function isRunning() : bool // Swoole base mode, no manager process return $masterPid && SwooleProcess::kill((int) $masterPid, 0); } - -} \ No newline at end of file +} diff --git a/src/Swoole/Command/StartCommand.php b/src/Swoole/Command/StartCommand.php index c7fe1a4..de74e40 100644 --- a/src/Swoole/Command/StartCommand.php +++ b/src/Swoole/Command/StartCommand.php @@ -1,16 +1,19 @@ container->get(SwooleServer::class); - $config = $this->container->get('config'); + $server = $this->container->get(SwooleServer::class); + $config = $this->container->get('config'); $processName = $config['dotkernel-queue-swoole']['swoole-server']['process-name'] ?? self::DEFAULT_PROCESS_NAME; @@ -81,7 +82,4 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 0; } - - - -} \ No newline at end of file +} diff --git a/src/Swoole/Command/StopCommand.php b/src/Swoole/Command/StopCommand.php index bb5bd59..614b544 100644 --- a/src/Swoole/Command/StopCommand.php +++ b/src/Swoole/Command/StopCommand.php @@ -1,5 +1,7 @@ killProcess = Closure::fromCallable([SwooleProcess::class, 'kill']); - $this->pidManager = $pidManager; + $this->pidManager = $pidManager; parent::__construct($name); } - protected function configure() : void + protected function configure(): void { $this->setDescription('Stop the web server.'); $this->setHelp(self::HELP); } - protected function execute(InputInterface $input, OutputInterface $output) : int + protected function execute(InputInterface $input, OutputInterface $output): int { if (! $this->isRunning()) { $output->writeln('Server is not running'); @@ -74,11 +76,11 @@ protected function execute(InputInterface $input, OutputInterface $output) : int return 0; } - private function stopServer() : bool + private function stopServer(): bool { - [$masterPid, ] = $this->pidManager->read(); - $startTime = time(); - $result = ($this->killProcess)((int) $masterPid); + [$masterPid] = $this->pidManager->read(); + $startTime = time(); + $result = ($this->killProcess)((int) $masterPid); while (! $result) { if (! ($this->killProcess)((int) $masterPid, 0)) { @@ -99,6 +101,4 @@ private function stopServer() : bool return true; } - - -} \ No newline at end of file +} diff --git a/src/Swoole/ConfigProvider.php b/src/Swoole/ConfigProvider.php index c3cef28..a468298 100644 --- a/src/Swoole/ConfigProvider.php +++ b/src/Swoole/ConfigProvider.php @@ -1,5 +1,7 @@ $this->getDependencies(), + 'dependencies' => $this->getDependencies(), ]; } @@ -26,11 +28,11 @@ public function getDependencies(): array ], "factories" => [ TCPSwooleServer::class => ServerFactory::class, - PidManager::class => PidManagerFactory::class, - StartCommand::class => StartCommandFactory::class, - StopCommand::class => StopCommandFactory::class + PidManager::class => PidManagerFactory::class, + StartCommand::class => StartCommandFactory::class, + StopCommand::class => StopCommandFactory::class, ], "aliases" => [], ]; } -} \ No newline at end of file +} diff --git a/src/Swoole/Delegators/TCPServerDelegator.php b/src/Swoole/Delegators/TCPServerDelegator.php index 30786d9..a5e6a48 100644 --- a/src/Swoole/Delegators/TCPServerDelegator.php +++ b/src/Swoole/Delegators/TCPServerDelegator.php @@ -1,9 +1,10 @@ on('receive', function ($server, $fd, $from_id, $data) use ($logger, $bus) { - + $server->on('receive', function ($server, $fd, $fromId, $data) use ($logger, $bus) { $bus->dispatch(new ExampleMessage(["foo" => $data])); $bus->dispatch(new ExampleMessage(["foo" => "with 5 seconds delay"]), [ - new DelayStamp(5000) + new DelayStamp(5000), ]); $server->send($fd, "Server: {$data}"); $logger->notice("Request received on receive", [ - 'fd' => $fd, - 'from_id' => $from_id + 'fd' => $fd, + 'from_id' => $fromId, ]); }); @@ -46,7 +46,5 @@ public function __invoke(ContainerInterface $container, string $serviceName, cal }); return $server; - } - -} \ No newline at end of file +} diff --git a/src/Swoole/PidManager.php b/src/Swoole/PidManager.php index a347d07..e5b66df 100644 --- a/src/Swoole/PidManager.php +++ b/src/Swoole/PidManager.php @@ -1,9 +1,20 @@