From 775f00cadc61a4bb1f26d6f43f067fb86c7df6ca Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Wed, 25 Nov 2026 13:56:55 +0300 Subject: [PATCH] Replace Psalm with PHPStan --- .github/workflows/bc.yml | 4 +- .github/workflows/build.yml | 4 +- .../workflows/composer-require-checker.yml | 4 +- .github/workflows/mutation.yml | 4 +- .github/workflows/rector.yml | 2 +- .github/workflows/static.yml | 37 ++++++++----------- CHANGELOG.md | 2 +- README.md | 1 - composer.json | 2 + docs/internals.md | 4 +- phpstan.neon | 5 +++ psalm.xml | 17 --------- src/MessageSource.php | 14 +++---- tools/psalm/composer.json | 5 --- 14 files changed, 40 insertions(+), 65 deletions(-) create mode 100644 phpstan.neon delete mode 100644 psalm.xml delete mode 100644 tools/psalm/composer.json diff --git a/.github/workflows/bc.yml b/.github/workflows/bc.yml index 0577a84..88ef133 100644 --- a/.github/workflows/bc.yml +++ b/.github/workflows/bc.yml @@ -8,7 +8,7 @@ on: - '.gitattributes' - 'infection.json.dist' - 'phpunit.xml.dist' - - 'psalm.xml' + - 'phpstan.neon' push: branches: ['master'] paths-ignore: @@ -19,7 +19,7 @@ on: - '.gitattributes' - 'infection.json.dist' - 'phpunit.xml.dist' - - 'psalm.xml' + - 'phpstan.neon' name: backwards compatibility diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 699f7c5..4b01b21 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ on: - '.gitignore' - '.gitattributes' - 'infection.json.dist' - - 'psalm.xml' + - 'phpstan.neon' push: branches: ['master'] @@ -18,7 +18,7 @@ on: - '.gitignore' - '.gitattributes' - 'infection.json.dist' - - 'psalm.xml' + - 'phpstan.neon' name: build diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml index 1685ae9..94e40b3 100644 --- a/.github/workflows/composer-require-checker.yml +++ b/.github/workflows/composer-require-checker.yml @@ -8,7 +8,7 @@ on: - '.gitattributes' - 'infection.json.dist' - 'phpunit.xml.dist' - - 'psalm.xml' + - 'phpstan.neon' push: branches: ['master'] @@ -20,7 +20,7 @@ on: - '.gitattributes' - 'infection.json.dist' - 'phpunit.xml.dist' - - 'psalm.xml' + - 'phpstan.neon' name: Composer require checker diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index ce83871..d468e0d 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -6,7 +6,7 @@ on: - 'CHANGELOG.md' - '.gitignore' - '.gitattributes' - - 'psalm.xml' + - 'phpstan.neon' push: branches: ['master'] @@ -16,7 +16,7 @@ on: - 'CHANGELOG.md' - '.gitignore' - '.gitattributes' - - 'psalm.xml' + - 'phpstan.neon' name: mutation test diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml index 5fd2d0a..3a84646 100644 --- a/.github/workflows/rector.yml +++ b/.github/workflows/rector.yml @@ -7,7 +7,7 @@ on: - '.gitignore' - '.gitattributes' - 'infection.json.dist' - - 'psalm.xml' + - 'phpstan.neon' name: rector diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 4099d39..f41f859 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -1,35 +1,28 @@ +name: static analysis + on: pull_request: - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'phpunit.xml.dist' - + paths: &paths + - 'src/**' + - 'phpstan.neon' + - 'composer.json' + - '.github/workflows/static.yml' push: branches: ['master'] - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'phpunit.xml.dist' - -name: static analysis + paths: *paths permissions: contents: read +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: - psalm: - uses: yiisoft/actions/.github/workflows/psalm.yml@master + phpstan: + uses: yiisoft/actions/.github/workflows/phpstan.yml@master with: os: >- ['ubuntu-latest'] php: >- - ['8.0', '8.1', '8.2', '8.3', '8.4'] + ['8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] diff --git a/CHANGELOG.md b/CHANGELOG.md index 79c2088..9d4220e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 1.1.3 under development -- no changes in this release. +- Chg #90: Replace Psalm with PHPStan (@vjik) ## 1.1.2 December 06, 2025 diff --git a/README.md b/README.md index 78cc05e..942f7bc 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,6 @@ [![Code Coverage](https://codecov.io/gh/yiisoft/translator-message-php/branch/master/graph/badge.svg)](https://codecov.io/gh/yiisoft/translator-message-php) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Ftranslator-message-php%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/translator-message-php/master) [![static analysis](https://github.com/yiisoft/translator-message-php/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/translator-message-php/actions?query=workflow%3A%22static+analysis%22) -[![type-coverage](https://shepherd.dev/github/yiisoft/translator-message-php/coverage.svg)](https://shepherd.dev/github/yiisoft/translator-message-php) The package provides message storage backend based on PHP arrays to be used with [`yiisoft/translator`](https://github.com/yiisoft/translator) package. diff --git a/composer.json b/composer.json index c7f43d2..da0c906 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ "require-dev": { "bamarni/composer-bin-plugin": "^1.8.3", "maglnet/composer-require-checker": "^4.4", + "phpstan/phpstan": "^2.3", "phpunit/phpunit": "^9.6.22", "rector/rector": "^2.0.10", "spatie/phpunit-watcher": "^1.23.6" @@ -64,6 +65,7 @@ } }, "scripts": { + "phpstan": "phpstan", "test": "phpunit --testdox --no-interaction", "test-watch": "phpunit-watcher watch" } diff --git a/docs/internals.md b/docs/internals.md index 087a514..04865dc 100644 --- a/docs/internals.md +++ b/docs/internals.md @@ -19,10 +19,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 ``` ## Code style diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..b74b10f --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,5 @@ +parameters: + level: max + paths: + - src + treatPhpDocTypesAsCertain: false diff --git a/psalm.xml b/psalm.xml deleted file mode 100644 index 1f7607c..0000000 --- a/psalm.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - diff --git a/src/MessageSource.php b/src/MessageSource.php index d9deda9..3520ca1 100644 --- a/src/MessageSource.php +++ b/src/MessageSource.php @@ -16,7 +16,7 @@ final class MessageSource implements MessageReaderInterface, MessageWriterInterface { /** - * @psalm-var array>> + * @var array>> */ private array $messages = []; @@ -43,13 +43,13 @@ public function getMessages(string $category, string $locale): array foreach ($messages as &$message) { $message = ['message' => $message]; } - /** @psalm-var array> $messages */ + /** @var array> $messages */ return $messages; } /** - * @psalm-param array> $messages + * @param array> $messages */ public function write(string $category, string $locale, array $messages): void { @@ -87,7 +87,7 @@ private function read(string $category, string $locale): void if (!is_array($messages)) { throw new RuntimeException('Invalid file format: ' . $path); } - /** @psalm-var array $messages */ + /** @var array $messages */ } else { $messages = []; } @@ -96,7 +96,7 @@ private function read(string $category, string $locale): void } /** - * @psalm-param array> $messages + * @param array> $messages */ private function generateMessagesFileContent(array $messages): string { @@ -113,7 +113,7 @@ private function generateMessagesFileContent(array $messages): string } /** - * @psalm-param array> $messages + * @param array> $messages */ private function messagesToCode(array $messages): string { @@ -123,13 +123,11 @@ private function messagesToCode(array $messages): string throw new InvalidArgumentException("Message is not valid for ID \"$messageId\". \"message\" key is missing."); } - /** @psalm-suppress DocblockTypeContradiction */ if (!is_string($messageData['message'])) { throw new InvalidArgumentException("Message is not a string for ID \"$messageId\"."); } if (array_key_exists('comment', $messageData)) { - /** @psalm-suppress DocblockTypeContradiction */ if (!is_string($messageData['comment'])) { throw new InvalidArgumentException("Message comment is not a string for ID \"$messageId\"."); } diff --git a/tools/psalm/composer.json b/tools/psalm/composer.json deleted file mode 100644 index 0cbdf97..0000000 --- a/tools/psalm/composer.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "require-dev": { - "vimeo/psalm": "^5.26.1 || ^6.8.9" - } -}