From 544c37b66e5ed51fe34dde9ff87934a40cd868b7 Mon Sep 17 00:00:00 2001 From: sergiu Date: Thu, 26 Jun 2025 11:14:52 +0300 Subject: [PATCH 1/4] remplace psalm with phpstan Signed-off-by: sergiu --- .github/workflows/static-analysis.yml | 53 ++++ .gitignore | 1 - composer.json | 7 +- phpstan.neon | 11 + psalm-baseline.xml | 335 ---------------------- psalm.xml.dist | 33 --- src/App/Message/ExampleMessageHandler.php | 2 +- src/Swoole/Command/IsRunningTrait.php | 2 +- src/Swoole/PidManager.php | 1 - src/Swoole/ServerFactory.php | 6 +- 10 files changed, 73 insertions(+), 378 deletions(-) create mode 100644 .github/workflows/static-analysis.yml create mode 100644 phpstan.neon delete mode 100644 psalm-baseline.xml delete mode 100644 psalm.xml.dist diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..bb8ee00 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,53 @@ +on: + - push + +name: Run PHPStan checks + +jobs: + mutation: + name: PHPStan ${{ matrix.php }}-${{ matrix.os }} + + 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 + run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + + - name: Setup project + run: | + mv config/autoload/local.php.dist config/autoload/local.php + mv config/autoload/mail.local.php.dist config/autoload/mail.local.php + mv config/autoload/local.test.php.dist config/autoload/local.test.php + - name: Run static analysis with PHPStan + run: vendor/bin/phpstan analyse diff --git a/.gitignore b/.gitignore index 7c32ed3..65d0b98 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /.phpcs-cache -/.psalm-cache /.phpunit.cache /clover.xml /coveralls-upload.json diff --git a/composer.json b/composer.json index 1289d56..0ec6840 100644 --- a/composer.json +++ b/composer.json @@ -55,10 +55,11 @@ "require-dev": { "laminas/laminas-coding-standard": "^3.0", "phpunit/phpunit": "^10.5.45", - "psalm/plugin-phpunit": "^0.19.2", "roave/security-advisories": "dev-master", "swoole/ide-helper": "~5.0.0", - "vimeo/psalm": "^6.8.8" + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-doctrine": "^2.0", + "phpstan/phpstan-phpunit": "^2.0" }, "autoload": { "psr-4": { @@ -79,6 +80,6 @@ "cs-fix": "phpcbf", "test": "phpunit --colors=always", "test-coverage": "phpunit --colors=always --coverage-clover clover.xml", - "static-analysis": "psalm --shepherd --stats" + "static-analysis": "phpstan analyse" } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..db8d511 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,11 @@ +includes: + - vendor/phpstan/phpstan-doctrine/extension.neon + - vendor/phpstan/phpstan-phpunit/extension.neon +parameters: + level: 5 + paths: + - src + - test + treatPhpDocTypesAsCertain: false + ignoreErrors: + - '#Constant Queue\\Swoole\\Command\\StartCommand::PROGRAMMATIC_CONFIG_FILES is unused#' diff --git a/psalm-baseline.xml b/psalm-baseline.xml deleted file mode 100644 index 1e1b60f..0000000 --- a/psalm-baseline.xml +++ /dev/null @@ -1,335 +0,0 @@ - - - - - stabilityFlags]]> - - - - - - - - - composerDefinition['autoload']]]> - composerDefinition['autoload-dev']]]> - - - - - - - composerDefinition['autoload']['psr-4']]]> - composerDefinition['autoload']['psr-4']['MezzioInstaller\\']]]> - composerDefinition['autoload-dev']['psr-4']]]> - composerDefinition['autoload-dev']['psr-4']['MezzioInstallerTest\\']]]> - composerDefinition['scripts']['pre-install-cmd']]]> - composerDefinition['scripts']['pre-update-cmd']]]> - - - composerDefinition['autoload']['psr-4']]]> - composerDefinition['autoload']['psr-4']['App\\']]]> - composerDefinition['require'][$packageName]]]> - composerDefinition['require-dev'][$packageName]]]> - composerDefinition['scripts']['cs-check']]]> - composerDefinition['scripts']['cs-fix']]]> - - - - - - - - - - composerDefinition]]> - - - - - - composerDefinition]]> - composerDefinition]]> - composerDefinition]]> - - - installType]]> - - - - - - projectRoot]]> - - - - - - - - - - - - - installType]]]> - - - - - - - - - - - - - - - - - - - - ack]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - , - * 4: string, - * 5: string - * }>]]> - , - * 6: string, - * 7: string - * }>]]> - - - - - - - - - - - - - - - - - - - - - getValue($installer)]]> - getValue($installer)]]> - - - - - - getValue($installer)['extra']]]> - - - - - - - getInstallerProperty($installer, 'composerDefinition')]]> - getInstallerProperty($installer, 'config')]]> - - - packageRoot . '/composer.json')]]> - - - packageRoot]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - autoloader]]> - - - - container]]> - - - - - - - - - - - devDependencies]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - projectRoot . '/data')]]> - projectRoot . '/data/cache')]]> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/psalm.xml.dist b/psalm.xml.dist deleted file mode 100644 index 6211543..0000000 --- a/psalm.xml.dist +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/App/Message/ExampleMessageHandler.php b/src/App/Message/ExampleMessageHandler.php index 12804cb..b77beba 100644 --- a/src/App/Message/ExampleMessageHandler.php +++ b/src/App/Message/ExampleMessageHandler.php @@ -18,6 +18,6 @@ public function __invoke(ExampleMessage $message) /** @var Logger $logger */ $logger = $this->container->get("dot-log.queue-log"); - $logger->info("message: " . $message->getPayload()['foo'] ?? null); + $logger->info("message: " . $message->getPayload()['foo']); } } diff --git a/src/Swoole/Command/IsRunningTrait.php b/src/Swoole/Command/IsRunningTrait.php index 17c6e92..21a68f8 100644 --- a/src/Swoole/Command/IsRunningTrait.php +++ b/src/Swoole/Command/IsRunningTrait.php @@ -21,7 +21,7 @@ public function isRunning(): bool [$masterPid, $managerPid] = $pids; - if ($managerPid) { + if ($managerPid !== '') { // Swoole process mode return $masterPid && $managerPid && SwooleProcess::kill((int) $managerPid, 0); } diff --git a/src/Swoole/PidManager.php b/src/Swoole/PidManager.php index e5b66df..b21c1ab 100644 --- a/src/Swoole/PidManager.php +++ b/src/Swoole/PidManager.php @@ -39,7 +39,6 @@ public function write(int $masterPid, int $managerPid): void * Read master pid and manager pid from pid file * * @return string[] Array with master and manager PID values as strings - * @psalm-return list */ public function read(): array { diff --git a/src/Swoole/ServerFactory.php b/src/Swoole/ServerFactory.php index a88f6ce..06d13fd 100644 --- a/src/Swoole/ServerFactory.php +++ b/src/Swoole/ServerFactory.php @@ -91,11 +91,11 @@ public function __invoke(ContainerInterface $container): SwooleServer throw new InvalidArgumentException('Invalid port'); } - if (! in_array($mode, static::MODES, true)) { + if (! in_array($mode, self::MODES, true)) { throw new InvalidArgumentException('Invalid server mode'); } - $validProtocols = static::PROTOCOLS; + $validProtocols = self::PROTOCOLS; if (defined('SWOOLE_SSL')) { $validProtocols[] = SWOOLE_SOCK_TCP | SWOOLE_SSL; $validProtocols[] = SWOOLE_SOCK_TCP6 | SWOOLE_SSL; @@ -106,7 +106,7 @@ public function __invoke(ContainerInterface $container): SwooleServer } $enableCoroutine = $swooleConfig['enable_coroutine'] ?? false; - if ($enableCoroutine && method_exists(SwooleRuntime::class, 'enableCoroutine')) { + if ($enableCoroutine) { SwooleRuntime::enableCoroutine(); } From 41cb57e615e2f63c9db181d5f8d9d2943fe19892 Mon Sep 17 00:00:00 2001 From: sergiu Date: Thu, 26 Jun 2025 11:23:19 +0300 Subject: [PATCH 2/4] added setup files to static analysis Signed-off-by: sergiu --- .github/workflows/static-analysis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index bb8ee00..1e227aa 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -47,7 +47,8 @@ jobs: - name: Setup project run: | mv config/autoload/local.php.dist config/autoload/local.php - mv config/autoload/mail.local.php.dist config/autoload/mail.local.php - mv config/autoload/local.test.php.dist config/autoload/local.test.php + mv config/autoload/messenger.local.php.dist config/autoload/messenger.local.php + mv config/autoload/swoole.local.php.dist config/autoload/swoole.local.php + mv config/autoload/log.local.php.dist config/autoload/log.local.php - name: Run static analysis with PHPStan run: vendor/bin/phpstan analyse From 62499b5e14b88ab0932f296dbee2edc4ba35c7b5 Mon Sep 17 00:00:00 2001 From: sergiu Date: Thu, 26 Jun 2025 12:18:43 +0300 Subject: [PATCH 3/4] phpcs fixes Signed-off-by: sergiu --- src/Swoole/Command/IsRunningTrait.php | 4 ++-- src/Swoole/ServerFactory.php | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Swoole/Command/IsRunningTrait.php b/src/Swoole/Command/IsRunningTrait.php index 21a68f8..6e7966a 100644 --- a/src/Swoole/Command/IsRunningTrait.php +++ b/src/Swoole/Command/IsRunningTrait.php @@ -21,9 +21,9 @@ public function isRunning(): bool [$masterPid, $managerPid] = $pids; - if ($managerPid !== '') { + if ($managerPid) { // Swoole process mode - return $masterPid && $managerPid && SwooleProcess::kill((int) $managerPid, 0); + return $masterPid && SwooleProcess::kill((int) $managerPid, 0); } // Swoole base mode, no manager process diff --git a/src/Swoole/ServerFactory.php b/src/Swoole/ServerFactory.php index 06d13fd..6467207 100644 --- a/src/Swoole/ServerFactory.php +++ b/src/Swoole/ServerFactory.php @@ -15,7 +15,6 @@ use function defined; use function in_array; use function is_array; -use function method_exists; use const SWOOLE_BASE; use const SWOOLE_PROCESS; From 9496cef9718f0baed9fc3f41f8fbb2aca9fb68af Mon Sep 17 00:00:00 2001 From: sergiu Date: Thu, 26 Jun 2025 13:23:11 +0300 Subject: [PATCH 4/4] added test folder Signed-off-by: sergiu --- composer.json | 3 ++- src/Swoole/ServerFactory.php | 2 +- test/SwooleConfigProviderTest.php | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 test/SwooleConfigProviderTest.php diff --git a/composer.json b/composer.json index 0ec6840..3876e10 100644 --- a/composer.json +++ b/composer.json @@ -74,7 +74,8 @@ "scripts": { "check": [ "@cs-check", - "@test" + "@test", + "@static-analysis" ], "cs-check": "phpcs", "cs-fix": "phpcbf", diff --git a/src/Swoole/ServerFactory.php b/src/Swoole/ServerFactory.php index 6467207..d5a1124 100644 --- a/src/Swoole/ServerFactory.php +++ b/src/Swoole/ServerFactory.php @@ -106,7 +106,7 @@ public function __invoke(ContainerInterface $container): SwooleServer $enableCoroutine = $swooleConfig['enable_coroutine'] ?? false; if ($enableCoroutine) { - SwooleRuntime::enableCoroutine(); + SwooleRuntime::enableCoroutine(true); } $httpServer = new SwooleServer($host, $port, $mode, $protocol); diff --git a/test/SwooleConfigProviderTest.php b/test/SwooleConfigProviderTest.php new file mode 100644 index 0000000..8647eb6 --- /dev/null +++ b/test/SwooleConfigProviderTest.php @@ -0,0 +1,23 @@ +config = (new ConfigProvider())(); + } + + public function testHasDependencies(): void + { + $this->assertArrayHasKey('dependencies', $this->config); + } +}