Skip to content

Commit

Permalink
chore(php): fix PHP 8.1 deprecations (#304)
Browse files Browse the repository at this point in the history
Signed-off-by: azjezz <azjezz@protonmail.com>
  • Loading branch information
azjezz authored Dec 8, 2021
1 parent 60683bf commit fd4557c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "unit tests"

on:
on:
pull_request: ~
push: ~

Expand All @@ -15,6 +15,7 @@ jobs:
php-version:
- "7.4"
- "8.0"
- "8.1"
operating-system:
- "macos-latest"
- "ubuntu-latest"
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ install-unit-tests-dependencies:
install: install-root-dependencies install-coding-standard-dependencies install-type-check-dependencies install-unit-tests-dependencies

coding-standard-fix:
php tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=tools/php-cs-fixer/.php_cs.dist
PHP_CS_FIXER_IGNORE_ENV=1 php 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:
php tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=tools/php-cs-fixer/.php_cs.dist --dry-run
PHP_CS_FIXER_IGNORE_ENV=1 php tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=tools/php-cs-fixer/.php_cs.dist --dry-run
php tools/php-codesniffer/vendor/bin/phpcs --basepath=. --standard=tools/php-codesniffer/.phpcs.xml

type-check:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"php": "^7.4 || ~8.0.0 || ~8.1.0",
"ext-bcmath": "*",
"ext-json": "*",
"ext-mbstring": "*",
Expand Down Expand Up @@ -39,4 +39,4 @@
"url": "https://github.com/hhvm/hsl"
}
}
}
}
18 changes: 5 additions & 13 deletions src/Psl/Internal/internal_encoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Psl;
use Psl\Exception;
use Psl\Type;

use function mb_internal_encoding;

Expand All @@ -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';
}
2 changes: 2 additions & 0 deletions src/Psl/Iter/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static function create(iterable $iterable): Iterator
*
* @return Tv
*/
#[\ReturnTypeWillChange]
public function current()
{
Psl\invariant($this->valid(), 'The Iterator is invalid.');
Expand Down Expand Up @@ -127,6 +128,7 @@ public function next(): void
*
* @return Tk
*/
#[\ReturnTypeWillChange]
public function key()
{
Psl\invariant($this->valid(), 'The Iterator is invalid.');
Expand Down
3 changes: 0 additions & 3 deletions tests/Psl/Str/WidthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ public function provideData(): array
{
return [
[5, 'Hello'],
[5, '☕ ☕ ☕'],
[1, ''],
[5, '⸺⸺⸺⸺⸺'],
[12, '♈♉♊♋♌♍♎♏♐♑♒♓'],
[1, ''],
[12, 'héllö, wôrld'],
[9, 'مرحبا بكم'],
Expand All @@ -33,7 +31,6 @@ public function provideData(): array
[4, 'تونس'],
[3, 'سيف'],
[14, 'こんにちは世界'],
[3, '🥇🥈🥉'],
[4, '你好'],
[6, 'สวัสดี'],
[3, 'ؤخى']
Expand Down

0 comments on commit fd4557c

Please sign in to comment.