From f4eef1f0c6cd43084a82d3321ebaea238bacc136 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 15 Mar 2025 13:58:48 +0100 Subject: [PATCH 01/13] devenv: Make direnv reload on flake changes We do not use `flake` direnv feature since flakes currently copy the whole repo into Nix store, so we need to watch the files manually. --- .envrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.envrc b/.envrc index 1d953f4..1b5ce28 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,2 @@ use nix +watch_file flake.nix flake.lock From b0ea6bcb951e72597b77d17ec24cec96eae163e8 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 15 Mar 2025 14:01:17 +0100 Subject: [PATCH 02/13] ci: Update actions --- .github/workflows/main.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index da0908a..d4171de 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -10,7 +10,7 @@ env: jobs: tests: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: matrix: php: @@ -27,13 +27,13 @@ jobs: phpstan: true name: 'Check with PHP ${{ matrix.php }}' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install Nix - uses: cachix/install-nix-action@v20 + uses: cachix/install-nix-action@v31 - name: Set up Nix cache - uses: cachix/cachix-action@v12 + uses: cachix/cachix-action@v16 with: # Use cache from https://github.com/fossar/nix-phps name: fossar @@ -46,7 +46,7 @@ jobs: run: | echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT" - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} From 2db54e07758e646808cba838dfa00f626efc0d2d Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 15 Mar 2025 14:01:59 +0100 Subject: [PATCH 03/13] gitignore: Add some annoying files --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 987e2a2..ad6cb61 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ composer.lock -vendor +vendor/ +.direnv/ +.php-cs-fixer.cache +.phpunit.result.cache From 8094799ac1b08b1840b9fee1f01b1959b582e6b0 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 15 Mar 2025 14:03:58 +0100 Subject: [PATCH 04/13] phpstan: Rename config to use dist suffix This allows developer to create their own own config file, e.g. for setting `editorUrl`: https://phpstan.org/user-guide/output-format#opening-file-in-an-editor --- .gitignore | 1 + phpstan.neon => phpstan.dist.neon | 0 2 files changed, 1 insertion(+) rename phpstan.neon => phpstan.dist.neon (100%) diff --git a/.gitignore b/.gitignore index ad6cb61..5509604 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ vendor/ .direnv/ .php-cs-fixer.cache .phpunit.result.cache +phpstan.neon diff --git a/phpstan.neon b/phpstan.dist.neon similarity index 100% rename from phpstan.neon rename to phpstan.dist.neon From fabb6a06ba55716732365d89018ff10062054e14 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 15 Mar 2025 14:06:33 +0100 Subject: [PATCH 05/13] Install PHPStan through composer It has isolated dependencies nowadays and it will be helpful for other developers, who probably expect it to be installed that way and do not want to use Nix. Do the same with PHP-CS-Fixer. --- composer.json | 4 +++- flake.nix | 3 --- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 642dfad..a43b28d 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,9 @@ "php": ">=7.2.5" }, "require-dev": { - "symfony/phpunit-bridge": "^6.2" + "symfony/phpunit-bridge": "^6.2", + "phpstan/phpstan": "^1.12", + "friendsofphp/php-cs-fixer": "^3.4" }, "suggest": { "ext-mbstring": "For using the MbTranscoder", diff --git a/flake.nix b/flake.nix index 70de764..3700333 100644 --- a/flake.nix +++ b/flake.nix @@ -48,9 +48,6 @@ # Composer and PHP. php phpBase.packages.composer - - phpBase.packages.php-cs-fixer - phpBase.packages.phpstan ]; }; }; From 0bf5a8f99f808b95c6d34d4dcf5d41d459fdc6c0 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 15 Mar 2025 14:07:06 +0100 Subject: [PATCH 06/13] flake.lock: Update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flake lock file updates: • Updated input 'phps': 'github:fossar/nix-phps/181dee32f3d47312674462cff30fcca661c6c643' (2023-03-05) → 'github:fossar/nix-phps/e48727edd2dbbbd7b9181bd284569554f6e4e5a6' (2025-03-10) • Updated input 'phps/flake-compat': 'github:edolstra/flake-compat/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9' (2023-01-17) → 'github:edolstra/flake-compat/ff81ac966bb2cae68946d5ed5fc4994f96d0ffec' (2024-12-04) • Updated input 'phps/nixpkgs': 'github:NixOS/nixpkgs/f5ffd5787786dde3a8bf648c7a1b5f78c4e01abb' (2023-03-03) → 'github:NixOS/nixpkgs/de0fe301211c267807afd11b12613f5511ff7433' (2025-03-07) • Updated input 'phps/utils': 'github:numtide/flake-utils/3db36a8b464d0c4532ba1c7dda728f4576d6d073' (2023-02-13) → 'github:numtide/flake-utils/11707dc2f618dd54ca8739b309ec4fc024de578b' (2024-11-13) • Added input 'phps/utils/systems': 'github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e' (2023-04-09) --- flake.lock | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/flake.lock b/flake.lock index 6b23d4c..ed532a6 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "flake-compat": { "flake": false, "locked": { - "lastModified": 1673956053, - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "lastModified": 1733328505, + "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", "owner": "edolstra", "repo": "flake-compat", - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", "type": "github" }, "original": { @@ -18,11 +18,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1677852945, - "narHash": "sha256-liiVJjkBTuBTAkRW3hrI8MbPD2ImYzwUpa7kvteiKhM=", + "lastModified": 1741310760, + "narHash": "sha256-aizILFrPgq/W53Jw8i0a1h1GZAAKtlYOrG/A5r46gVM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "f5ffd5787786dde3a8bf648c7a1b5f78c4e01abb", + "rev": "de0fe301211c267807afd11b12613f5511ff7433", "type": "github" }, "original": { @@ -39,11 +39,11 @@ "utils": "utils" }, "locked": { - "lastModified": 1678028979, - "narHash": "sha256-qFSN1sKlavyqUl9Vz60+iniYbTLfXtdAwFmTDdlLN5o=", + "lastModified": 1741586946, + "narHash": "sha256-EI5TFGNt2ObkK8MdBASS9LVkWT0qTqOljFFP2+RjZI0=", "owner": "fossar", "repo": "nix-phps", - "rev": "181dee32f3d47312674462cff30fcca661c6c643", + "rev": "e48727edd2dbbbd7b9181bd284569554f6e4e5a6", "type": "github" }, "original": { @@ -57,13 +57,31 @@ "phps": "phps" } }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "utils": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1676283394, - "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", "owner": "numtide", "repo": "flake-utils", - "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { From 52c84e2dae0a176ea540af3ed5c3acea7f1f4b57 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 15 Mar 2025 14:08:45 +0100 Subject: [PATCH 07/13] composer: Allow phpunit-bridge 7 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a43b28d..8254773 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "php": ">=7.2.5" }, "require-dev": { - "symfony/phpunit-bridge": "^6.2", + "symfony/phpunit-bridge": "^6.2 || ^7.0", "phpstan/phpstan": "^1.12", "friendsofphp/php-cs-fixer": "^3.4" }, From 8d309bd4ba9d2b5b3f9dbb2247011ac2fcc8e849 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 15 Mar 2025 14:09:08 +0100 Subject: [PATCH 08/13] ci: Check PHP 8.4 and PHP 8.3 --- .github/workflows/main.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index d4171de..1528552 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -14,6 +14,8 @@ jobs: strategy: matrix: php: + - '8.4' + - '8.3' - '8.2' - '8.1' - '8.0' From 976d0f40f137fbcb76b3c691f77e00c2652ebdc5 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 15 Mar 2025 14:10:08 +0100 Subject: [PATCH 09/13] devenv: Install Phpactor This is a Language Server Provider for PHP. --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 3700333..5230e64 100644 --- a/flake.nix +++ b/flake.nix @@ -48,6 +48,7 @@ # Composer and PHP. php phpBase.packages.composer + pkgs.phpactor ]; }; }; From 2a7809a6e3f8da3a22454b1cd9d2767f18f3be9b Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 15 Mar 2025 16:30:47 +0100 Subject: [PATCH 10/13] devenv: Provide locale archive Without this, the Iconv tests on CI started to fail in `setLocale` invocation: PHPUnit\Framework\Exception: The locale functionality is not implemented on your platform, the specified locale does not exist or the category name is invalid. /home/runner/work/transcoder/transcoder/tests/IconvTranscoderTest.php:25 --- flake.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flake.nix b/flake.nix index 5230e64..44217c7 100644 --- a/flake.nix +++ b/flake.nix @@ -50,6 +50,10 @@ phpBase.packages.composer pkgs.phpactor ]; + + env = pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { + LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive"; + }; }; }; } From ac7fc2ccc69ec73193aa1d3d58fbb71083d6ed8e Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 15 Mar 2025 16:49:11 +0100 Subject: [PATCH 11/13] Raise minimum PHP version to 7.4 https://www.php.net/releases/7_3_0.php https://www.php.net/releases/7_4_0.php This installed a newer version of CS Fixer - friendsofphp/php-cs-fixer updated from v3.4.0 to v3.72.0 minor See changes: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/compare/FriendsOfPHP:v3.4.0...PHP-CS-Fixer:v3.72.0 Release notes: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/tag/v3.72.0 - `no_superfluous_phpdoc_tags` removes `inheritdoc`. - `phpdoc_to_param_type` did its thing in one place. As a result, I had to fix some rules: - Disable `phpdoc_to_param_type` since it now tries to use union type in a param type hint, which is only supported on PHP 8.0. Also enable PHP 7.3 migration in PHP-CS-Fixer, although there was nothing to do. --- .github/workflows/main.yaml | 2 -- .php-cs-fixer.php | 6 +++--- CHANGELOG.md | 1 + composer.json | 4 ++-- src/IconvTranscoder.php | 3 --- src/MbTranscoder.php | 2 -- src/Transcoder.php | 3 --- 7 files changed, 6 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 1528552..6095ec7 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -20,8 +20,6 @@ jobs: - '8.1' - '8.0' - '7.4' - - '7.3' - - '7.2' include: - php: '7.4' cs_fixer: true diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index bd56d62..0ce1789 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -5,9 +5,9 @@ $rules = [ '@Symfony' => true, - '@PHP71Migration' => true, - '@PHP71Migration:risky' => true, - 'phpdoc_to_param_type' => true, + '@PHP74Migration' => true, + '@PHP74Migration:risky' => true, + // 'phpdoc_to_param_type' => true, // requires PHP 8.0 'phpdoc_to_return_type' => true, // overwrite some Symfony rules 'concat_space' => ['spacing' => 'one'], diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ed47bf..92654a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [3.0.0] – unreleased - Mb: Make encoding detection stricter. +- Raise minimum PHP version to 7.4.0. ## [2.0.0] – 2023-03-07 diff --git a/composer.json b/composer.json index 8254773..84ba200 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "ddeboer/transcoder": "self.version" }, "require": { - "php": ">=7.2.5" + "php": ">=7.4.0" }, "require-dev": { "symfony/phpunit-bridge": "^6.2 || ^7.0", @@ -36,7 +36,7 @@ }, "config": { "platform": { - "php": "7.2.5" + "php": "7.4.0" } }, "scripts": { diff --git a/src/IconvTranscoder.php b/src/IconvTranscoder.php index ff09cc3..6347957 100644 --- a/src/IconvTranscoder.php +++ b/src/IconvTranscoder.php @@ -29,9 +29,6 @@ public function __construct(string $defaultEncoding = 'UTF-8') $this->defaultEncoding = $defaultEncoding; } - /** - * {@inheritdoc} - */ public function transcode(string $string, ?string $from = null, ?string $to = null): string { set_error_handler( diff --git a/src/MbTranscoder.php b/src/MbTranscoder.php index 232f44e..986e44e 100644 --- a/src/MbTranscoder.php +++ b/src/MbTranscoder.php @@ -43,8 +43,6 @@ public function __construct(string $defaultEncoding = 'UTF-8') } /** - * {@inheritdoc} - * * @param array|string|null $from */ public function transcode(string $string, $from = null, ?string $to = null): string diff --git a/src/Transcoder.php b/src/Transcoder.php index 7f71782..99370d2 100644 --- a/src/Transcoder.php +++ b/src/Transcoder.php @@ -27,9 +27,6 @@ public function __construct(array $transcoders) $this->transcoders = $transcoders; } - /** - * {@inheritdoc} - */ public function transcode(string $string, ?string $from = null, ?string $to = null): string { foreach ($this->transcoders as $transcoder) { From f396153d37da7150d502542129724977df9c7086 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 15 Mar 2025 17:00:09 +0100 Subject: [PATCH 12/13] Use property type hints Not a BC break since all of them are private. Had to change an initialization check in `MbTranscoder::__construct`, since PHPStan figured out it is not nullable. --- .php-cs-fixer.php | 1 + src/IconvTranscoder.php | 5 +---- src/MbTranscoder.php | 9 +++------ src/Transcoder.php | 4 ++-- tests/IconvTranscoderTest.php | 5 +---- tests/MbTranscoderTest.php | 5 +---- tests/TranscoderTest.php | 5 +---- 7 files changed, 10 insertions(+), 24 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 0ce1789..f0f592f 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -7,6 +7,7 @@ '@Symfony' => true, '@PHP74Migration' => true, '@PHP74Migration:risky' => true, + 'phpdoc_to_property_type' => true, // 'phpdoc_to_param_type' => true, // requires PHP 8.0 'phpdoc_to_return_type' => true, // overwrite some Symfony rules diff --git a/src/IconvTranscoder.php b/src/IconvTranscoder.php index 6347957..09da620 100644 --- a/src/IconvTranscoder.php +++ b/src/IconvTranscoder.php @@ -10,10 +10,7 @@ class IconvTranscoder implements TranscoderInterface { - /** - * @var string - */ - private $defaultEncoding; + private string $defaultEncoding; /** * Create an Iconv-based transcoder. diff --git a/src/MbTranscoder.php b/src/MbTranscoder.php index 986e44e..e8826e2 100644 --- a/src/MbTranscoder.php +++ b/src/MbTranscoder.php @@ -13,12 +13,9 @@ class MbTranscoder implements TranscoderInterface /** * @var array */ - private static $encodings; + private static array $encodings; - /** - * @var string - */ - private $defaultEncoding; + private string $defaultEncoding; /** * Create a Mb-based transcoder. @@ -31,7 +28,7 @@ public function __construct(string $defaultEncoding = 'UTF-8') throw new ExtensionMissingException('mb'); } - if (null === self::$encodings) { + if (!isset(self::$encodings)) { self::$encodings = array_change_key_case( array_flip(mb_list_encodings()), CASE_LOWER diff --git a/src/Transcoder.php b/src/Transcoder.php index 99370d2..f43b0d8 100644 --- a/src/Transcoder.php +++ b/src/Transcoder.php @@ -12,12 +12,12 @@ class Transcoder implements TranscoderInterface /** * @var array */ - private static $chain; + private static array $chain; /** * @var TranscoderInterface[] */ - private $transcoders = []; + private array $transcoders = []; /** * @param TranscoderInterface[] $transcoders diff --git a/tests/IconvTranscoderTest.php b/tests/IconvTranscoderTest.php index 64f8aa8..95eda5f 100644 --- a/tests/IconvTranscoderTest.php +++ b/tests/IconvTranscoderTest.php @@ -8,10 +8,7 @@ class IconvTranscoderTest extends \PHPUnit\Framework\TestCase { - /** - * @var IconvTranscoder - */ - private $transcoder; + private IconvTranscoder $transcoder; /** * @before diff --git a/tests/MbTranscoderTest.php b/tests/MbTranscoderTest.php index 97e9077..6735d71 100644 --- a/tests/MbTranscoderTest.php +++ b/tests/MbTranscoderTest.php @@ -8,10 +8,7 @@ class MbTranscoderTest extends \PHPUnit\Framework\TestCase { - /** - * @var MbTranscoder - */ - private $transcoder; + private MbTranscoder $transcoder; /** * @before diff --git a/tests/TranscoderTest.php b/tests/TranscoderTest.php index d1d78a6..77f7b89 100644 --- a/tests/TranscoderTest.php +++ b/tests/TranscoderTest.php @@ -9,10 +9,7 @@ class TranscoderTest extends \PHPUnit\Framework\TestCase { - /** - * @var TranscoderInterface - */ - private $transcoder; + private TranscoderInterface $transcoder; /** * @before From b4f81262ec12e3f9b3c8b3beaa6f95b28bba8240 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 15 Mar 2025 17:17:20 +0100 Subject: [PATCH 13/13] Upgrade PHPStan to version 2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - phpstan/phpstan updated from 1.12.21 to 2.1.8 major See changes: https://github.com/phpstan/phpstan/compare/1.12.21...2.1.8 Release notes Had to remove redundant assertion. Not clear when false can actually occur on PHP ≥ 8.0 – on PHP 7.4, it can happen when passing an invalid target encoding but on PHP 8.0, it just throws a `ValueError`. --- composer.json | 2 +- src/MbTranscoder.php | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 84ba200..1575f4f 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "require-dev": { "symfony/phpunit-bridge": "^6.2 || ^7.0", - "phpstan/phpstan": "^1.12", + "phpstan/phpstan": "^2.1", "friendsofphp/php-cs-fixer": "^3.4" }, "suggest": { diff --git a/src/MbTranscoder.php b/src/MbTranscoder.php index e8826e2..91ca423 100644 --- a/src/MbTranscoder.php +++ b/src/MbTranscoder.php @@ -72,9 +72,6 @@ public function transcode(string $string, $from = null, ?string $to = null): str $from ); - // For PHPStan: We check the encoding is valid. - assert($result !== false); - return $result; }