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 diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index da0908a..6095ec7 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -10,16 +10,16 @@ env: jobs: tests: - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest strategy: matrix: php: + - '8.4' + - '8.3' - '8.2' - '8.1' - '8.0' - '7.4' - - '7.3' - - '7.2' include: - php: '7.4' cs_fixer: true @@ -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') }} diff --git a/.gitignore b/.gitignore index 987e2a2..5509604 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ composer.lock -vendor +vendor/ +.direnv/ +.php-cs-fixer.cache +.phpunit.result.cache +phpstan.neon diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index bd56d62..f0f592f 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -5,9 +5,10 @@ $rules = [ '@Symfony' => true, - '@PHP71Migration' => true, - '@PHP71Migration:risky' => true, - 'phpdoc_to_param_type' => 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 '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 642dfad..1575f4f 100644 --- a/composer.json +++ b/composer.json @@ -17,10 +17,12 @@ "ddeboer/transcoder": "self.version" }, "require": { - "php": ">=7.2.5" + "php": ">=7.4.0" }, "require-dev": { - "symfony/phpunit-bridge": "^6.2" + "symfony/phpunit-bridge": "^6.2 || ^7.0", + "phpstan/phpstan": "^2.1", + "friendsofphp/php-cs-fixer": "^3.4" }, "suggest": { "ext-mbstring": "For using the MbTranscoder", @@ -34,7 +36,7 @@ }, "config": { "platform": { - "php": "7.2.5" + "php": "7.4.0" } }, "scripts": { 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": { diff --git a/flake.nix b/flake.nix index 70de764..44217c7 100644 --- a/flake.nix +++ b/flake.nix @@ -48,10 +48,12 @@ # Composer and PHP. php phpBase.packages.composer - - phpBase.packages.php-cs-fixer - phpBase.packages.phpstan + pkgs.phpactor ]; + + env = pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { + LOCALE_ARCHIVE = "${pkgs.glibcLocales}/lib/locale/locale-archive"; + }; }; }; } diff --git a/phpstan.neon b/phpstan.dist.neon similarity index 100% rename from phpstan.neon rename to phpstan.dist.neon diff --git a/src/IconvTranscoder.php b/src/IconvTranscoder.php index ff09cc3..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. @@ -29,9 +26,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..91ca423 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 @@ -43,8 +40,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 @@ -77,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; } diff --git a/src/Transcoder.php b/src/Transcoder.php index 7f71782..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 @@ -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) { 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