From 9fdb771b1d04e57b7ad82fe01a367a37075e47d2 Mon Sep 17 00:00:00 2001 From: Saif Eddin Gmati <29315886+azjezz@users.noreply.github.com> Date: Sat, 6 Nov 2021 06:09:56 +0100 Subject: [PATCH] chore(php): fix PHP 8.1 deprecations (#255) Signed-off-by: azjezz --- .github/workflows/unit-tests.yml | 1 + Makefile | 4 +-- composer.json | 2 +- src/Psl/Internal/internal_encoding.php | 18 +++------- src/Psl/Iter/Iterator.php | 4 +-- tests/unit/Str/WidthTest.php | 3 -- tools/php-cs-fixer/composer.lock | 50 +++++++++++++------------- 7 files changed, 36 insertions(+), 46 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index c623413d..eb7b3e26 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -14,6 +14,7 @@ jobs: matrix: php-version: - "8.0" + - "8.1" operating-system: - "macos-latest" - "ubuntu-latest" diff --git a/Makefile b/Makefile index 4c6c0bca..bfd6d238 100644 --- a/Makefile +++ b/Makefile @@ -20,11 +20,11 @@ install-unit-tests-dependencies: install-root-dependencies install: install-root-dependencies install-coding-standard-dependencies install-benchmark-dependencies install-static-analysis-dependencies install-unit-tests-dependencies ## install all dependencies for a development environment coding-standard-fix: ## apply automated coding standard fixes - ./tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=tools/php-cs-fixer/.php_cs.dist.php + PHP_CS_FIXER_IGNORE_ENV=1 ./tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=tools/php-cs-fixer/.php_cs.dist.php ./tools/php-codesniffer/vendor/bin/phpcbf --basepath=. --standard=tools/php-codesniffer/.phpcs.xml coding-standard-check: ## check coding-standard compliance - ./tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=tools/php-cs-fixer/.php_cs.dist.php --dry-run + PHP_CS_FIXER_IGNORE_ENV=1 ./tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=tools/php-cs-fixer/.php_cs.dist.php --dry-run ./tools/php-codesniffer/vendor/bin/phpcs --basepath=. --standard=tools/php-codesniffer/.phpcs.xml benchmarks: ## run benchmarks diff --git a/composer.json b/composer.json index 8f758b98..6212d997 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": "^8.0", + "php": "~8.0.0 || ~8.1.0", "ext-bcmath": "*", "ext-json": "*", "ext-mbstring": "*", diff --git a/src/Psl/Internal/internal_encoding.php b/src/Psl/Internal/internal_encoding.php index 52680634..297ce977 100644 --- a/src/Psl/Internal/internal_encoding.php +++ b/src/Psl/Internal/internal_encoding.php @@ -6,7 +6,6 @@ use Psl; use Psl\Exception; -use Psl\Type; use function mb_internal_encoding; @@ -17,23 +16,16 @@ */ function internal_encoding(?string $encoding = null): string { - Psl\invariant(null === $encoding || is_encoding_valid($encoding), 'Invalid encoding.'); if (null !== $encoding) { + Psl\invariant(is_encoding_valid($encoding), 'Invalid encoding.'); + return $encoding; } /** * @psalm-suppress ImpureFunctionCall + * + * @var string */ - $internal_encoding = mb_internal_encoding(); - - /** - * @psalm-suppress ImpureFunctionCall - see https://github.com/azjezz/psl/issues/130 - * @psalm-suppress ImpureMethodCall - see https://github.com/azjezz/psl/issues/130 - */ - if (Type\string()->matches($internal_encoding)) { - return $internal_encoding; - } - - return 'UTF-8'; + return mb_internal_encoding() ?: 'UTF-8'; } diff --git a/src/Psl/Iter/Iterator.php b/src/Psl/Iter/Iterator.php index 872c300f..037c2f72 100644 --- a/src/Psl/Iter/Iterator.php +++ b/src/Psl/Iter/Iterator.php @@ -87,7 +87,7 @@ public static function create(iterable $iterable): Iterator * * @return Tv */ - public function current() + public function current(): mixed { Psl\invariant($this->valid(), 'The Iterator is invalid.'); if (!contains_key($this->entries, $this->position)) { @@ -127,7 +127,7 @@ public function next(): void * * @return Tk */ - public function key() + public function key(): mixed { Psl\invariant($this->valid(), 'The Iterator is invalid.'); if (!contains_key($this->entries, $this->position)) { diff --git a/tests/unit/Str/WidthTest.php b/tests/unit/Str/WidthTest.php index 45178216..a8896d3c 100644 --- a/tests/unit/Str/WidthTest.php +++ b/tests/unit/Str/WidthTest.php @@ -21,10 +21,8 @@ public function provideData(): array { return [ [5, 'Hello'], - [5, '☕ ☕ ☕'], [1, '⏟'], [5, '⸺⸺⸺⸺⸺'], - [12, '♈♉♊♋♌♍♎♏♐♑♒♓'], [1, '༇'], [12, 'héllö, wôrld'], [9, 'مرحبا بكم'], @@ -33,7 +31,6 @@ public function provideData(): array [4, 'تونس'], [3, 'سيف'], [14, 'こんにちは世界'], - [3, '🥇🥈🥉'], [4, '你好'], [6, 'สวัสดี'], [3, 'ؤخى'] diff --git a/tools/php-cs-fixer/composer.lock b/tools/php-cs-fixer/composer.lock index 4299db6a..4ea10f35 100644 --- a/tools/php-cs-fixer/composer.lock +++ b/tools/php-cs-fixer/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "composer/semver", - "version": "3.2.5", + "version": "3.2.6", "source": { "type": "git", "url": "https://github.com/composer/semver.git", - "reference": "31f3ea725711245195f62e54ffa402d8ef2fdba9" + "reference": "83e511e247de329283478496f7a1e114c9517506" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/31f3ea725711245195f62e54ffa402d8ef2fdba9", - "reference": "31f3ea725711245195f62e54ffa402d8ef2fdba9", + "url": "https://api.github.com/repos/composer/semver/zipball/83e511e247de329283478496f7a1e114c9517506", + "reference": "83e511e247de329283478496f7a1e114c9517506", "shasum": "" }, "require": { @@ -69,7 +69,7 @@ "support": { "irc": "irc://irc.freenode.org/composer", "issues": "https://github.com/composer/semver/issues", - "source": "https://github.com/composer/semver/tree/3.2.5" + "source": "https://github.com/composer/semver/tree/3.2.6" }, "funding": [ { @@ -85,7 +85,7 @@ "type": "tidelift" } ], - "time": "2021-05-24T12:41:47+00:00" + "time": "2021-10-25T11:34:17+00:00" }, { "name": "composer/xdebug-handler", @@ -496,20 +496,20 @@ }, { "name": "psr/container", - "version": "1.1.1", + "version": "1.1.2", "source": { "type": "git", "url": "https://github.com/php-fig/container.git", - "reference": "8622567409010282b7aeebe4bb841fe98b58dcaf" + "reference": "513e0666f7216c7459170d56df27dfcefe1689ea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/8622567409010282b7aeebe4bb841fe98b58dcaf", - "reference": "8622567409010282b7aeebe4bb841fe98b58dcaf", + "url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea", + "reference": "513e0666f7216c7459170d56df27dfcefe1689ea", "shasum": "" }, "require": { - "php": ">=7.2.0" + "php": ">=7.4.0" }, "type": "library", "autoload": { @@ -538,9 +538,9 @@ ], "support": { "issues": "https://github.com/php-fig/container/issues", - "source": "https://github.com/php-fig/container/tree/1.1.1" + "source": "https://github.com/php-fig/container/tree/1.1.2" }, - "time": "2021-03-05T17:36:06+00:00" + "time": "2021-11-05T16:50:12+00:00" }, { "name": "psr/event-dispatcher", @@ -644,16 +644,16 @@ }, { "name": "symfony/console", - "version": "v5.3.7", + "version": "v5.3.10", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "8b1008344647462ae6ec57559da166c2bfa5e16a" + "reference": "d4e409d9fbcfbf71af0e5a940abb7b0b4bad0bd3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/8b1008344647462ae6ec57559da166c2bfa5e16a", - "reference": "8b1008344647462ae6ec57559da166c2bfa5e16a", + "url": "https://api.github.com/repos/symfony/console/zipball/d4e409d9fbcfbf71af0e5a940abb7b0b4bad0bd3", + "reference": "d4e409d9fbcfbf71af0e5a940abb7b0b4bad0bd3", "shasum": "" }, "require": { @@ -723,7 +723,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.3.7" + "source": "https://github.com/symfony/console/tree/v5.3.10" }, "funding": [ { @@ -739,7 +739,7 @@ "type": "tidelift" } ], - "time": "2021-08-25T20:02:16+00:00" + "time": "2021-10-26T09:30:15+00:00" }, { "name": "symfony/deprecation-contracts", @@ -2012,16 +2012,16 @@ }, { "name": "symfony/string", - "version": "v5.3.7", + "version": "v5.3.10", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "8d224396e28d30f81969f083a58763b8b9ceb0a5" + "reference": "d70c35bb20bbca71fc4ab7921e3c6bda1a82a60c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/8d224396e28d30f81969f083a58763b8b9ceb0a5", - "reference": "8d224396e28d30f81969f083a58763b8b9ceb0a5", + "url": "https://api.github.com/repos/symfony/string/zipball/d70c35bb20bbca71fc4ab7921e3c6bda1a82a60c", + "reference": "d70c35bb20bbca71fc4ab7921e3c6bda1a82a60c", "shasum": "" }, "require": { @@ -2075,7 +2075,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.3.7" + "source": "https://github.com/symfony/string/tree/v5.3.10" }, "funding": [ { @@ -2091,7 +2091,7 @@ "type": "tidelift" } ], - "time": "2021-08-26T08:00:08+00:00" + "time": "2021-10-27T18:21:46+00:00" } ], "packages-dev": [],