From 333b20344e313ce55bd8caff182b4132ed6cc2dd Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sun, 22 Nov 2026 10:18:03 +0300 Subject: [PATCH 1/2] Replace Psalm with PHPStan --- .gitattributes | 2 +- .github/workflows/mutation.yml | 2 +- .github/workflows/static.yml | 8 ++++---- CHANGELOG.md | 2 +- README.md | 1 - composer.json | 4 ++-- docs/internals.md | 4 ++-- phpstan.neon | 4 ++++ psalm.xml | 18 ------------------ src/PgsqlMutex.php | 8 +++----- 10 files changed, 18 insertions(+), 35 deletions(-) create mode 100644 phpstan.neon delete mode 100644 psalm.xml diff --git a/.gitattributes b/.gitattributes index d2354a6..2955355 100644 --- a/.gitattributes +++ b/.gitattributes @@ -30,7 +30,7 @@ /.styleci.yml export-ignore /infection.json.dist export-ignore /phpunit.xml.dist export-ignore -/psalm.xml export-ignore +/phpstan.neon export-ignore /tests export-ignore /docs export-ignore diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index cd61262..c74a219 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -8,7 +8,7 @@ on: - '.github/workflows/mutation.yml' - 'composer.json' - 'infection.json.dist' - - 'psalm.xml' + - 'phpstan.neon' push: branches: ['master'] paths: *paths diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 475179e..9162c8e 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -5,7 +5,7 @@ on: paths: &paths - '.github/workflows/static.yml' - 'src/**' - - 'psalm*.xml' + - 'phpstan.neon' - 'composer.json' push: branches: ['master'] @@ -15,11 +15,11 @@ permissions: contents: read jobs: - psalm: - uses: yiisoft/actions/.github/workflows/psalm.yml@master + phpstan: + uses: yiisoft/actions/.github/workflows/phpstan.yml@master with: extensions: pdo, pdo_pgsql os: >- ['ubuntu-latest'] php: >- - ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] + ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5', '8.6'] diff --git a/CHANGELOG.md b/CHANGELOG.md index 9da5ef5..15db6e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 1.2.1 under development -- no changes in this release. +- Chg #60: Replace Psalm with PHPStan (@vjik) ## 1.2.0 November 13, 2026 diff --git a/README.md b/README.md index 5b97cd3..6801be4 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,6 @@ [![Code Coverage](https://codecov.io/gh/yiisoft/mutex-pdo-pgsql/branch/master/graph/badge.svg)](https://codecov.io/gh/yiisoft/mutex-pdo-pgsql) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fmutex-pdo-pgsql%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/mutex-pdo-pgsql/master) [![static analysis](https://github.com/yiisoft/mutex-pdo-pgsql/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/mutex-pdo-pgsql/actions?query=workflow%3A%22static+analysis%22) -[![type-coverage](https://shepherd.dev/github/yiisoft/mutex-pdo-pgsql/coverage.svg)](https://shepherd.dev/github/yiisoft/mutex-pdo-pgsql) This library provides a PostgreSQL mutex implementation for [yiisoft/mutex](https://github.com/yiisoft/mutex). diff --git a/composer.json b/composer.json index 0f4a02a..66cf28a 100644 --- a/composer.json +++ b/composer.json @@ -34,11 +34,11 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^3.95", "infection/infection": "^0.26.6 || ^0.27.10 || ^0.29.8 || ^0.35.8", + "phpstan/phpstan": "^2.3", "phpunit/phpunit": "^9.6.35", "rector/rector": "^2.8.3", "shipmonk/composer-dependency-analyser": "^1.8", "spatie/phpunit-watcher": "^1.23", - "vimeo/psalm": "^4.30 || ^5.26.1 || ^6.16.1", "yiisoft/code-style": "^1.1" }, "autoload": { @@ -61,7 +61,7 @@ "scripts": { "cs-fix": "php-cs-fixer fix", "dependency-analyser": "composer-dependency-analyser", - "psalm": "psalm", + "phpstan": "phpstan", "rector": "rector", "test": "phpunit --testdox --no-interaction", "test-watch": "phpunit-watcher watch" diff --git a/docs/internals.md b/docs/internals.md index e34dbba..1fce91a 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -18,10 +18,10 @@ The package tests are checked with [Infection](https://infection.github.io/) mut ## Static analysis -The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis: +The code is statically analyzed with [PHPStan](https://phpstan.org/). To run static analysis: ```shell -./vendor/bin/psalm +./vendor/bin/phpstan ``` ## Dependencies diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..776ccd8 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + level: max + paths: + - src diff --git a/psalm.xml b/psalm.xml deleted file mode 100644 index fa5f129..0000000 --- a/psalm.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - diff --git a/src/PgsqlMutex.php b/src/PgsqlMutex.php index 910f84e..4275c91 100644 --- a/src/PgsqlMutex.php +++ b/src/PgsqlMutex.php @@ -18,6 +18,7 @@ */ final class PgsqlMutex extends Mutex { + /** @var list */ private array $lockKeys; private PDO $connection; @@ -30,13 +31,10 @@ public function __construct(string $name, PDO $connection) /** * Decode the first eight hash bytes in big-endian order and normalize to PostgreSQL signed int4 keys. * On 32-bit PHP, unpack() already returns signed integers for words with the high bit set. - * - * @psalm-suppress PossiblyFalseArgument `unpack()` never returns `false` here because `sha1(...)` with raw - * output always returns a 20-byte string, enough for the eight bytes required by the 'N2' format. */ $this->lockKeys = array_values(array_map( - static fn(int $key): int => $key > 0x7FFFFFFF ? $key - 0x100000000 : $key, - unpack('N2', sha1($name, true)), + static fn(int $key): int => $key > 0x7FFFFFFF ? $key - 0x100000000 : $key, // @phpstan-ignore argument.type + unpack('N2', sha1($name, true)), // @phpstan-ignore argument.type )); $this->connection = $connection; From 7c1913bd286d8da196dad6b6bf4bd82b723340b7 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Sun, 22 Nov 2026 10:26:04 +0300 Subject: [PATCH 2/2] Explain why unpack() never returns false in PHPStan ignores --- src/PgsqlMutex.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/PgsqlMutex.php b/src/PgsqlMutex.php index 4275c91..32910e3 100644 --- a/src/PgsqlMutex.php +++ b/src/PgsqlMutex.php @@ -31,6 +31,9 @@ public function __construct(string $name, PDO $connection) /** * Decode the first eight hash bytes in big-endian order and normalize to PostgreSQL signed int4 keys. * On 32-bit PHP, unpack() already returns signed integers for words with the high bit set. + * + * `unpack()` never returns `false` here because `sha1(...)` with raw output always returns a 20-byte string, + * enough for the eight bytes required by the 'N2' format. */ $this->lockKeys = array_values(array_map( static fn(int $key): int => $key > 0x7FFFFFFF ? $key - 0x100000000 : $key, // @phpstan-ignore argument.type