Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(php): fix PHP 8.1 deprecations #255

Merged
merged 1 commit into from
Nov 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
matrix:
php-version:
- "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 @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": "^8.0",
"php": "~8.0.0 || ~8.1.0",
"ext-bcmath": "*",
"ext-json": "*",
"ext-mbstring": "*",
Expand Down
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';
}
4 changes: 2 additions & 2 deletions src/Psl/Iter/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand Down
3 changes: 0 additions & 3 deletions tests/unit/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
50 changes: 25 additions & 25 deletions tools/php-cs-fixer/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.