diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index d9376481..f71c479b 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -24,5 +24,11 @@ jobs: run: | make install -j10 -O - - name: "checking coding standards" - run: make coding-standard-check + - name: "install mago" + run: wget -qO- https://carthage.software/mago.sh | bash -s -- --install-dir="/usr/local/bin" + + - name: "formatting" + run: mago fmt --dry-run + + - name: "linting" + run: mago lint --reporting-format=github diff --git a/Makefile b/Makefile index 8e0e50f7..f34fde9a 100644 --- a/Makefile +++ b/Makefile @@ -5,12 +5,12 @@ install: ## inst COMPOSER_IGNORE_PLATFORM_REQ=php+ composer install coding-standard-fix: ## apply automated coding standard fixes - PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --config=config/.php_cs.dist.php - ./vendor/bin/phpcbf --basepath=. --standard=config/.phpcs.xml + mago fix + mago fmt coding-standard-check: ## check coding-standard compliance - PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --config=config/.php_cs.dist.php --dry-run - ./vendor/bin/phpcs --basepath=. --standard=config/.phpcs.xml + mago lint + mago fmt --dry-run benchmarks: ## run benchmarks ./vendor/bin/phpbench run --config config/phpbench.json diff --git a/composer.json b/composer.json index 392ca0d7..dd2c0f89 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,6 @@ "revolt/event-loop": "^1.0.6" }, "require-dev": { - "squizlabs/php_codesniffer": "^3.9.0", - "friendsofphp/php-cs-fixer": "^3.52.1", "phpbench/phpbench": "^1.2.15", "phpunit/phpunit": "^9.6.18", "vimeo/psalm": "^5.23.1", diff --git a/composer.lock b/composer.lock index a3d30aef..a691135a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "96e8a3659280b296c7389255024734c4", + "content-hash": "d4da059ee360b8a310648954ad0fc6dc", "packages": [ { "name": "revolt/event-loop", @@ -240,70 +240,6 @@ ], "time": "2024-04-13T18:00:56+00:00" }, - { - "name": "clue/ndjson-react", - "version": "v1.3.0", - "source": { - "type": "git", - "url": "https://github.com/clue/reactphp-ndjson.git", - "reference": "392dc165fce93b5bb5c637b67e59619223c931b0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/clue/reactphp-ndjson/zipball/392dc165fce93b5bb5c637b67e59619223c931b0", - "reference": "392dc165fce93b5bb5c637b67e59619223c931b0", - "shasum": "" - }, - "require": { - "php": ">=5.3", - "react/stream": "^1.2" - }, - "require-dev": { - "phpunit/phpunit": "^9.5 || ^5.7 || ^4.8.35", - "react/event-loop": "^1.2" - }, - "type": "library", - "autoload": { - "psr-4": { - "Clue\\React\\NDJson\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Lück", - "email": "christian@clue.engineering" - } - ], - "description": "Streaming newline-delimited JSON (NDJSON) parser and encoder for ReactPHP.", - "homepage": "https://github.com/clue/reactphp-ndjson", - "keywords": [ - "NDJSON", - "json", - "jsonlines", - "newline", - "reactphp", - "streaming" - ], - "support": { - "issues": "https://github.com/clue/reactphp-ndjson/issues", - "source": "https://github.com/clue/reactphp-ndjson/tree/v1.3.0" - }, - "funding": [ - { - "url": "https://clue.engineering/support", - "type": "custom" - }, - { - "url": "https://github.com/clue", - "type": "github" - } - ], - "time": "2022-12-23T10:58:28+00:00" - }, { "name": "colinodell/json5", "version": "v2.3.0", @@ -920,53 +856,6 @@ ], "time": "2024-02-05T11:56:58+00:00" }, - { - "name": "evenement/evenement", - "version": "v3.0.2", - "source": { - "type": "git", - "url": "https://github.com/igorw/evenement.git", - "reference": "0a16b0d71ab13284339abb99d9d2bd813640efbc" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/igorw/evenement/zipball/0a16b0d71ab13284339abb99d9d2bd813640efbc", - "reference": "0a16b0d71ab13284339abb99d9d2bd813640efbc", - "shasum": "" - }, - "require": { - "php": ">=7.0" - }, - "require-dev": { - "phpunit/phpunit": "^9 || ^6" - }, - "type": "library", - "autoload": { - "psr-4": { - "Evenement\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Igor Wiedler", - "email": "igor@wiedler.ch" - } - ], - "description": "Événement is a very simple event dispatching library for PHP", - "keywords": [ - "event-dispatcher", - "event-emitter" - ], - "support": { - "issues": "https://github.com/igorw/evenement/issues", - "source": "https://github.com/igorw/evenement/tree/v3.0.2" - }, - "time": "2023-08-08T05:53:35+00:00" - }, { "name": "felixfbecker/advanced-json-rpc", "version": "v3.2.1", @@ -1129,106 +1018,6 @@ ], "time": "2024-02-07T09:43:46+00:00" }, - { - "name": "friendsofphp/php-cs-fixer", - "version": "v3.58.1", - "source": { - "type": "git", - "url": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer.git", - "reference": "04e9424025677a86914b9a4944dbbf4060bb0aff" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/PHP-CS-Fixer/PHP-CS-Fixer/zipball/04e9424025677a86914b9a4944dbbf4060bb0aff", - "reference": "04e9424025677a86914b9a4944dbbf4060bb0aff", - "shasum": "" - }, - "require": { - "clue/ndjson-react": "^1.0", - "composer/semver": "^3.4", - "composer/xdebug-handler": "^3.0.3", - "ext-filter": "*", - "ext-json": "*", - "ext-tokenizer": "*", - "fidry/cpu-core-counter": "^1.0", - "php": "^7.4 || ^8.0", - "react/child-process": "^0.6.5", - "react/event-loop": "^1.0", - "react/promise": "^2.0 || ^3.0", - "react/socket": "^1.0", - "react/stream": "^1.0", - "sebastian/diff": "^4.0 || ^5.0 || ^6.0", - "symfony/console": "^5.4 || ^6.0 || ^7.0", - "symfony/event-dispatcher": "^5.4 || ^6.0 || ^7.0", - "symfony/filesystem": "^5.4 || ^6.0 || ^7.0", - "symfony/finder": "^5.4 || ^6.0 || ^7.0", - "symfony/options-resolver": "^5.4 || ^6.0 || ^7.0", - "symfony/polyfill-mbstring": "^1.28", - "symfony/polyfill-php80": "^1.28", - "symfony/polyfill-php81": "^1.28", - "symfony/process": "^5.4 || ^6.0 || ^7.0", - "symfony/stopwatch": "^5.4 || ^6.0 || ^7.0" - }, - "require-dev": { - "facile-it/paraunit": "^1.3 || ^2.0", - "infection/infection": "^0.27.11", - "justinrainbow/json-schema": "^5.2", - "keradus/cli-executor": "^2.1", - "mikey179/vfsstream": "^1.6.11", - "php-coveralls/php-coveralls": "^2.7", - "php-cs-fixer/accessible-object": "^1.1", - "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.4", - "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.4", - "phpunit/phpunit": "^9.6 || ^10.5.5 || ^11.0.2", - "symfony/var-dumper": "^5.4 || ^6.0 || ^7.0", - "symfony/yaml": "^5.4 || ^6.0 || ^7.0" - }, - "suggest": { - "ext-dom": "For handling output formats in XML", - "ext-mbstring": "For handling non-UTF8 characters." - }, - "bin": [ - "php-cs-fixer" - ], - "type": "application", - "autoload": { - "psr-4": { - "PhpCsFixer\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Dariusz Rumiński", - "email": "dariusz.ruminski@gmail.com" - } - ], - "description": "A tool to automatically fix PHP code style", - "keywords": [ - "Static code analysis", - "fixer", - "standards", - "static analysis" - ], - "support": { - "issues": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues", - "source": "https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/tree/v3.58.1" - }, - "funding": [ - { - "url": "https://github.com/keradus", - "type": "github" - } - ], - "time": "2024-05-29T16:39:07+00:00" - }, { "name": "guzzlehttp/guzzle", "version": "7.8.1", @@ -3379,56 +3168,6 @@ }, "time": "2021-11-05T16:47:00+00:00" }, - { - "name": "psr/event-dispatcher", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/event-dispatcher.git", - "reference": "dbefd12671e8a14ec7f180cab83036ed26714bb0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/event-dispatcher/zipball/dbefd12671e8a14ec7f180cab83036ed26714bb0", - "reference": "dbefd12671e8a14ec7f180cab83036ed26714bb0", - "shasum": "" - }, - "require": { - "php": ">=7.2.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\EventDispatcher\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Standard interfaces for event handling.", - "keywords": [ - "events", - "psr", - "psr-14" - ], - "support": { - "issues": "https://github.com/php-fig/event-dispatcher/issues", - "source": "https://github.com/php-fig/event-dispatcher/tree/1.0.0" - }, - "time": "2019-01-08T18:20:26+00:00" - }, { "name": "psr/http-client", "version": "1.0.3", @@ -3684,30 +3423,37 @@ "time": "2019-03-08T08:55:37+00:00" }, { - "name": "react/cache", - "version": "v1.2.0", + "name": "roave/infection-static-analysis-plugin", + "version": "1.35.0", "source": { "type": "git", - "url": "https://github.com/reactphp/cache.git", - "reference": "d47c472b64aa5608225f47965a484b75c7817d5b" + "url": "https://github.com/Roave/infection-static-analysis-plugin.git", + "reference": "3cb32845c5f758913a4b9eafd91ae18eafc26d82" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/cache/zipball/d47c472b64aa5608225f47965a484b75c7817d5b", - "reference": "d47c472b64aa5608225f47965a484b75c7817d5b", + "url": "https://api.github.com/repos/Roave/infection-static-analysis-plugin/zipball/3cb32845c5f758913a4b9eafd91ae18eafc26d82", + "reference": "3cb32845c5f758913a4b9eafd91ae18eafc26d82", "shasum": "" }, "require": { - "php": ">=5.3.0", - "react/promise": "^3.0 || ^2.0 || ^1.1" + "composer-runtime-api": "^2.2", + "infection/infection": "0.27.10", + "php": "~8.1.0 || ~8.2.0 || ~8.3.0", + "sanmai/later": "^0.1.4", + "vimeo/psalm": "^4.30.0 || ^5.15" }, "require-dev": { - "phpunit/phpunit": "^9.5 || ^5.7 || ^4.8.35" + "doctrine/coding-standard": "^12.0.0", + "phpunit/phpunit": "^10.5.12" }, + "bin": [ + "bin/roave-infection-static-analysis-plugin" + ], "type": "library", "autoload": { "psr-4": { - "React\\Cache\\": "src/" + "Roave\\InfectionStaticAnalysis\\": "src/Roave/InfectionStaticAnalysis" } }, "notification-url": "https://packagist.org/downloads/", @@ -3716,634 +3462,97 @@ ], "authors": [ { - "name": "Christian Lück", - "email": "christian@clue.engineering", - "homepage": "https://clue.engineering/" - }, - { - "name": "Cees-Jan Kiewiet", - "email": "reactphp@ceesjankiewiet.nl", - "homepage": "https://wyrihaximus.net/" - }, - { - "name": "Jan Sorgalla", - "email": "jsorgalla@gmail.com", - "homepage": "https://sorgalla.com/" - }, - { - "name": "Chris Boden", - "email": "cboden@gmail.com", - "homepage": "https://cboden.dev/" + "name": "Marco Pivetta", + "email": "ocramius@gmail.com" } ], - "description": "Async, Promise-based cache interface for ReactPHP", - "keywords": [ - "cache", - "caching", - "promise", - "reactphp" - ], + "description": "Static analysis on top of mutation testing - prevents escaped mutants from being invalid according to static analysis", "support": { - "issues": "https://github.com/reactphp/cache/issues", - "source": "https://github.com/reactphp/cache/tree/v1.2.0" + "issues": "https://github.com/Roave/infection-static-analysis-plugin/issues", + "source": "https://github.com/Roave/infection-static-analysis-plugin/tree/1.35.0" }, - "funding": [ - { - "url": "https://opencollective.com/reactphp", - "type": "open_collective" - } - ], - "time": "2022-11-30T15:59:55+00:00" + "time": "2024-03-10T11:55:48+00:00" }, { - "name": "react/child-process", - "version": "v0.6.5", + "name": "sanmai/later", + "version": "0.1.4", "source": { "type": "git", - "url": "https://github.com/reactphp/child-process.git", - "reference": "e71eb1aa55f057c7a4a0d08d06b0b0a484bead43" + "url": "https://github.com/sanmai/later.git", + "reference": "e24c4304a4b1349c2a83151a692cec0c10579f60" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/child-process/zipball/e71eb1aa55f057c7a4a0d08d06b0b0a484bead43", - "reference": "e71eb1aa55f057c7a4a0d08d06b0b0a484bead43", + "url": "https://api.github.com/repos/sanmai/later/zipball/e24c4304a4b1349c2a83151a692cec0c10579f60", + "reference": "e24c4304a4b1349c2a83151a692cec0c10579f60", "shasum": "" }, "require": { - "evenement/evenement": "^3.0 || ^2.0 || ^1.0", - "php": ">=5.3.0", - "react/event-loop": "^1.2", - "react/stream": "^1.2" + "php": ">=7.4" }, "require-dev": { - "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35", - "react/socket": "^1.8", - "sebastian/environment": "^5.0 || ^3.0 || ^2.0 || ^1.0" + "ergebnis/composer-normalize": "^2.8", + "friendsofphp/php-cs-fixer": "^3.35.1", + "infection/infection": ">=0.27.6", + "phan/phan": ">=2", + "php-coveralls/php-coveralls": "^2.0", + "phpstan/phpstan": ">=1.4.5", + "phpunit/phpunit": ">=9.5 <10", + "vimeo/psalm": ">=2" }, "type": "library", + "extra": { + "branch-alias": { + "dev-main": "0.1.x-dev" + } + }, "autoload": { + "files": [ + "src/functions.php" + ], "psr-4": { - "React\\ChildProcess\\": "src" + "Later\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "MIT" + "Apache-2.0" ], "authors": [ { - "name": "Christian Lück", - "email": "christian@clue.engineering", - "homepage": "https://clue.engineering/" - }, - { - "name": "Cees-Jan Kiewiet", - "email": "reactphp@ceesjankiewiet.nl", - "homepage": "https://wyrihaximus.net/" - }, - { - "name": "Jan Sorgalla", - "email": "jsorgalla@gmail.com", - "homepage": "https://sorgalla.com/" - }, - { - "name": "Chris Boden", - "email": "cboden@gmail.com", - "homepage": "https://cboden.dev/" + "name": "Alexey Kopytko", + "email": "alexey@kopytko.com" } ], - "description": "Event-driven library for executing child processes with ReactPHP.", - "keywords": [ - "event-driven", - "process", - "reactphp" - ], + "description": "Later: deferred wrapper object", "support": { - "issues": "https://github.com/reactphp/child-process/issues", - "source": "https://github.com/reactphp/child-process/tree/v0.6.5" + "issues": "https://github.com/sanmai/later/issues", + "source": "https://github.com/sanmai/later/tree/0.1.4" }, "funding": [ { - "url": "https://github.com/WyriHaximus", - "type": "github" - }, - { - "url": "https://github.com/clue", + "url": "https://github.com/sanmai", "type": "github" } ], - "time": "2022-09-16T13:41:56+00:00" + "time": "2023-10-24T00:25:28+00:00" }, { - "name": "react/dns", - "version": "v1.13.0", + "name": "sanmai/pipeline", + "version": "v6.10", "source": { "type": "git", - "url": "https://github.com/reactphp/dns.git", - "reference": "eb8ae001b5a455665c89c1df97f6fb682f8fb0f5" + "url": "https://github.com/sanmai/pipeline.git", + "reference": "cbd2ea30ba8bef596b8dad1adb9c92fb2987e430" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/dns/zipball/eb8ae001b5a455665c89c1df97f6fb682f8fb0f5", - "reference": "eb8ae001b5a455665c89c1df97f6fb682f8fb0f5", + "url": "https://api.github.com/repos/sanmai/pipeline/zipball/cbd2ea30ba8bef596b8dad1adb9c92fb2987e430", + "reference": "cbd2ea30ba8bef596b8dad1adb9c92fb2987e430", "shasum": "" }, "require": { - "php": ">=5.3.0", - "react/cache": "^1.0 || ^0.6 || ^0.5", - "react/event-loop": "^1.2", - "react/promise": "^3.2 || ^2.7 || ^1.2.1" - }, - "require-dev": { - "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36", - "react/async": "^4.3 || ^3 || ^2", - "react/promise-timer": "^1.11" - }, - "type": "library", - "autoload": { - "psr-4": { - "React\\Dns\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Lück", - "email": "christian@clue.engineering", - "homepage": "https://clue.engineering/" - }, - { - "name": "Cees-Jan Kiewiet", - "email": "reactphp@ceesjankiewiet.nl", - "homepage": "https://wyrihaximus.net/" - }, - { - "name": "Jan Sorgalla", - "email": "jsorgalla@gmail.com", - "homepage": "https://sorgalla.com/" - }, - { - "name": "Chris Boden", - "email": "cboden@gmail.com", - "homepage": "https://cboden.dev/" - } - ], - "description": "Async DNS resolver for ReactPHP", - "keywords": [ - "async", - "dns", - "dns-resolver", - "reactphp" - ], - "support": { - "issues": "https://github.com/reactphp/dns/issues", - "source": "https://github.com/reactphp/dns/tree/v1.13.0" - }, - "funding": [ - { - "url": "https://opencollective.com/reactphp", - "type": "open_collective" - } - ], - "time": "2024-06-13T14:18:03+00:00" - }, - { - "name": "react/event-loop", - "version": "v1.5.0", - "source": { - "type": "git", - "url": "https://github.com/reactphp/event-loop.git", - "reference": "bbe0bd8c51ffc05ee43f1729087ed3bdf7d53354" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/event-loop/zipball/bbe0bd8c51ffc05ee43f1729087ed3bdf7d53354", - "reference": "bbe0bd8c51ffc05ee43f1729087ed3bdf7d53354", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "require-dev": { - "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36" - }, - "suggest": { - "ext-pcntl": "For signal handling support when using the StreamSelectLoop" - }, - "type": "library", - "autoload": { - "psr-4": { - "React\\EventLoop\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Lück", - "email": "christian@clue.engineering", - "homepage": "https://clue.engineering/" - }, - { - "name": "Cees-Jan Kiewiet", - "email": "reactphp@ceesjankiewiet.nl", - "homepage": "https://wyrihaximus.net/" - }, - { - "name": "Jan Sorgalla", - "email": "jsorgalla@gmail.com", - "homepage": "https://sorgalla.com/" - }, - { - "name": "Chris Boden", - "email": "cboden@gmail.com", - "homepage": "https://cboden.dev/" - } - ], - "description": "ReactPHP's core reactor event loop that libraries can use for evented I/O.", - "keywords": [ - "asynchronous", - "event-loop" - ], - "support": { - "issues": "https://github.com/reactphp/event-loop/issues", - "source": "https://github.com/reactphp/event-loop/tree/v1.5.0" - }, - "funding": [ - { - "url": "https://opencollective.com/reactphp", - "type": "open_collective" - } - ], - "time": "2023-11-13T13:48:05+00:00" - }, - { - "name": "react/promise", - "version": "v3.2.0", - "source": { - "type": "git", - "url": "https://github.com/reactphp/promise.git", - "reference": "8a164643313c71354582dc850b42b33fa12a4b63" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/promise/zipball/8a164643313c71354582dc850b42b33fa12a4b63", - "reference": "8a164643313c71354582dc850b42b33fa12a4b63", - "shasum": "" - }, - "require": { - "php": ">=7.1.0" - }, - "require-dev": { - "phpstan/phpstan": "1.10.39 || 1.4.10", - "phpunit/phpunit": "^9.6 || ^7.5" - }, - "type": "library", - "autoload": { - "files": [ - "src/functions_include.php" - ], - "psr-4": { - "React\\Promise\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jan Sorgalla", - "email": "jsorgalla@gmail.com", - "homepage": "https://sorgalla.com/" - }, - { - "name": "Christian Lück", - "email": "christian@clue.engineering", - "homepage": "https://clue.engineering/" - }, - { - "name": "Cees-Jan Kiewiet", - "email": "reactphp@ceesjankiewiet.nl", - "homepage": "https://wyrihaximus.net/" - }, - { - "name": "Chris Boden", - "email": "cboden@gmail.com", - "homepage": "https://cboden.dev/" - } - ], - "description": "A lightweight implementation of CommonJS Promises/A for PHP", - "keywords": [ - "promise", - "promises" - ], - "support": { - "issues": "https://github.com/reactphp/promise/issues", - "source": "https://github.com/reactphp/promise/tree/v3.2.0" - }, - "funding": [ - { - "url": "https://opencollective.com/reactphp", - "type": "open_collective" - } - ], - "time": "2024-05-24T10:39:05+00:00" - }, - { - "name": "react/socket", - "version": "v1.15.0", - "source": { - "type": "git", - "url": "https://github.com/reactphp/socket.git", - "reference": "216d3aec0b87f04a40ca04f481e6af01bdd1d038" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/socket/zipball/216d3aec0b87f04a40ca04f481e6af01bdd1d038", - "reference": "216d3aec0b87f04a40ca04f481e6af01bdd1d038", - "shasum": "" - }, - "require": { - "evenement/evenement": "^3.0 || ^2.0 || ^1.0", - "php": ">=5.3.0", - "react/dns": "^1.11", - "react/event-loop": "^1.2", - "react/promise": "^3 || ^2.6 || ^1.2.1", - "react/stream": "^1.2" - }, - "require-dev": { - "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36", - "react/async": "^4 || ^3 || ^2", - "react/promise-stream": "^1.4", - "react/promise-timer": "^1.10" - }, - "type": "library", - "autoload": { - "psr-4": { - "React\\Socket\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Lück", - "email": "christian@clue.engineering", - "homepage": "https://clue.engineering/" - }, - { - "name": "Cees-Jan Kiewiet", - "email": "reactphp@ceesjankiewiet.nl", - "homepage": "https://wyrihaximus.net/" - }, - { - "name": "Jan Sorgalla", - "email": "jsorgalla@gmail.com", - "homepage": "https://sorgalla.com/" - }, - { - "name": "Chris Boden", - "email": "cboden@gmail.com", - "homepage": "https://cboden.dev/" - } - ], - "description": "Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for ReactPHP", - "keywords": [ - "Connection", - "Socket", - "async", - "reactphp", - "stream" - ], - "support": { - "issues": "https://github.com/reactphp/socket/issues", - "source": "https://github.com/reactphp/socket/tree/v1.15.0" - }, - "funding": [ - { - "url": "https://opencollective.com/reactphp", - "type": "open_collective" - } - ], - "time": "2023-12-15T11:02:10+00:00" - }, - { - "name": "react/stream", - "version": "v1.4.0", - "source": { - "type": "git", - "url": "https://github.com/reactphp/stream.git", - "reference": "1e5b0acb8fe55143b5b426817155190eb6f5b18d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/stream/zipball/1e5b0acb8fe55143b5b426817155190eb6f5b18d", - "reference": "1e5b0acb8fe55143b5b426817155190eb6f5b18d", - "shasum": "" - }, - "require": { - "evenement/evenement": "^3.0 || ^2.0 || ^1.0", - "php": ">=5.3.8", - "react/event-loop": "^1.2" - }, - "require-dev": { - "clue/stream-filter": "~1.2", - "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36" - }, - "type": "library", - "autoload": { - "psr-4": { - "React\\Stream\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Christian Lück", - "email": "christian@clue.engineering", - "homepage": "https://clue.engineering/" - }, - { - "name": "Cees-Jan Kiewiet", - "email": "reactphp@ceesjankiewiet.nl", - "homepage": "https://wyrihaximus.net/" - }, - { - "name": "Jan Sorgalla", - "email": "jsorgalla@gmail.com", - "homepage": "https://sorgalla.com/" - }, - { - "name": "Chris Boden", - "email": "cboden@gmail.com", - "homepage": "https://cboden.dev/" - } - ], - "description": "Event-driven readable and writable streams for non-blocking I/O in ReactPHP", - "keywords": [ - "event-driven", - "io", - "non-blocking", - "pipe", - "reactphp", - "readable", - "stream", - "writable" - ], - "support": { - "issues": "https://github.com/reactphp/stream/issues", - "source": "https://github.com/reactphp/stream/tree/v1.4.0" - }, - "funding": [ - { - "url": "https://opencollective.com/reactphp", - "type": "open_collective" - } - ], - "time": "2024-06-11T12:45:25+00:00" - }, - { - "name": "roave/infection-static-analysis-plugin", - "version": "1.35.0", - "source": { - "type": "git", - "url": "https://github.com/Roave/infection-static-analysis-plugin.git", - "reference": "3cb32845c5f758913a4b9eafd91ae18eafc26d82" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Roave/infection-static-analysis-plugin/zipball/3cb32845c5f758913a4b9eafd91ae18eafc26d82", - "reference": "3cb32845c5f758913a4b9eafd91ae18eafc26d82", - "shasum": "" - }, - "require": { - "composer-runtime-api": "^2.2", - "infection/infection": "0.27.10", - "php": "~8.1.0 || ~8.2.0 || ~8.3.0", - "sanmai/later": "^0.1.4", - "vimeo/psalm": "^4.30.0 || ^5.15" - }, - "require-dev": { - "doctrine/coding-standard": "^12.0.0", - "phpunit/phpunit": "^10.5.12" - }, - "bin": [ - "bin/roave-infection-static-analysis-plugin" - ], - "type": "library", - "autoload": { - "psr-4": { - "Roave\\InfectionStaticAnalysis\\": "src/Roave/InfectionStaticAnalysis" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com" - } - ], - "description": "Static analysis on top of mutation testing - prevents escaped mutants from being invalid according to static analysis", - "support": { - "issues": "https://github.com/Roave/infection-static-analysis-plugin/issues", - "source": "https://github.com/Roave/infection-static-analysis-plugin/tree/1.35.0" - }, - "time": "2024-03-10T11:55:48+00:00" - }, - { - "name": "sanmai/later", - "version": "0.1.4", - "source": { - "type": "git", - "url": "https://github.com/sanmai/later.git", - "reference": "e24c4304a4b1349c2a83151a692cec0c10579f60" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sanmai/later/zipball/e24c4304a4b1349c2a83151a692cec0c10579f60", - "reference": "e24c4304a4b1349c2a83151a692cec0c10579f60", - "shasum": "" - }, - "require": { - "php": ">=7.4" - }, - "require-dev": { - "ergebnis/composer-normalize": "^2.8", - "friendsofphp/php-cs-fixer": "^3.35.1", - "infection/infection": ">=0.27.6", - "phan/phan": ">=2", - "php-coveralls/php-coveralls": "^2.0", - "phpstan/phpstan": ">=1.4.5", - "phpunit/phpunit": ">=9.5 <10", - "vimeo/psalm": ">=2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "0.1.x-dev" - } - }, - "autoload": { - "files": [ - "src/functions.php" - ], - "psr-4": { - "Later\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Alexey Kopytko", - "email": "alexey@kopytko.com" - } - ], - "description": "Later: deferred wrapper object", - "support": { - "issues": "https://github.com/sanmai/later/issues", - "source": "https://github.com/sanmai/later/tree/0.1.4" - }, - "funding": [ - { - "url": "https://github.com/sanmai", - "type": "github" - } - ], - "time": "2023-10-24T00:25:28+00:00" - }, - { - "name": "sanmai/pipeline", - "version": "v6.10", - "source": { - "type": "git", - "url": "https://github.com/sanmai/pipeline.git", - "reference": "cbd2ea30ba8bef596b8dad1adb9c92fb2987e430" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sanmai/pipeline/zipball/cbd2ea30ba8bef596b8dad1adb9c92fb2987e430", - "reference": "cbd2ea30ba8bef596b8dad1adb9c92fb2987e430", - "shasum": "" - }, - "require": { - "php": "^7.4 || ^8.0" + "php": "^7.4 || ^8.0" }, "require-dev": { "ergebnis/composer-normalize": "^2.8", @@ -5478,294 +4687,54 @@ }, "funding": [ { - "url": "https://spatie.be/open-source/support-us", - "type": "custom" - }, - { - "url": "https://github.com/spatie", - "type": "github" - } - ], - "time": "2024-05-01T10:20:27+00:00" - }, - { - "name": "squizlabs/php_codesniffer", - "version": "3.10.1", - "source": { - "type": "git", - "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "8f90f7a53ce271935282967f53d0894f8f1ff877" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/8f90f7a53ce271935282967f53d0894f8f1ff877", - "reference": "8f90f7a53ce271935282967f53d0894f8f1ff877", - "shasum": "" - }, - "require": { - "ext-simplexml": "*", - "ext-tokenizer": "*", - "ext-xmlwriter": "*", - "php": ">=5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4" - }, - "bin": [ - "bin/phpcbf", - "bin/phpcs" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.x-dev" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Greg Sherwood", - "role": "Former lead" - }, - { - "name": "Juliette Reinders Folmer", - "role": "Current lead" - }, - { - "name": "Contributors", - "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer/graphs/contributors" - } - ], - "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "https://github.com/PHPCSStandards/PHP_CodeSniffer", - "keywords": [ - "phpcs", - "standards", - "static analysis" - ], - "support": { - "issues": "https://github.com/PHPCSStandards/PHP_CodeSniffer/issues", - "security": "https://github.com/PHPCSStandards/PHP_CodeSniffer/security/policy", - "source": "https://github.com/PHPCSStandards/PHP_CodeSniffer", - "wiki": "https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki" - }, - "funding": [ - { - "url": "https://github.com/PHPCSStandards", - "type": "github" - }, - { - "url": "https://github.com/jrfnl", - "type": "github" - }, - { - "url": "https://opencollective.com/php_codesniffer", - "type": "open_collective" - } - ], - "time": "2024-05-22T21:24:41+00:00" - }, - { - "name": "symfony/config", - "version": "v7.1.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/config.git", - "reference": "2210fc99fa42a259eb6c89d1f724ce0c4d62d5d2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/2210fc99fa42a259eb6c89d1f724ce0c4d62d5d2", - "reference": "2210fc99fa42a259eb6c89d1f724ce0c4d62d5d2", - "shasum": "" - }, - "require": { - "php": ">=8.2", - "symfony/deprecation-contracts": "^2.5|^3", - "symfony/filesystem": "^7.1", - "symfony/polyfill-ctype": "~1.8" - }, - "conflict": { - "symfony/finder": "<6.4", - "symfony/service-contracts": "<2.5" - }, - "require-dev": { - "symfony/event-dispatcher": "^6.4|^7.0", - "symfony/finder": "^6.4|^7.0", - "symfony/messenger": "^6.4|^7.0", - "symfony/service-contracts": "^2.5|^3", - "symfony/yaml": "^6.4|^7.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Config\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Helps you find, load, combine, autofill and validate configuration values of any kind", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/config/tree/v7.1.1" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2024-05-31T14:57:53+00:00" - }, - { - "name": "symfony/console", - "version": "v7.1.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/console.git", - "reference": "9b008f2d7b21c74ef4d0c3de6077a642bc55ece3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/9b008f2d7b21c74ef4d0c3de6077a642bc55ece3", - "reference": "9b008f2d7b21c74ef4d0c3de6077a642bc55ece3", - "shasum": "" - }, - "require": { - "php": ">=8.2", - "symfony/polyfill-mbstring": "~1.0", - "symfony/service-contracts": "^2.5|^3", - "symfony/string": "^6.4|^7.0" - }, - "conflict": { - "symfony/dependency-injection": "<6.4", - "symfony/dotenv": "<6.4", - "symfony/event-dispatcher": "<6.4", - "symfony/lock": "<6.4", - "symfony/process": "<6.4" - }, - "provide": { - "psr/log-implementation": "1.0|2.0|3.0" - }, - "require-dev": { - "psr/log": "^1|^2|^3", - "symfony/config": "^6.4|^7.0", - "symfony/dependency-injection": "^6.4|^7.0", - "symfony/event-dispatcher": "^6.4|^7.0", - "symfony/http-foundation": "^6.4|^7.0", - "symfony/http-kernel": "^6.4|^7.0", - "symfony/lock": "^6.4|^7.0", - "symfony/messenger": "^6.4|^7.0", - "symfony/process": "^6.4|^7.0", - "symfony/stopwatch": "^6.4|^7.0", - "symfony/var-dumper": "^6.4|^7.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Console\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Eases the creation of beautiful and testable command line interfaces", - "homepage": "https://symfony.com", - "keywords": [ - "cli", - "command-line", - "console", - "terminal" - ], - "support": { - "source": "https://github.com/symfony/console/tree/v7.1.1" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", + "url": "https://spatie.be/open-source/support-us", "type": "custom" }, { - "url": "https://github.com/fabpot", + "url": "https://github.com/spatie", "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" } ], - "time": "2024-05-31T14:57:53+00:00" + "time": "2024-05-01T10:20:27+00:00" }, { - "name": "symfony/deprecation-contracts", - "version": "v3.5.0", + "name": "symfony/config", + "version": "v7.1.1", "source": { "type": "git", - "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1" + "url": "https://github.com/symfony/config.git", + "reference": "2210fc99fa42a259eb6c89d1f724ce0c4d62d5d2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", - "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", + "url": "https://api.github.com/repos/symfony/config/zipball/2210fc99fa42a259eb6c89d1f724ce0c4d62d5d2", + "reference": "2210fc99fa42a259eb6c89d1f724ce0c4d62d5d2", "shasum": "" }, "require": { - "php": ">=8.1" + "php": ">=8.2", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/filesystem": "^7.1", + "symfony/polyfill-ctype": "~1.8" }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "3.5-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } + "conflict": { + "symfony/finder": "<6.4", + "symfony/service-contracts": "<2.5" + }, + "require-dev": { + "symfony/event-dispatcher": "^6.4|^7.0", + "symfony/finder": "^6.4|^7.0", + "symfony/messenger": "^6.4|^7.0", + "symfony/service-contracts": "^2.5|^3", + "symfony/yaml": "^6.4|^7.0" }, + "type": "library", "autoload": { - "files": [ - "function.php" + "psr-4": { + "Symfony\\Component\\Config\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" ] }, "notification-url": "https://packagist.org/downloads/", @@ -5774,18 +4743,18 @@ ], "authors": [ { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" + "name": "Fabien Potencier", + "email": "fabien@symfony.com" }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" } ], - "description": "A generic function and convention to trigger deprecation notices", + "description": "Helps you find, load, combine, autofill and validate configuration values of any kind", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.0" + "source": "https://github.com/symfony/config/tree/v7.1.1" }, "funding": [ { @@ -5801,48 +4770,55 @@ "type": "tidelift" } ], - "time": "2024-04-18T09:32:20+00:00" + "time": "2024-05-31T14:57:53+00:00" }, { - "name": "symfony/event-dispatcher", + "name": "symfony/console", "version": "v7.1.1", "source": { "type": "git", - "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "9fa7f7a21beb22a39a8f3f28618b29e50d7a55a7" + "url": "https://github.com/symfony/console.git", + "reference": "9b008f2d7b21c74ef4d0c3de6077a642bc55ece3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/9fa7f7a21beb22a39a8f3f28618b29e50d7a55a7", - "reference": "9fa7f7a21beb22a39a8f3f28618b29e50d7a55a7", + "url": "https://api.github.com/repos/symfony/console/zipball/9b008f2d7b21c74ef4d0c3de6077a642bc55ece3", + "reference": "9b008f2d7b21c74ef4d0c3de6077a642bc55ece3", "shasum": "" }, "require": { "php": ">=8.2", - "symfony/event-dispatcher-contracts": "^2.5|^3" + "symfony/polyfill-mbstring": "~1.0", + "symfony/service-contracts": "^2.5|^3", + "symfony/string": "^6.4|^7.0" }, "conflict": { "symfony/dependency-injection": "<6.4", - "symfony/service-contracts": "<2.5" + "symfony/dotenv": "<6.4", + "symfony/event-dispatcher": "<6.4", + "symfony/lock": "<6.4", + "symfony/process": "<6.4" }, "provide": { - "psr/event-dispatcher-implementation": "1.0", - "symfony/event-dispatcher-implementation": "2.0|3.0" + "psr/log-implementation": "1.0|2.0|3.0" }, "require-dev": { "psr/log": "^1|^2|^3", "symfony/config": "^6.4|^7.0", "symfony/dependency-injection": "^6.4|^7.0", - "symfony/error-handler": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0", + "symfony/event-dispatcher": "^6.4|^7.0", "symfony/http-foundation": "^6.4|^7.0", - "symfony/service-contracts": "^2.5|^3", - "symfony/stopwatch": "^6.4|^7.0" + "symfony/http-kernel": "^6.4|^7.0", + "symfony/lock": "^6.4|^7.0", + "symfony/messenger": "^6.4|^7.0", + "symfony/process": "^6.4|^7.0", + "symfony/stopwatch": "^6.4|^7.0", + "symfony/var-dumper": "^6.4|^7.0" }, "type": "library", "autoload": { "psr-4": { - "Symfony\\Component\\EventDispatcher\\": "" + "Symfony\\Component\\Console\\": "" }, "exclude-from-classmap": [ "/Tests/" @@ -5862,10 +4838,16 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", + "description": "Eases the creation of beautiful and testable command line interfaces", "homepage": "https://symfony.com", + "keywords": [ + "cli", + "command-line", + "console", + "terminal" + ], "support": { - "source": "https://github.com/symfony/event-dispatcher/tree/v7.1.1" + "source": "https://github.com/symfony/console/tree/v7.1.1" }, "funding": [ { @@ -5884,22 +4866,21 @@ "time": "2024-05-31T14:57:53+00:00" }, { - "name": "symfony/event-dispatcher-contracts", + "name": "symfony/deprecation-contracts", "version": "v3.5.0", "source": { "type": "git", - "url": "https://github.com/symfony/event-dispatcher-contracts.git", - "reference": "8f93aec25d41b72493c6ddff14e916177c9efc50" + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/8f93aec25d41b72493c6ddff14e916177c9efc50", - "reference": "8f93aec25d41b72493c6ddff14e916177c9efc50", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", + "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1", "shasum": "" }, "require": { - "php": ">=8.1", - "psr/event-dispatcher": "^1" + "php": ">=8.1" }, "type": "library", "extra": { @@ -5912,9 +4893,9 @@ } }, "autoload": { - "psr-4": { - "Symfony\\Contracts\\EventDispatcher\\": "" - } + "files": [ + "function.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -5930,18 +4911,10 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Generic abstractions related to dispatching event", + "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", - "keywords": [ - "abstractions", - "contracts", - "decoupling", - "interfaces", - "interoperability", - "standards" - ], "support": { - "source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.5.0" + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.0" }, "funding": [ { @@ -6474,162 +5447,6 @@ ], "time": "2024-01-29T20:11:03+00:00" }, - { - "name": "symfony/polyfill-php80", - "version": "v1.29.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/87b68208d5c1188808dd7839ee1e6c8ec3b02f1b", - "reference": "87b68208d5c1188808dd7839ee1e6c8ec3b02f1b", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "type": "library", - "extra": { - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Php80\\": "" - }, - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ion Bazan", - "email": "ion.bazan@gmail.com" - }, - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.29.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2024-01-29T20:11:03+00:00" - }, - { - "name": "symfony/polyfill-php81", - "version": "v1.29.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php81.git", - "reference": "c565ad1e63f30e7477fc40738343c62b40bc672d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/c565ad1e63f30e7477fc40738343c62b40bc672d", - "reference": "c565ad1e63f30e7477fc40738343c62b40bc672d", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "type": "library", - "extra": { - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "Symfony\\Polyfill\\Php81\\": "" - }, - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-php81/tree/v1.29.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2024-01-29T20:11:03+00:00" - }, { "name": "symfony/process", "version": "v7.1.1", diff --git a/config/.php_cs.dist.php b/config/.php_cs.dist.php deleted file mode 100644 index 778a2352..00000000 --- a/config/.php_cs.dist.php +++ /dev/null @@ -1,81 +0,0 @@ -setFinder( - Finder::create() - ->in([ - __DIR__ . '/../src', - __DIR__ . '/../config', - __DIR__ . '/../examples', - __DIR__ . '/../docs', - __DIR__ . '/../tests', - ]) - ) - ->setRiskyAllowed(true) - ->setRules([ - 'align_multiline_comment' => true, - 'array_indentation' => true, - 'declare_strict_types' => true, - // Currently it is not possible to mark all classes as final (exceptions etc.) - // We can run this fixer periodically on the tests folder only. - // 'final_class' => true, - 'global_namespace_import' => [ - 'import_classes' => true, - 'import_constants' => true, - 'import_functions' => true, - ], - 'list_syntax' => [ - 'syntax' => 'short', - ], - 'multiline_comment_opening_closing' => true, - 'native_function_casing' => true, - 'no_empty_phpdoc' => true, - 'no_leading_import_slash' => true, - 'no_unused_imports' => true, - 'no_useless_else' => true, - 'no_useless_return' => true, - 'ordered_imports' => [ - 'imports_order' => ['class', 'function', 'const'], - ], - 'ordered_interfaces' => true, - 'php_unit_test_annotation' => true, - 'php_unit_test_case_static_method_calls' => [ - 'call_type' => 'static', - ], - 'single_import_per_statement' => true, - 'single_trait_insert_per_statement' => true, - 'static_lambda' => true, - 'strict_comparison' => true, - 'strict_param' => true, - 'no_blank_lines_after_phpdoc' => true, - 'phpdoc_align' => [ - 'align' => 'left', - ], - 'phpdoc_indent' => true, - 'phpdoc_line_span' => [ - 'const' => 'multi', - 'property' => 'multi', - 'method' => 'multi', - ], - 'phpdoc_no_alias_tag' => [ - 'replacements' => [ - 'psalm-var' => 'var', - 'psalm-template' => 'template', - 'psalm-param' => 'param', - 'psalm-return' => 'return', - ] - ], - 'phpdoc_order' => true, - 'phpdoc_scalar' => true, - 'phpdoc_separation' => true, - 'phpdoc_summary' => true, - 'phpdoc_tag_casing' => true, - 'phpdoc_trim' => true, - 'phpdoc_trim_consecutive_blank_line_separation' => true, - 'no_empty_statement' => true, - 'semicolon_after_instruction' => true, - 'nullable_type_declaration_for_default_null_value' => true, - ]) - ; diff --git a/config/.phpcs.xml b/config/.phpcs.xml deleted file mode 100644 index 4c03b766..00000000 --- a/config/.phpcs.xml +++ /dev/null @@ -1,64 +0,0 @@ - - - The coding standard for PHP Standard Library. - - ../src - ../config - ../config - ../tests - - - */src/Psl/File/(WriteMode|LockType).php - */src/Psl/Network/SocketScheme.php - */src/Psl/Str/Encoding.php - */src/Psl/Html/Encoding.php - */src/Psl/Hash/Algorithm.php - */src/Psl/Hash/Hmac/Algorithm.php - */src/Psl/OS/OperatingSystemFamily.php - */src/Psl/Password/Algorithm.php - */src/Psl/Shell/ErrorOutputBehavior.php - - */tests/unit/Str/Grapheme/RangeTest.php - - - - - - - error - - - - error - - - - - error - - - - - - - - - - - error - - - - - - - - - - - - - - - - diff --git a/examples/async/main.php b/examples/async/main.php index 538f4de0..701631b0 100644 --- a/examples/async/main.php +++ b/examples/async/main.php @@ -10,23 +10,23 @@ require __DIR__ . '/../../vendor/autoload.php'; -Async\main(static function(): int { - $watcher = Async\Scheduler::onSignal(SIGINT, static function (): never { - IO\write_line('SIGINT received, stopping...'); - exit(0); - }); +Async\main(static function (): int { + $watcher = Async\Scheduler::onSignal(SIGINT, static function (): never { + IO\write_line('SIGINT received, stopping...'); + exit(0); + }); - Async\Scheduler::unreference($watcher); + Async\Scheduler::unreference($watcher); - IO\write_error_line('Press Ctrl+C to stop'); + IO\write_error_line('Press Ctrl+C to stop'); - Async\concurrently([ - static fn(): string => Shell\execute('sleep', ['3']), - static fn(): string => Shell\execute('echo', ['Hello World!']), - static fn(): string => Shell\execute('echo', ['Hello World!']), - ]); + Async\concurrently([ + static fn(): string => Shell\execute('sleep', ['3']), + static fn(): string => Shell\execute('echo', ['Hello World!']), + static fn(): string => Shell\execute('echo', ['Hello World!']), + ]); - IO\write_error_line('Done!'); + IO\write_error_line('Done!'); - return 0; + return 0; }); diff --git a/examples/async/usleep.php b/examples/async/usleep.php index dafcbebb..fb624539 100644 --- a/examples/async/usleep.php +++ b/examples/async/usleep.php @@ -25,7 +25,7 @@ $duration = DateTime\Timestamp::monotonic()->since($start); - IO\write_error_line("duration : %s.", $duration->toString(max_decimals: 5)); + IO\write_error_line('duration : %s.', $duration->toString(max_decimals: 5)); return 0; }); diff --git a/examples/channel/bounded.php b/examples/channel/bounded.php index 79321817..3d32a452 100644 --- a/examples/channel/bounded.php +++ b/examples/channel/bounded.php @@ -24,7 +24,7 @@ $receiver->receive(); } } catch (Channel\Exception\ClosedChannelException) { - IO\write_error_line("[ receiver ]: completed."); + IO\write_error_line('[ receiver ]: completed.'); } }); @@ -37,9 +37,8 @@ $file->close(); } - IO\write_error_line("[ sender ]: completed."); + IO\write_error_line('[ sender ]: completed.'); $sender->close(); return 0; }); - diff --git a/examples/io/benchmark.php b/examples/io/benchmark.php index 219b3828..62d95416 100644 --- a/examples/io/benchmark.php +++ b/examples/io/benchmark.php @@ -28,7 +28,7 @@ $args = getopt('i:o:t:'); $input_file = $args['i'] ?? '/dev/zero'; $output_file = $args['o'] ?? '/dev/null'; - $seconds = DateTime\Duration::seconds((int)($args['t'] ?? 5)); + $seconds = DateTime\Duration::seconds((int) ($args['t'] ?? 5)); // passing file descriptors requires mapping paths (https://bugs.php.net/bug.php?id=53465) $input_file = Regex\replace($input_file, '(^/dev/fd/)', 'php://fd/'); @@ -55,10 +55,10 @@ $duration = DateTime\Timestamp::monotonic()->since($start); $bytes = $i * 65536; - $bytes_formatted = Math\round($bytes / 1024 / 1024 / $duration->getTotalSeconds(), 1); + $bytes_formatted = Math\round((($bytes / 1024) / 1024) / $duration->getTotalSeconds(), 1); IO\write_error_line('read %d byte(s) in %s => %dMiB/s', $bytes, $duration->toString(), $bytes_formatted); - IO\write_error_line('peak memory usage of %dMiB', Math\round(memory_get_peak_usage(true) / 1024 / 1024, 1)); + IO\write_error_line('peak memory usage of %dMiB', Math\round((memory_get_peak_usage(true) / 1024) / 1024, 1)); return 0; }); diff --git a/examples/io/pipe.php b/examples/io/pipe.php index 55e9b2c0..66fe58f8 100644 --- a/examples/io/pipe.php +++ b/examples/io/pipe.php @@ -10,25 +10,25 @@ require __DIR__ . '/../../vendor/autoload.php'; -Async\main(static function(): int { +Async\main(static function (): int { [$read, $write] = IO\pipe(); Async\concurrently([ - static function() use($read): void { - IO\write_error_line("< sleeping."); + static function () use ($read): void { + IO\write_error_line('< sleeping.'); Async\sleep(Duration::milliseconds(10)); - IO\write_error_line("< waiting for content."); + IO\write_error_line('< waiting for content.'); $content = $read->readAll(); IO\write_error_line('< received "%s".', $content); - IO\write_error_line("< closing."); + IO\write_error_line('< closing.'); $read->close(); }, - static function() use($write): void { + static function () use ($write): void { IO\write_error_line('> sleeping.'); Async\sleep(Duration::milliseconds(100)); diff --git a/examples/io/queued.php b/examples/io/queued.php index ae344e77..eaede2a8 100644 --- a/examples/io/queued.php +++ b/examples/io/queued.php @@ -10,14 +10,14 @@ require __DIR__ . '/../../vendor/autoload.php'; -Async\main(static function(): int { +Async\main(static function (): int { [$read, $write] = IO\pipe(); $he = Async\run(static fn(): string => $read->readFixedSize(2)); Async\sleep(Psl\DateTime\Duration::milliseconds(200)); - $write->write("hello"); + $write->write('hello'); $llo = $read->readFixedSize(3); diff --git a/examples/run.php b/examples/run.php index d2af7dbb..9bd5588d 100644 --- a/examples/run.php +++ b/examples/run.php @@ -1,6 +1,5 @@ started', $component, $script); - $awaitables[] = Async\run(static function() use($component, $script, $file): array { + $awaitables[] = Async\run(static function () use ($component, $script, $file): array { $start = DateTime\Timestamp::monotonic(); Shell\execute(PHP_BINARY, [$file]); $duration = DateTime\Timestamp::monotonic()->since($start); diff --git a/examples/tcp/basic-http-server.php b/examples/tcp/basic-http-server.php index 95bdeaa1..9e8507c6 100644 --- a/examples/tcp/basic-http-server.php +++ b/examples/tcp/basic-http-server.php @@ -35,15 +35,16 @@ IO\write_error_line('Click Ctrl+C to stop the server.'); Iter\apply($server->incoming(), static function (Network\StreamSocketInterface $connection): void { - Async\run(static function() use($connection): void { + Async\run(static function () use ($connection): void { $request = $connection->read(); $connection->writeAll("HTTP/1.1 200 OK\nConnection: close\nContent-Type: text/html; charset=utf-8\n\n"); $connection->writeAll(Str\format(RESPONSE_FORMAT, Html\encode_special_characters($request))); $connection->close(); - })->catch( - static fn(IO\Exception\ExceptionInterface $e) => IO\write_error_line('Error: %s.', $e->getMessage()) - )->ignore(); + })->catch(static fn(IO\Exception\ExceptionInterface $e) => IO\write_error_line( + 'Error: %s.', + $e->getMessage(), + ))->ignore(); }); IO\write_error_line(''); diff --git a/examples/unix/concurrent.php b/examples/unix/concurrent.php index a4cbe51d..3cccc167 100644 --- a/examples/unix/concurrent.php +++ b/examples/unix/concurrent.php @@ -20,7 +20,7 @@ return 0; } - $file = Filesystem\create_temporary_file(prefix: 'psl-examples') . ".sock"; + $file = Filesystem\create_temporary_file(prefix: 'psl-examples') . '.sock'; Async\concurrently([ 'server' => static function () use ($file): void { diff --git a/mago.toml b/mago.toml new file mode 100644 index 00000000..626f244f --- /dev/null +++ b/mago.toml @@ -0,0 +1,56 @@ +[source] +paths = ["src", "tests", "examples"] +includes = ["vendor"] +excludes = [] + +[format] +null_type_hint = "pipe" + +[linter] +level = "Error" +default_plugins = true +plugins = ["phpunit"] + +[[linter.rules]] +name = "best-practices/disallowed-functions" +functions = ["is_null", "assert"] + +[[linter.rules]] +name = "best-practices/excessive-nesting" +threshold = 5 + +[[linter.rules]] +name = "best-practices/no-debug-symbols" +level = "Error" + +[[linter.rules]] +name = "strictness/no-assignment-in-condition" +level = "Warning" + +[[linter.rules]] +name = "strictness/require-constant-type" +level = "Warning" + +[[linter.rules]] +name = "strictness/require-parameter-type" +level = "Warning" + +[[linter.rules]] +name = "strictness/require-property-type" +level = "Error" + +[[linter.rules]] +name = "strictness/require-return-type" +level = "Warning" + +[[linter.rules]] +name = "strictness/require-strict-types" +level = "Error" + +[[linter.rules]] +name = "safety/no-error-control-operator" +level = "Off" + +[[linter.rules]] +name = "safety/no-global" +level = "Warning" diff --git a/src/Psl/Async/Awaitable.php b/src/Psl/Async/Awaitable.php index 1d8ab514..cc18ce13 100644 --- a/src/Psl/Async/Awaitable.php +++ b/src/Psl/Async/Awaitable.php @@ -145,7 +145,7 @@ public function then(Closure $success, Closure $failure): Awaitable * @param null|Throwable $error * @param null|T $value */ - static function (?Throwable $error, mixed $value) use ($state, $success, $failure): void { + static function (null|Throwable $error, mixed $value) use ($state, $success, $failure): void { if ($error) { try { $state->complete($failure($error)); @@ -181,7 +181,7 @@ static function (?Throwable $error, mixed $value) use ($state, $success, $failur */ public function map(Closure $success): Awaitable { - return $this->then($success, static fn (Throwable $throwable) => throw $throwable); + return $this->then($success, static fn(Throwable $throwable) => throw $throwable); } /** @@ -220,7 +220,7 @@ public function always(Closure $always): Awaitable /** @var State $state */ $state = new State(); - $this->state->subscribe(static function (?Throwable $error, mixed $value) use ($state, $always): void { + $this->state->subscribe(static function (null|Throwable $error, mixed $value) use ($state, $always): void { try { $always(); @@ -256,7 +256,7 @@ public function await(): mixed * @param null|Throwable $error * @param null|T $value */ - static function (?Throwable $error, mixed $value) use ($suspension): void { + static function (null|Throwable $error, mixed $value) use ($suspension): void { if ($error) { $suspension->throw($error); } else { diff --git a/src/Psl/Async/Exception/CompositeException.php b/src/Psl/Async/Exception/CompositeException.php index 48ed59b4..6101baa5 100644 --- a/src/Psl/Async/Exception/CompositeException.php +++ b/src/Psl/Async/Exception/CompositeException.php @@ -23,7 +23,7 @@ final class CompositeException extends Exception implements ExceptionInterface * @param non-empty-array $reasons Array of exceptions. * @param string|null $message Exception message, defaults to message generated from passed exceptions. */ - public function __construct(array $reasons, ?string $message = null) + public function __construct(array $reasons, null|string $message = null) { parent::__construct($message ?? $this->generateMessage($reasons)); @@ -43,7 +43,11 @@ public function getReasons(): array */ private function generateMessage(array $reasons): string { - $message = Str\format('"Multiple errors encountered (%d); use "%s::getReasons()" to retrieve the array of exceptions thrown:', count($reasons), self::class); + $message = Str\format( + '"Multiple errors encountered (%d); use "%s::getReasons()" to retrieve the array of exceptions thrown:', + count($reasons), + self::class, + ); foreach ($reasons as $reason) { $message .= PHP_EOL . PHP_EOL . $reason::class; diff --git a/src/Psl/Async/Exception/UnhandledAwaitableException.php b/src/Psl/Async/Exception/UnhandledAwaitableException.php index e6de6270..01052696 100644 --- a/src/Psl/Async/Exception/UnhandledAwaitableException.php +++ b/src/Psl/Async/Exception/UnhandledAwaitableException.php @@ -13,9 +13,12 @@ final class UnhandledAwaitableException extends RuntimeException implements Exce public static function forThrowable(Throwable $throwable): UnhandledAwaitableException { return new self( - Str\format('Unhandled awaitable error "%s", make sure to call `Awaitable::await()` before the awaitable is destroyed, or call `Awaitable::ignore()` to ignore exceptions.', $throwable::class), + Str\format( + 'Unhandled awaitable error "%s", make sure to call `Awaitable::await()` before the awaitable is destroyed, or call `Awaitable::ignore()` to ignore exceptions.', + $throwable::class, + ), (int) $throwable->getCode(), - $throwable + $throwable, ); } } diff --git a/src/Psl/Async/Internal/AwaitableIterator.php b/src/Psl/Async/Internal/AwaitableIterator.php index a6710edd..accd2ee2 100644 --- a/src/Psl/Async/Internal/AwaitableIterator.php +++ b/src/Psl/Async/Internal/AwaitableIterator.php @@ -38,7 +38,7 @@ final class AwaitableIterator /** * @var null|Awaitable|Awaitable|Awaitable}> */ - private ?Awaitable $complete = null; + private null|Awaitable $complete = null; public function __construct() { @@ -63,15 +63,7 @@ public function enqueue(State $state, mixed $key, Awaitable $awaitable): void /** * @param Tv|null $_result */ - static function ( - ?Throwable $_error, - mixed $_result, - string $id - ) use ( - $key, - $awaitable, - $queue - ): void { + static function (null|Throwable $_error, mixed $_result, string $id) use ($key, $awaitable, $queue): void { unset($queue->pending[$id]); if ($queue->suspension) { @@ -81,7 +73,7 @@ static function ( } $queue->items[] = [$key, $awaitable]; - } + }, ); $queue->pending[$id] = $state; @@ -126,7 +118,7 @@ public function error(Throwable $exception): void * * @return null|array{0: Tk, 1: Awaitable} */ - public function consume(): ?array + public function consume(): null|array { if (null !== $this->queue->suspension) { Psl\invariant_violation('Concurrent consume() operations are not supported'); diff --git a/src/Psl/Async/Internal/AwaitableIteratorQueue.php b/src/Psl/Async/Internal/AwaitableIteratorQueue.php index 260f19a9..3987e90e 100644 --- a/src/Psl/Async/Internal/AwaitableIteratorQueue.php +++ b/src/Psl/Async/Internal/AwaitableIteratorQueue.php @@ -35,5 +35,5 @@ final class AwaitableIteratorQueue */ public array $pending = []; - public ?Suspension $suspension = null; + public null|Suspension $suspension = null; } diff --git a/src/Psl/Async/Internal/State.php b/src/Psl/Async/Internal/State.php index 1d1e1aac..b9a8f223 100644 --- a/src/Psl/Async/Internal/State.php +++ b/src/Psl/Async/Internal/State.php @@ -45,7 +45,7 @@ final class State */ private mixed $result = null; - private ?Throwable $throwable = null; + private null|Throwable $throwable = null; /** * @throws Exception\UnhandledAwaitableException diff --git a/src/Psl/Async/OptionalIncrementalTimeout.php b/src/Psl/Async/OptionalIncrementalTimeout.php index 78b511aa..dd0459a8 100644 --- a/src/Psl/Async/OptionalIncrementalTimeout.php +++ b/src/Psl/Async/OptionalIncrementalTimeout.php @@ -24,7 +24,7 @@ final class OptionalIncrementalTimeout /** * @var ?Timestamp The end time. */ - private ?Timestamp $end; + private null|Timestamp $end; /** * @var (Closure(): ?Duration) The handler to be called upon timeout. @@ -35,7 +35,7 @@ final class OptionalIncrementalTimeout * @param null|Duration $timeout The timeout duration. Null to disable timeout. * @param (Closure(): ?Duration) $handler The handler to be executed if the timeout is reached. */ - public function __construct(?Duration $timeout, Closure $handler) + public function __construct(null|Duration $timeout, Closure $handler) { $this->handler = $handler; @@ -59,7 +59,7 @@ public function __construct(?Duration $timeout, Closure $handler) * * @return Duration|null The remaining time duration, null if no timeout is set, or the handler's return value if the timeout is exceeded. */ - public function getRemaining(): ?Duration + public function getRemaining(): null|Duration { if ($this->end === null) { return null; diff --git a/src/Psl/Async/Scheduler.php b/src/Psl/Async/Scheduler.php index e499afbb..c32372a3 100644 --- a/src/Psl/Async/Scheduler.php +++ b/src/Psl/Async/Scheduler.php @@ -144,7 +144,6 @@ public static function repeat(DateTime\Duration $interval, Closure $callback): s return EventLoop::repeat($interval->getTotalSeconds(), $callback); } - /** * Enable a callback to be active starting in the next tick. * diff --git a/src/Psl/Async/all.php b/src/Psl/Async/all.php index a534cdfb..c25aa731 100644 --- a/src/Psl/Async/all.php +++ b/src/Psl/Async/all.php @@ -48,7 +48,10 @@ function all(iterable $awaitables): array throw $exception; } - throw new Exception\CompositeException([$exception, ...$errors], 'Multiple exceptions thrown while waiting.'); + throw new Exception\CompositeException( + [$exception, ...$errors], + 'Multiple exceptions thrown while waiting.', + ); } } diff --git a/src/Psl/Async/later.php b/src/Psl/Async/later.php index 7665bb0e..8c364f36 100644 --- a/src/Psl/Async/later.php +++ b/src/Psl/Async/later.php @@ -17,7 +17,7 @@ function later(): void { $suspension = EventLoop::getSuspension(); - EventLoop::defer(static fn () => $suspension->resume()); + EventLoop::defer(static fn() => $suspension->resume()); $suspension->suspend(); } diff --git a/src/Psl/Async/sleep.php b/src/Psl/Async/sleep.php index 394ab5c7..584081bf 100644 --- a/src/Psl/Async/sleep.php +++ b/src/Psl/Async/sleep.php @@ -13,10 +13,7 @@ function sleep(DateTime\Duration $duration): void { $suspension = EventLoop::getSuspension(); - $watcher = EventLoop::delay( - $duration->getTotalSeconds(), - static fn () => $suspension->resume(), - ); + $watcher = EventLoop::delay($duration->getTotalSeconds(), static fn() => $suspension->resume()); try { $suspension->suspend(); diff --git a/src/Psl/Channel/ChannelInterface.php b/src/Psl/Channel/ChannelInterface.php index 4f7afa3d..1b20f83e 100644 --- a/src/Psl/Channel/ChannelInterface.php +++ b/src/Psl/Channel/ChannelInterface.php @@ -18,7 +18,7 @@ interface ChannelInterface extends Countable * * @psalm-mutation-free */ - public function getCapacity(): ?int; + public function getCapacity(): null|int; /** * Closes the channel. diff --git a/src/Psl/Channel/Internal/ChannelSideTrait.php b/src/Psl/Channel/Internal/ChannelSideTrait.php index 33ce5f6b..19a34f15 100644 --- a/src/Psl/Channel/Internal/ChannelSideTrait.php +++ b/src/Psl/Channel/Internal/ChannelSideTrait.php @@ -21,7 +21,7 @@ trait ChannelSideTrait * * @psalm-mutation-free */ - public function getCapacity(): ?int + public function getCapacity(): null|int { /** @var null|int<1, max> */ return $this->state->getCapacity(); diff --git a/src/Psl/Collection/AccessibleCollectionInterface.php b/src/Psl/Collection/AccessibleCollectionInterface.php index ad37ea53..1dcc84fa 100644 --- a/src/Psl/Collection/AccessibleCollectionInterface.php +++ b/src/Psl/Collection/AccessibleCollectionInterface.php @@ -244,7 +244,7 @@ public function dropWhile(Closure $fn): AccessibleCollectionInterface; * * @psalm-mutation-free */ - public function slice(int $start, ?int $length = null): AccessibleCollectionInterface; + public function slice(int $start, null|int $length = null): AccessibleCollectionInterface; /** * Returns a `AccessibleCollectionInterface` containing the original `AccessibleCollectionInterface` split into diff --git a/src/Psl/Collection/CollectionInterface.php b/src/Psl/Collection/CollectionInterface.php index 87d63df5..8075caaf 100644 --- a/src/Psl/Collection/CollectionInterface.php +++ b/src/Psl/Collection/CollectionInterface.php @@ -203,7 +203,7 @@ public function dropWhile(Closure $fn): CollectionInterface; * * @psalm-mutation-free */ - public function slice(int $start, ?int $length = null): CollectionInterface; + public function slice(int $start, null|int $length = null): CollectionInterface; /** * Returns a `CollectionInterface` containing the original `CollectionInterface` split into diff --git a/src/Psl/Collection/Map.php b/src/Psl/Collection/Map.php index 3f486fe6..4f445d2b 100644 --- a/src/Psl/Collection/Map.php +++ b/src/Psl/Collection/Map.php @@ -279,7 +279,6 @@ public function get(int|string $k): mixed return $this->elements[$k] ?? null; } - /** * Returns a `Vector` containing the values of the current * `Map`. @@ -532,7 +531,7 @@ public function dropWhile(Closure $fn): Map * * @psalm-mutation-free */ - public function slice(int $start, ?int $length = null): Map + public function slice(int $start, null|int $length = null): Map { /** @psalm-suppress ImpureFunctionCall - conditionally pure */ $result = Dict\slice($this->elements, $start, $length); @@ -575,7 +574,7 @@ static function (Vector $vector): Map { } return Map::fromArray($array); - } + }, ); } } diff --git a/src/Psl/Collection/MapInterface.php b/src/Psl/Collection/MapInterface.php index fa74a144..67098667 100644 --- a/src/Psl/Collection/MapInterface.php +++ b/src/Psl/Collection/MapInterface.php @@ -276,7 +276,7 @@ public function dropWhile(Closure $fn): MapInterface; * * @psalm-mutation-free */ - public function slice(int $start, ?int $length = null): MapInterface; + public function slice(int $start, null|int $length = null): MapInterface; /** * Returns a `VectorInterface` containing the original `MapInterface` split into diff --git a/src/Psl/Collection/MutableAccessibleCollectionInterface.php b/src/Psl/Collection/MutableAccessibleCollectionInterface.php index c3355724..c0c4954d 100644 --- a/src/Psl/Collection/MutableAccessibleCollectionInterface.php +++ b/src/Psl/Collection/MutableAccessibleCollectionInterface.php @@ -222,7 +222,7 @@ public function dropWhile(Closure $fn): MutableAccessibleCollectionInterface; * * @psalm-mutation-free */ - public function slice(int $start, ?int $length = null): MutableAccessibleCollectionInterface; + public function slice(int $start, null|int $length = null): MutableAccessibleCollectionInterface; /** * Returns a `MutableAccessibleCollectionInterface` containing the original `MutableAccessibleCollectionInterface` split into diff --git a/src/Psl/Collection/MutableCollectionInterface.php b/src/Psl/Collection/MutableCollectionInterface.php index 0e5149d6..dffa265c 100644 --- a/src/Psl/Collection/MutableCollectionInterface.php +++ b/src/Psl/Collection/MutableCollectionInterface.php @@ -174,7 +174,7 @@ public function dropWhile(Closure $fn): MutableCollectionInterface; * * @psalm-mutation-free */ - public function slice(int $start, ?int $length = null): MutableCollectionInterface; + public function slice(int $start, null|int $length = null): MutableCollectionInterface; /** * Returns a `MutableCollectionInterface` containing the original `MutableCollectionInterface` split into diff --git a/src/Psl/Collection/MutableMap.php b/src/Psl/Collection/MutableMap.php index 7dd1d252..5d98de63 100644 --- a/src/Psl/Collection/MutableMap.php +++ b/src/Psl/Collection/MutableMap.php @@ -537,7 +537,7 @@ public function dropWhile(Closure $fn): MutableMap * * @psalm-mutation-free */ - public function slice(int $start, ?int $length = null): MutableMap + public function slice(int $start, null|int $length = null): MutableMap { /** @psalm-suppress ImpureFunctionCall - conditionally pure */ return self::fromArray(Dict\slice($this->elements, $start, $length)); @@ -580,7 +580,7 @@ static function (MutableVector $vector): MutableMap { } return MutableMap::fromArray($array); - } + }, ); } @@ -730,7 +730,9 @@ public function clear(): MutableMap public function offsetExists(mixed $offset): bool { if (!is_int($offset) && !is_string($offset)) { - throw new Exception\InvalidOffsetException('Invalid map read offset type, expected a string or an integer.'); + throw new Exception\InvalidOffsetException( + 'Invalid map read offset type, expected a string or an integer.', + ); } /** @var Tk $offset - technically, we don't know if the offset is of type Tk, but we can assume it is, as this causes no "harm". */ @@ -754,7 +756,9 @@ public function offsetExists(mixed $offset): bool public function offsetGet(mixed $offset): mixed { if (!is_int($offset) && !is_string($offset)) { - throw new Exception\InvalidOffsetException('Invalid map read offset type, expected a string or an integer.'); + throw new Exception\InvalidOffsetException( + 'Invalid map read offset type, expected a string or an integer.', + ); } /** @var Tk $offset - technically, we don't know if the offset is of type Tk, but we can assume it is, as this causes no "harm". */ @@ -777,7 +781,9 @@ public function offsetGet(mixed $offset): mixed public function offsetSet(mixed $offset, mixed $value): void { if (!is_int($offset) && !is_string($offset)) { - throw new Exception\InvalidOffsetException('Invalid map write offset type, expected a string or an integer.'); + throw new Exception\InvalidOffsetException( + 'Invalid map write offset type, expected a string or an integer.', + ); } /** @var Tk $offset - technically, we don't know if the offset is of type Tk, but we can assume it is, as this causes no "harm". */ @@ -798,7 +804,9 @@ public function offsetSet(mixed $offset, mixed $value): void public function offsetUnset(mixed $offset): void { if (!is_int($offset) && !is_string($offset)) { - throw new Exception\InvalidOffsetException('Invalid map read offset type, expected a string or an integer.'); + throw new Exception\InvalidOffsetException( + 'Invalid map read offset type, expected a string or an integer.', + ); } /** @var Tk $offset - technically, we don't know if the offset is of type Tk, but we can assume it is, as this causes no "harm". */ diff --git a/src/Psl/Collection/MutableMapInterface.php b/src/Psl/Collection/MutableMapInterface.php index 1c696f3f..2030b676 100644 --- a/src/Psl/Collection/MutableMapInterface.php +++ b/src/Psl/Collection/MutableMapInterface.php @@ -277,7 +277,7 @@ public function dropWhile(Closure $fn): MutableMapInterface; * * @psalm-mutation-free */ - public function slice(int $start, ?int $length = null): MutableMapInterface; + public function slice(int $start, null|int $length = null): MutableMapInterface; /** * Returns a `MutableVectorInterface` containing the original `MutableMapInterface` split into diff --git a/src/Psl/Collection/MutableSet.php b/src/Psl/Collection/MutableSet.php index 7def68cb..81de9f75 100644 --- a/src/Psl/Collection/MutableSet.php +++ b/src/Psl/Collection/MutableSet.php @@ -617,7 +617,7 @@ public function dropWhile(Closure $fn): MutableSet * * @psalm-mutation-free */ - public function slice(int $start, ?int $length = null): MutableSet + public function slice(int $start, null|int $length = null): MutableSet { /** @psalm-suppress ImpureFunctionCall - conditionally pure */ return MutableSet::fromArray(Dict\slice($this->elements, $start, $length)); @@ -654,7 +654,7 @@ public function chunk(int $size): MutableVector * * @return MutableSet */ - static fn(array $chunk) => MutableSet::fromArray($chunk) + static fn(array $chunk) => MutableSet::fromArray($chunk), )); } @@ -674,7 +674,9 @@ public function chunk(int $size): MutableVector public function offsetExists(mixed $offset): bool { if (!is_int($offset) && !is_string($offset)) { - throw new Exception\InvalidOffsetException('Invalid set read offset type, expected a string or an integer.'); + throw new Exception\InvalidOffsetException( + 'Invalid set read offset type, expected a string or an integer.', + ); } /** @var T $offset - technically, we don't know if the offset is of type T, but we can assume it is, as this causes no "harm". */ @@ -698,7 +700,9 @@ public function offsetExists(mixed $offset): bool public function offsetGet(mixed $offset): mixed { if (!is_int($offset) && !is_string($offset)) { - throw new Exception\InvalidOffsetException('Invalid set read offset type, expected a string or an integer.'); + throw new Exception\InvalidOffsetException( + 'Invalid set read offset type, expected a string or an integer.', + ); } /** @var T $offset - technically, we don't know if the offset is of type T, but we can assume it is, as this causes no "harm". */ @@ -725,7 +729,9 @@ public function offsetSet(mixed $offset, mixed $value): void return; } - throw new Exception\InvalidOffsetException('Invalid set write offset type, expected null or the same as the value.'); + throw new Exception\InvalidOffsetException( + 'Invalid set write offset type, expected null or the same as the value.', + ); } /** @@ -742,7 +748,9 @@ public function offsetSet(mixed $offset, mixed $value): void public function offsetUnset(mixed $offset): void { if (!is_int($offset) && !is_string($offset)) { - throw new Exception\InvalidOffsetException('Invalid set read offset type, expected a string or an integer.'); + throw new Exception\InvalidOffsetException( + 'Invalid set read offset type, expected a string or an integer.', + ); } /** @var T $offset - technically, we don't know if the offset is of type T, but we can assume it is, as this causes no "harm". */ diff --git a/src/Psl/Collection/MutableSetInterface.php b/src/Psl/Collection/MutableSetInterface.php index c6b68e0c..163fd2d3 100644 --- a/src/Psl/Collection/MutableSetInterface.php +++ b/src/Psl/Collection/MutableSetInterface.php @@ -318,7 +318,7 @@ public function dropWhile(Closure $fn): MutableSetInterface; * * @psalm-mutation-free */ - public function slice(int $start, ?int $length = null): MutableSetInterface; + public function slice(int $start, null|int $length = null): MutableSetInterface; /** * Returns a `MutableVectorInterface` containing the original `MutableSetInterface` split into diff --git a/src/Psl/Collection/MutableVector.php b/src/Psl/Collection/MutableVector.php index 1ade1cc9..c2381b6a 100644 --- a/src/Psl/Collection/MutableVector.php +++ b/src/Psl/Collection/MutableVector.php @@ -244,7 +244,7 @@ public function get(int|string $k): mixed * * @psalm-mutation-free */ - public function firstKey(): ?int + public function firstKey(): null|int { return [] === $this->elements ? null : 0; } @@ -257,7 +257,7 @@ public function firstKey(): ?int * * @psalm-mutation-free */ - public function lastKey(): ?int + public function lastKey(): null|int { return array_key_last($this->elements); } @@ -274,7 +274,7 @@ public function lastKey(): ?int * * @psalm-mutation-free */ - public function linearSearch(mixed $search_value): ?int + public function linearSearch(mixed $search_value): null|int { foreach ($this->elements as $key => $element) { if ($search_value === $element) { @@ -661,7 +661,7 @@ public function dropWhile(Closure $fn): MutableVector * * @psalm-mutation-free */ - public function slice(int $start, ?int $length = null): MutableVector + public function slice(int $start, null|int $length = null): MutableVector { /** @psalm-suppress ImpureFunctionCall - conditionally pure */ return MutableVector::fromArray(Dict\slice($this->elements, $start, $length)); @@ -700,11 +700,10 @@ public function chunk(int $size): MutableVector * * @return MutableVector */ - static fn(array $chunk) => MutableVector::fromArray($chunk) + static fn(array $chunk) => MutableVector::fromArray($chunk), )); } - /** * Determines if the specified offset exists in the current vector. * @@ -772,7 +771,9 @@ public function offsetSet(mixed $offset, mixed $value): void } if (!is_int($offset) || $offset < 0) { - throw new Exception\InvalidOffsetException('Invalid vector write offset type, expected a positive integer or null.'); + throw new Exception\InvalidOffsetException( + 'Invalid vector write offset type, expected a positive integer or null.', + ); } $this->set($offset, $value); diff --git a/src/Psl/Collection/MutableVectorInterface.php b/src/Psl/Collection/MutableVectorInterface.php index 3a507f97..0603cd4b 100644 --- a/src/Psl/Collection/MutableVectorInterface.php +++ b/src/Psl/Collection/MutableVectorInterface.php @@ -140,7 +140,7 @@ public function first(): mixed; * * @psalm-mutation-free */ - public function firstKey(): ?int; + public function firstKey(): null|int; /** * Returns the last value in the current `MutableVectorInterface`. @@ -160,7 +160,7 @@ public function last(): mixed; * * @psalm-mutation-free */ - public function lastKey(): ?int; + public function lastKey(): null|int; /** * Returns the index of the first element that matches the search value. @@ -174,7 +174,7 @@ public function lastKey(): ?int; * * @psalm-mutation-free */ - public function linearSearch(mixed $search_value): ?int; + public function linearSearch(mixed $search_value): null|int; /** * Returns a `MutableVectorInterface` where each element is a `array{0: Tv, 1: Tu}` that combines the @@ -287,7 +287,7 @@ public function dropWhile(Closure $fn): MutableVectorInterface; * * @psalm-mutation-free */ - public function slice(int $start, ?int $length = null): MutableVectorInterface; + public function slice(int $start, null|int $length = null): MutableVectorInterface; /** * Returns a `MutableVectorInterface` containing the original `MutableVectorInterface` split into diff --git a/src/Psl/Collection/Set.php b/src/Psl/Collection/Set.php index c87c65d8..9d2ad4e4 100644 --- a/src/Psl/Collection/Set.php +++ b/src/Psl/Collection/Set.php @@ -185,7 +185,6 @@ public function toArray(): array return $this->elements; } - /** * Get an array copy of the current `Set`. * @@ -368,7 +367,6 @@ public function filter(Closure $fn): Set return new Set(Dict\filter_keys($this->elements, $fn)); } - /** * Applies a user-defined condition to each value in the `Set`, * considering the value as both key and value. @@ -548,7 +546,7 @@ public function dropWhile(Closure $fn): Set * * @psalm-mutation-free */ - public function slice(int $start, ?int $length = null): Set + public function slice(int $start, null|int $length = null): Set { /** @psalm-suppress ImpureFunctionCall - conditionally pure */ return self::fromArray(Dict\slice($this->elements, $start, $length)); @@ -581,7 +579,7 @@ public function chunk(int $size): Vector * * @return Set */ - static fn(array $chunk) => static::fromArray($chunk) + static fn(array $chunk) => static::fromArray($chunk), )); } } diff --git a/src/Psl/Collection/SetInterface.php b/src/Psl/Collection/SetInterface.php index e8ba3fba..3233b0af 100644 --- a/src/Psl/Collection/SetInterface.php +++ b/src/Psl/Collection/SetInterface.php @@ -317,7 +317,7 @@ public function dropWhile(Closure $fn): SetInterface; * * @psalm-mutation-free */ - public function slice(int $start, ?int $length = null): SetInterface; + public function slice(int $start, null|int $length = null): SetInterface; /** * Returns a `VectorInterface` containing the original `SetInterface` split into diff --git a/src/Psl/Collection/Vector.php b/src/Psl/Collection/Vector.php index 83f6e557..aacdfe6c 100644 --- a/src/Psl/Collection/Vector.php +++ b/src/Psl/Collection/Vector.php @@ -165,7 +165,6 @@ public function toArray(): array return $this->elements; } - /** * Get an array copy of the current `Vector`. * @@ -244,7 +243,7 @@ public function get(int|string $k): mixed * * @psalm-mutation-free */ - public function firstKey(): ?int + public function firstKey(): null|int { return [] === $this->elements ? null : 0; } @@ -257,7 +256,7 @@ public function firstKey(): ?int * * @psalm-mutation-free */ - public function lastKey(): ?int + public function lastKey(): null|int { return array_key_last($this->elements); } @@ -274,7 +273,7 @@ public function lastKey(): ?int * * @psalm-mutation-free */ - public function linearSearch(mixed $search_value): ?int + public function linearSearch(mixed $search_value): null|int { foreach ($this->elements as $key => $element) { if ($search_value === $element) { @@ -527,7 +526,7 @@ public function dropWhile(Closure $fn): Vector * * @psalm-mutation-free */ - public function slice(int $start, ?int $length = null): Vector + public function slice(int $start, null|int $length = null): Vector { /** @psalm-suppress ImpureFunctionCall - conditionally pure */ return self::fromArray(Dict\slice($this->elements, $start, $length)); @@ -562,7 +561,7 @@ public function chunk(int $size): Vector * * @return Vector */ - static fn(array $chunk) => static::fromArray($chunk) + static fn(array $chunk) => static::fromArray($chunk), )); } } diff --git a/src/Psl/Collection/VectorInterface.php b/src/Psl/Collection/VectorInterface.php index 284b42da..49374333 100644 --- a/src/Psl/Collection/VectorInterface.php +++ b/src/Psl/Collection/VectorInterface.php @@ -168,7 +168,7 @@ public function first(): mixed; * * @psalm-mutation-free */ - public function firstKey(): ?int; + public function firstKey(): null|int; /** * Returns the last value in the current `VectorInterface`. @@ -188,7 +188,7 @@ public function last(): mixed; * * @psalm-mutation-free */ - public function lastKey(): ?int; + public function lastKey(): null|int; /** * Returns the index of the first element that matches the search value. @@ -202,7 +202,7 @@ public function lastKey(): ?int; * * @psalm-mutation-free */ - public function linearSearch(mixed $search_value): ?int; + public function linearSearch(mixed $search_value): null|int; /** * Returns a `VectorInterface` where each element is a `array{0: Tv, 1: Tu}` that combines the @@ -315,7 +315,7 @@ public function dropWhile(Closure $fn): VectorInterface; * * @psalm-mutation-free */ - public function slice(int $start, ?int $length = null): VectorInterface; + public function slice(int $start, null|int $length = null): VectorInterface; /** * Returns a `VectorInterface` containing the original `VectorInterface` split into diff --git a/src/Psl/Comparison/Exception/IncomparableException.php b/src/Psl/Comparison/Exception/IncomparableException.php index 6ccc9e3f..1a95ffdc 100644 --- a/src/Psl/Comparison/Exception/IncomparableException.php +++ b/src/Psl/Comparison/Exception/IncomparableException.php @@ -14,13 +14,11 @@ class IncomparableException extends InvalidArgumentRootException implements Exce { public static function fromValues(mixed $a, mixed $b, string $additionalInfo = ''): self { - return new self( - Str\format( - 'Unable to compare "%s" with "%s"%s', - get_debug_type($a), - get_debug_type($b), - $additionalInfo ? ': ' . $additionalInfo : '.', - ) - ); + return new self(Str\format( + 'Unable to compare "%s" with "%s"%s', + get_debug_type($a), + get_debug_type($b), + $additionalInfo ? (': ' . $additionalInfo) : '.', + )); } } diff --git a/src/Psl/DateTime/DateTime.php b/src/Psl/DateTime/DateTime.php index 87398c91..85e81ce8 100644 --- a/src/Psl/DateTime/DateTime.php +++ b/src/Psl/DateTime/DateTime.php @@ -65,8 +65,17 @@ * * @psalm-mutation-free */ - private function __construct(Timezone $timezone, Timestamp $timestamp, int $year, int $month, int $day, int $hours, int $minutes, int $seconds, int $nanoseconds) - { + private function __construct( + Timezone $timezone, + Timestamp $timestamp, + int $year, + int $month, + int $day, + int $hours, + int $minutes, + int $seconds, + int $nanoseconds, + ) { if ($nanoseconds < 0 || $nanoseconds >= NANOSECONDS_PER_SECOND) { throw Exception\InvalidArgumentException::forNanoseconds($nanoseconds); } @@ -112,7 +121,7 @@ private function __construct(Timezone $timezone, Timestamp $timestamp, int $year * * @psalm-mutation-free */ - public static function now(?Timezone $timezone = null): DateTime + public static function now(null|Timezone $timezone = null): DateTime { return self::fromTimestamp(Timestamp::now(), $timezone); } @@ -137,8 +146,13 @@ public static function now(?Timezone $timezone = null): DateTime * * @psalm-mutation-free */ - public static function todayAt(int $hours, int $minutes, int $seconds = 0, int $nanoseconds = 0, ?Timezone $timezone = null): DateTime - { + public static function todayAt( + int $hours, + int $minutes, + int $seconds = 0, + int $nanoseconds = 0, + null|Timezone $timezone = null, + ): DateTime { return self::now($timezone)->withTime($hours, $minutes, $seconds, $nanoseconds); } @@ -166,13 +180,29 @@ public static function todayAt(int $hours, int $minutes, int $seconds = 0, int $ * * @psalm-suppress ImpureMethodCall */ - public static function fromParts(Timezone $timezone, int $year, Month|int $month, int $day, int $hours = 0, int $minutes = 0, int $seconds = 0, int $nanoseconds = 0): self - { + public static function fromParts( + Timezone $timezone, + int $year, + Month|int $month, + int $day, + int $hours = 0, + int $minutes = 0, + int $seconds = 0, + int $nanoseconds = 0, + ): self { if ($month instanceof Month) { $month = $month->value; } - $calendar = Internal\create_intl_calendar_from_date_time($timezone, $year, $month, $day, $hours, $minutes, $seconds); + $calendar = Internal\create_intl_calendar_from_date_time( + $timezone, + $year, + $month, + $day, + $hours, + $minutes, + $seconds, + ); if ($seconds !== $calendar->get(IntlCalendar::FIELD_SECOND)) { throw Exception\UnexpectedValueException::forSeconds($seconds, $calendar->get(IntlCalendar::FIELD_SECOND)); @@ -203,17 +233,7 @@ public static function fromParts(Timezone $timezone, int $year, Month|int $month $timestamp = Timestamp::fromParts($timestamp_in_seconds, $nanoseconds); /** @psalm-suppress MissingThrowsDocblock */ - return new self( - $timezone, - $timestamp, - $year, - $month, - $day, - $hours, - $minutes, - $seconds, - $nanoseconds - ); + return new self($timezone, $timestamp, $year, $month, $day, $hours, $minutes, $seconds, $nanoseconds); } /** @@ -229,18 +249,14 @@ public static function fromParts(Timezone $timezone, int $year, Month|int $month * * @psalm-suppress ImpureMethodCall */ - public static function fromTimestamp(Timestamp $timestamp, ?Timezone $timezone = null): static + public static function fromTimestamp(Timestamp $timestamp, null|Timezone $timezone = null): static { $timezone ??= Timezone::default(); /** @var IntlCalendar $calendar */ - $calendar = IntlCalendar::createInstance( - Internal\to_intl_timezone($timezone), - ); + $calendar = IntlCalendar::createInstance(Internal\to_intl_timezone($timezone)); - $calendar->setTime( - $timestamp->getSeconds() * MILLISECONDS_PER_SECOND, - ); + $calendar->setTime($timestamp->getSeconds() * MILLISECONDS_PER_SECOND); $year = $calendar->get(IntlCalendar::FIELD_YEAR); $month = $calendar->get(IntlCalendar::FIELD_MONTH) + 1; @@ -251,20 +267,9 @@ public static function fromTimestamp(Timestamp $timestamp, ?Timezone $timezone = $nanoseconds = $timestamp->getNanoseconds(); /** @psalm-suppress MissingThrowsDocblock */ - return new static( - $timezone, - $timestamp, - $year, - $month, - $day, - $hour, - $minute, - $second, - $nanoseconds, - ); + return new static($timezone, $timestamp, $year, $month, $day, $hour, $minute, $second, $nanoseconds); } - /** * Parses a date and time string into an instance of {@see Timestamp} using a specific format pattern, with optional customization for timezone and locale. * @@ -295,8 +300,12 @@ public static function fromTimestamp(Timestamp $timestamp, ?Timezone $timezone = * * @psalm-mutation-free */ - public static function parse(string $raw_string, null|FormatPattern|string $pattern = null, ?Timezone $timezone = null, null|Locale $locale = null): static - { + public static function parse( + string $raw_string, + null|FormatPattern|string $pattern = null, + null|Timezone $timezone = null, + null|Locale $locale = null, + ): static { $timezone ??= Timezone::default(); return self::fromTimestamp(Timestamp::parse($raw_string, $pattern, $timezone, $locale), $timezone); @@ -334,11 +343,19 @@ public static function parse(string $raw_string, null|FormatPattern|string $patt * * @psalm-mutation-free */ - public static function fromString(string $raw_string, null|DateStyle $date_style = null, null|TimeStyle $time_style = null, null|Timezone $timezone = null, null|Locale $locale = null): static - { + public static function fromString( + string $raw_string, + null|DateStyle $date_style = null, + null|TimeStyle $time_style = null, + null|Timezone $timezone = null, + null|Locale $locale = null, + ): static { $timezone ??= Timezone::default(); - return self::fromTimestamp(Timestamp::fromString($raw_string, $date_style, $time_style, $timezone, $locale), $timezone); + return self::fromTimestamp( + Timestamp::fromString($raw_string, $date_style, $time_style, $timezone, $locale), + $timezone, + ); } /** diff --git a/src/Psl/DateTime/DateTimeConvenienceMethodsTrait.php b/src/Psl/DateTime/DateTimeConvenienceMethodsTrait.php index 383b7e08..3d93caaa 100644 --- a/src/Psl/DateTime/DateTimeConvenienceMethodsTrait.php +++ b/src/Psl/DateTime/DateTimeConvenienceMethodsTrait.php @@ -256,7 +256,7 @@ public function getEra(): Era */ public function getCentury(): int { - return (int)($this->getYear() / 100) + 1; + return ((int) ($this->getYear() / 100)) + 1; } /** @@ -297,8 +297,8 @@ public function getMonthEnum(): Month public function getTwelveHours(): array { return [ - ($this->getHours() % 12 ?: 12), - ($this->getHours() < 12 ? Meridiem::AnteMeridiem : Meridiem::PostMeridiem), + ($this->getHours() % 12) ?: 12, + $this->getHours() < 12 ? Meridiem::AnteMeridiem : Meridiem::PostMeridiem, ]; } @@ -331,8 +331,8 @@ public function getTwelveHours(): array public function getISOWeekNumber(): array { /** @var int<1, 53> $week */ - $week = (int)$this->format(pattern: 'w'); - $year = (int)$this->format(pattern: 'Y'); + $week = (int) $this->format(pattern: 'w'); + $year = (int) $this->format(pattern: 'Y'); return [$year, $week]; } @@ -416,10 +416,7 @@ public function plusMonths(int $months): static return $this->withDate( $target_year = $this->getYear() + $plus_years, $target_month_enum->value, - Math\minva( - $this->getDay(), - $target_month_enum->getDaysForYear($target_year) - ) + Math\minva($this->getDay(), $target_month_enum->getDaysForYear($target_year)), ); } @@ -456,10 +453,7 @@ public function minusMonths(int $months): static return $this->withDate( $target_year = $this->getYear() - $minus_years, $target_month_enum->value, - Math\minva( - $this->getDay(), - $target_month_enum->getDaysForYear($target_year) - ) + Math\minva($this->getDay(), $target_month_enum->getDaysForYear($target_year)), ); } @@ -539,16 +533,24 @@ public function minus(Duration $duration): static * * @psalm-mutation-free */ - public function format(null|FormatPattern|string $pattern = null, null|Timezone $timezone = null, null|Locale $locale = null): string - { + public function format( + null|FormatPattern|string $pattern = null, + null|Timezone $timezone = null, + null|Locale $locale = null, + ): string { $timestamp = $this->getTimestamp(); /** * @psalm-suppress InvalidOperand * @psalm-suppress ImpureMethodCall */ - return Internal\create_intl_date_formatter(null, null, $pattern, $timezone ?? $this->getTimezone(), $locale) - ->format($timestamp->getSeconds() + ($timestamp->getNanoseconds() / NANOSECONDS_PER_SECOND)); + return Internal\create_intl_date_formatter( + null, + null, + $pattern, + $timezone ?? $this->getTimezone(), + $locale, + )->format($timestamp->getSeconds() + ($timestamp->getNanoseconds() / NANOSECONDS_PER_SECOND)); } /** @@ -578,7 +580,7 @@ public function format(null|FormatPattern|string $pattern = null, null|Timezone * * @psalm-mutation-free */ - public function toRfc3339(?SecondsStyle $seconds_style = null, bool $use_z = false): string + public function toRfc3339(null|SecondsStyle $seconds_style = null, bool $use_z = false): string { return Internal\format_rfc3339($this->getTimestamp(), $seconds_style, $use_z, $this->getTimezone()); } @@ -611,14 +613,23 @@ public function toRfc3339(?SecondsStyle $seconds_style = null, bool $use_z = fal * * @psalm-mutation-free */ - public function toString(null|DateStyle $date_style = null, null|TimeStyle $time_style = null, null|Timezone $timezone = null, null|Locale $locale = null): string - { + public function toString( + null|DateStyle $date_style = null, + null|TimeStyle $time_style = null, + null|Timezone $timezone = null, + null|Locale $locale = null, + ): string { $timestamp = $this->getTimestamp(); /** * @psalm-suppress ImpureMethodCall */ - return Internal\create_intl_date_formatter($date_style, $time_style, null, $timezone ?? $this->getTimezone(), $locale) - ->format($timestamp->getSeconds()); + return Internal\create_intl_date_formatter( + $date_style, + $time_style, + null, + $timezone ?? $this->getTimezone(), + $locale, + )->format($timestamp->getSeconds()); } } diff --git a/src/Psl/DateTime/DateTimeInterface.php b/src/Psl/DateTime/DateTimeInterface.php index c1f4edb3..9cba1fe3 100644 --- a/src/Psl/DateTime/DateTimeInterface.php +++ b/src/Psl/DateTime/DateTimeInterface.php @@ -19,7 +19,7 @@ interface DateTimeInterface extends TemporalInterface * * @psalm-mutation-free */ - public static function fromTimestamp(Timestamp $timestamp, ?Timezone $timezone = null): static; + public static function fromTimestamp(Timestamp $timestamp, null|Timezone $timezone = null): static; /** * Checks if this {@see DateTimeInterface} instance is equal to the given {@see DateTimeInterface} instance including the timezone. @@ -453,7 +453,11 @@ public function minusDays(int $days): static; * * @psalm-mutation-free */ - public function format(null|FormatPattern|string $pattern = null, null|Timezone $timezone = null, null|Locale $locale = null): string; + public function format( + null|FormatPattern|string $pattern = null, + null|Timezone $timezone = null, + null|Locale $locale = null, + ): string; /** * Provides a string representation of this {@see TemporalInterface} instance, formatted according to specified styles for date and time, @@ -483,7 +487,12 @@ public function format(null|FormatPattern|string $pattern = null, null|Timezone * * @psalm-mutation-free */ - public function toString(null|DateStyle $date_style = null, null|TimeStyle $time_style = null, null|Timezone $timezone = null, null|Locale $locale = null): string; + public function toString( + null|DateStyle $date_style = null, + null|TimeStyle $time_style = null, + null|Timezone $timezone = null, + null|Locale $locale = null, + ): string; /** * Formats this {@see DateTimeInterface} instance to a string based on the RFC 3339 format, with additional @@ -512,7 +521,7 @@ public function toString(null|DateStyle $date_style = null, null|TimeStyle $time * * @psalm-mutation-free */ - public function toRfc3339(?SecondsStyle $seconds_style = null, bool $use_z = false): string; + public function toRfc3339(null|SecondsStyle $seconds_style = null, bool $use_z = false): string; /** * Magic method that provides a default string representation of the date and time. diff --git a/src/Psl/DateTime/Duration.php b/src/Psl/DateTime/Duration.php index 5a5b54cd..05d20f56 100644 --- a/src/Psl/DateTime/Duration.php +++ b/src/Psl/DateTime/Duration.php @@ -44,7 +44,7 @@ private function __construct( private int $hours, private int $minutes, private int $seconds, - private int $nanoseconds + private int $nanoseconds, ) { } @@ -58,7 +58,11 @@ private function __construct( public static function fromParts(int $hours, int $minutes = 0, int $seconds = 0, int $nanoseconds = 0): self { // This is where the normalization happens. - $s = (SECONDS_PER_HOUR * $hours) + (SECONDS_PER_MINUTE * $minutes) + ($seconds + (int)($nanoseconds / NANOSECONDS_PER_SECOND)); + $s = + (SECONDS_PER_HOUR * $hours) + + (SECONDS_PER_MINUTE * $minutes) + + $seconds + + ((int) ($nanoseconds / NANOSECONDS_PER_SECOND)); $ns = $nanoseconds % NANOSECONDS_PER_SECOND; if ($s < 0 && $ns > 0) { ++$s; @@ -68,9 +72,9 @@ public static function fromParts(int $hours, int $minutes = 0, int $seconds = 0, $ns += NANOSECONDS_PER_SECOND; } - $m = (int)($s / 60); + $m = (int) ($s / 60); $s %= 60; - $h = (int)($m / 60); + $h = (int) ($m / 60); $m %= 60; return new self($h, $m, $s, $ns); } @@ -252,9 +256,12 @@ public function getNanoseconds(): int public function getTotalHours(): float { /** @psalm-suppress InvalidOperand */ - return ($this->hours + ($this->minutes / MINUTES_PER_HOUR) + + return ( + $this->hours + + ($this->minutes / MINUTES_PER_HOUR) + ($this->seconds / SECONDS_PER_HOUR) + - ($this->nanoseconds / (SECONDS_PER_HOUR * NANOSECONDS_PER_SECOND))); + ($this->nanoseconds / (SECONDS_PER_HOUR * NANOSECONDS_PER_SECOND)) + ); } /** @@ -266,9 +273,12 @@ public function getTotalHours(): float public function getTotalMinutes(): float { /** @psalm-suppress InvalidOperand */ - return (($this->hours * MINUTES_PER_HOUR) + - $this->minutes + ($this->seconds / SECONDS_PER_MINUTE) + - ($this->nanoseconds / (SECONDS_PER_MINUTE * NANOSECONDS_PER_SECOND))); + return ( + ($this->hours * MINUTES_PER_HOUR) + + $this->minutes + + ($this->seconds / SECONDS_PER_MINUTE) + + ($this->nanoseconds / (SECONDS_PER_MINUTE * NANOSECONDS_PER_SECOND)) + ); } /** @@ -280,10 +290,12 @@ public function getTotalMinutes(): float public function getTotalSeconds(): float { /** @psalm-suppress InvalidOperand */ - return ($this->seconds + + return ( + $this->seconds + ($this->minutes * SECONDS_PER_MINUTE) + ($this->hours * SECONDS_PER_HOUR) + - ($this->nanoseconds / NANOSECONDS_PER_SECOND)); + ($this->nanoseconds / NANOSECONDS_PER_SECOND) + ); } /** @@ -295,10 +307,12 @@ public function getTotalSeconds(): float public function getTotalMilliseconds(): float { /** @psalm-suppress InvalidOperand */ - return (($this->hours * SECONDS_PER_HOUR * MILLISECONDS_PER_SECOND) + + return ( + ($this->hours * SECONDS_PER_HOUR * MILLISECONDS_PER_SECOND) + ($this->minutes * SECONDS_PER_MINUTE * MILLISECONDS_PER_SECOND) + ($this->seconds * MILLISECONDS_PER_SECOND) + - ($this->nanoseconds / NANOSECONDS_PER_MILLISECOND)); + ($this->nanoseconds / NANOSECONDS_PER_MILLISECOND) + ); } /** @@ -310,10 +324,12 @@ public function getTotalMilliseconds(): float public function getTotalMicroseconds(): float { /** @psalm-suppress InvalidOperand */ - return (($this->hours * SECONDS_PER_HOUR * MICROSECONDS_PER_SECOND) + + return ( + ($this->hours * SECONDS_PER_HOUR * MICROSECONDS_PER_SECOND) + ($this->minutes * SECONDS_PER_MINUTE * MICROSECONDS_PER_SECOND) + ($this->seconds * MICROSECONDS_PER_SECOND) + - ($this->nanoseconds / NANOSECONDS_PER_MICROSECOND)); + ($this->nanoseconds / NANOSECONDS_PER_MICROSECOND) + ); } /** @@ -323,10 +339,7 @@ public function getTotalMicroseconds(): float */ public function isZero(): bool { - return $this->hours === 0 && - $this->minutes === 0 && - $this->seconds === 0 && - $this->nanoseconds === 0; + return $this->hours === 0 && $this->minutes === 0 && $this->seconds === 0 && $this->nanoseconds === 0; } /** @@ -342,10 +355,7 @@ public function isZero(): bool */ public function isPositive(): bool { - return $this->hours > 0 || - $this->minutes > 0 || - $this->seconds > 0 || - $this->nanoseconds > 0; + return $this->hours > 0 || $this->minutes > 0 || $this->seconds > 0 || $this->nanoseconds > 0; } /** @@ -361,10 +371,7 @@ public function isPositive(): bool */ public function isNegative(): bool { - return $this->hours < 0 || - $this->minutes < 0 || - $this->seconds < 0 || - $this->nanoseconds < 0; + return $this->hours < 0 || $this->minutes < 0 || $this->seconds < 0 || $this->nanoseconds < 0; } /** @@ -382,12 +389,7 @@ public function isNegative(): bool */ public function withHours(int $hours): self { - return self::fromParts( - $hours, - $this->minutes, - $this->seconds, - $this->nanoseconds, - ); + return self::fromParts($hours, $this->minutes, $this->seconds, $this->nanoseconds); } /** @@ -405,12 +407,7 @@ public function withHours(int $hours): self */ public function withMinutes(int $minutes): self { - return self::fromParts( - $this->hours, - $minutes, - $this->seconds, - $this->nanoseconds, - ); + return self::fromParts($this->hours, $minutes, $this->seconds, $this->nanoseconds); } /** @@ -428,12 +425,7 @@ public function withMinutes(int $minutes): self */ public function withSeconds(int $seconds): self { - return self::fromParts( - $this->hours, - $this->minutes, - $seconds, - $this->nanoseconds, - ); + return self::fromParts($this->hours, $this->minutes, $seconds, $this->nanoseconds); } /** @@ -451,12 +443,7 @@ public function withSeconds(int $seconds): self */ public function withNanoseconds(int $nanoseconds): self { - return self::fromParts( - $this->hours, - $this->minutes, - $this->seconds, - $nanoseconds, - ); + return self::fromParts($this->hours, $this->minutes, $this->seconds, $nanoseconds); } /** @@ -581,12 +568,7 @@ public function invert(): self return $this; } - return new self( - -$this->hours, - -$this->minutes, - -$this->seconds, - -$this->nanoseconds, - ); + return new self(-$this->hours, -$this->minutes, -$this->seconds, -$this->nanoseconds); } /** @@ -661,7 +643,7 @@ public function toString(int $max_decimals = 3): string { $decimal_part = ''; if ($max_decimals > 0) { - $decimal_part = (string)Math\abs($this->nanoseconds); + $decimal_part = (string) Math\abs($this->nanoseconds); $decimal_part = Str\pad_left($decimal_part, 9, '0'); $decimal_part = Str\slice($decimal_part, 0, $max_decimals); $decimal_part = Str\trim_right($decimal_part, '0'); @@ -674,7 +656,6 @@ public function toString(int $max_decimals = 3): string $sec_sign = $this->seconds < 0 || $this->nanoseconds < 0 ? '-' : ''; $sec = Math\abs($this->seconds); - $containsHours = $this->hours !== 0; $containsMinutes = $this->minutes !== 0; $concatenatedSeconds = $sec_sign . ((string) $sec) . $decimal_part; @@ -686,7 +667,7 @@ public function toString(int $max_decimals = 3): string $output[] = ((string) $this->hours) . ' hour(s)'; } - if ($containsMinutes || ($containsHours && $containsSeconds)) { + if ($containsMinutes || $containsHours && $containsSeconds) { $output[] = ((string) $this->minutes) . ' minute(s)'; } @@ -694,7 +675,7 @@ public function toString(int $max_decimals = 3): string $output[] = $concatenatedSeconds . ' second(s)'; } - return ([] === $output) ? '0 second(s)' : Str\join($output, ', '); + return [] === $output ? '0 second(s)' : Str\join($output, ', '); } /** diff --git a/src/Psl/DateTime/Exception/InvalidArgumentException.php b/src/Psl/DateTime/Exception/InvalidArgumentException.php index 40ca7d7e..95dd1d51 100644 --- a/src/Psl/DateTime/Exception/InvalidArgumentException.php +++ b/src/Psl/DateTime/Exception/InvalidArgumentException.php @@ -23,7 +23,10 @@ final class InvalidArgumentException extends Exception\InvalidArgumentException */ public static function forYear(int $value): self { - return new self(Str\format('The year \'%d\' diverges from expectation; a positive integer is required.', $value)); + return new self(Str\format( + 'The year \'%d\' diverges from expectation; a positive integer is required.', + $value, + )); } /** @@ -62,7 +65,7 @@ public static function forDay(int $value, int $month, int $year): self $value, $month, $year, - Month::from($month)->getDaysForYear($year) + Month::from($month)->getDaysForYear($year), )); } @@ -111,7 +114,10 @@ public static function forMinutes(int $value): self */ public static function forSeconds(int $value): self { - return new self(Str\format('The seconds \'%d\' stretch outside the acceptable range of \'0\' to \'59\'.', $value)); + return new self(Str\format( + 'The seconds \'%d\' stretch outside the acceptable range of \'0\' to \'59\'.', + $value, + )); } /** @@ -127,6 +133,9 @@ public static function forSeconds(int $value): self */ public static function forNanoseconds(int $value): self { - return new self(Str\format('The nanoseconds \'%d\' exceed the foreseen limit of \'0\' to \'999999999\'.', $value)); + return new self(Str\format( + 'The nanoseconds \'%d\' exceed the foreseen limit of \'0\' to \'999999999\'.', + $value, + )); } } diff --git a/src/Psl/DateTime/Exception/UnexpectedValueException.php b/src/Psl/DateTime/Exception/UnexpectedValueException.php index 0f71486a..cbf061a5 100644 --- a/src/Psl/DateTime/Exception/UnexpectedValueException.php +++ b/src/Psl/DateTime/Exception/UnexpectedValueException.php @@ -26,7 +26,7 @@ public static function forYear(int $provided_year, int $calendar_year): self return new self(Str\format( 'Unexpected year value encountered. Provided "%d", but the calendar expects "%d". Check the year for accuracy and ensure it\'s within the supported range.', $provided_year, - $calendar_year + $calendar_year, )); } @@ -47,7 +47,7 @@ public static function forMonth(int $provided_month, int $calendar_month): self return new self(Str\format( 'Unexpected month value encountered. Provided "%d", but the calendar expects "%d". Ensure the month is within the 1-12 range and matches the specific year context.', $provided_month, - $calendar_month + $calendar_month, )); } @@ -68,7 +68,7 @@ public static function forDay(int $provided_day, int $calendar_day): self return new self(Str\format( 'Unexpected day value encountered. Provided "%d", but the calendar expects "%d". Ensure the day is valid for the given month and year, considering variations like leap years.', $provided_day, - $calendar_day + $calendar_day, )); } @@ -89,7 +89,7 @@ public static function forHours(int $provided_hours, int $calendar_hours): self return new self(Str\format( 'Unexpected hours value encountered. Provided "%d", but the calendar expects "%d". Ensure the hour falls within a 24-hour day.', $provided_hours, - $calendar_hours + $calendar_hours, )); } @@ -110,7 +110,7 @@ public static function forMinutes(int $provided_minutes, int $calendar_minutes): return new self(Str\format( 'Unexpected minutes value encountered. Provided "%d", but the calendar expects "%d". Check the minutes value for errors and ensure it\'s within the 0-59 range.', $provided_minutes, - $calendar_minutes + $calendar_minutes, )); } @@ -131,7 +131,7 @@ public static function forSeconds(int $provided_seconds, int $calendar_seconds): return new self(Str\format( 'Unexpected seconds value encountered. Provided "%d", but the calendar expects "%d". Ensure the seconds are correct and within the 0-59 range.', $calendar_seconds, - $provided_seconds + $provided_seconds, )); } } diff --git a/src/Psl/DateTime/Internal/create_intl_calendar_from_date_time.php b/src/Psl/DateTime/Internal/create_intl_calendar_from_date_time.php index f09a21e0..4706509c 100644 --- a/src/Psl/DateTime/Internal/create_intl_calendar_from_date_time.php +++ b/src/Psl/DateTime/Internal/create_intl_calendar_from_date_time.php @@ -23,14 +23,12 @@ function create_intl_calendar_from_date_time( int $day, int $hours, int $minutes, - int $seconds + int $seconds, ): IntlCalendar { /** * @var IntlCalendar $calendar */ - $calendar = IntlCalendar::createInstance( - to_intl_timezone($timezone), - ); + $calendar = IntlCalendar::createInstance(to_intl_timezone($timezone)); if (PHP_VERSION_ID >= 80300) { $calendar->setDateTime($year, $month - 1, $day, $hours, $minutes, $seconds); diff --git a/src/Psl/DateTime/Internal/create_intl_date_formatter.php b/src/Psl/DateTime/Internal/create_intl_date_formatter.php index ccc45a46..916205db 100644 --- a/src/Psl/DateTime/Internal/create_intl_date_formatter.php +++ b/src/Psl/DateTime/Internal/create_intl_date_formatter.php @@ -17,11 +17,11 @@ * @psalm-mutation-free */ function create_intl_date_formatter( - null|DateStyle $date_style = null, - null|TimeStyle $time_style = null, + null|DateStyle $date_style = null, + null|TimeStyle $time_style = null, null|FormatPattern|string $pattern = null, - null|Timezone $timezone = null, - null|Locale $locale = null, + null|Timezone $timezone = null, + null|Locale $locale = null, ): IntlDateFormatter { if ($pattern instanceof FormatPattern) { $pattern = $pattern->value; diff --git a/src/Psl/DateTime/Internal/format_rfc3339.php b/src/Psl/DateTime/Internal/format_rfc3339.php index 727242b8..e9016db7 100644 --- a/src/Psl/DateTime/Internal/format_rfc3339.php +++ b/src/Psl/DateTime/Internal/format_rfc3339.php @@ -18,7 +18,7 @@ */ function format_rfc3339( Timestamp $timestamp, - ?SecondsStyle $seconds_style = null, + null|SecondsStyle $seconds_style = null, bool $use_z = false, null|Timezone $timezone = null, ): string { diff --git a/src/Psl/DateTime/Internal/parse.php b/src/Psl/DateTime/Internal/parse.php index c728ae0d..4dce2288 100644 --- a/src/Psl/DateTime/Internal/parse.php +++ b/src/Psl/DateTime/Internal/parse.php @@ -20,12 +20,12 @@ * @throws ParserException */ function parse( - string $raw_string, - null|DateStyle $date_style = null, - null|TimeStyle $time_style = null, + string $raw_string, + null|DateStyle $date_style = null, + null|TimeStyle $time_style = null, null|FormatPattern|string $pattern = null, - null|Timezone $timezone = null, - null|Locale $locale = null, + null|Timezone $timezone = null, + null|Locale $locale = null, ): int { $formatter = namespace\create_intl_date_formatter($date_style, $time_style, $pattern, $timezone, $locale); @@ -34,7 +34,7 @@ function parse( if ($timestamp === false) { // Only show pattern in the exception if it was provided. if (null !== $pattern) { - $formatter_pattern = $pattern instanceof FormatPattern ? $pattern->value : $pattern; + $formatter_pattern = ($pattern instanceof FormatPattern) ? $pattern->value : $pattern; throw new ParserException(Str\format( 'Unable to interpret \'%s\' as a valid date/time using pattern \'%s\'.', @@ -43,9 +43,7 @@ function parse( )); } - throw new ParserException( - "Unable to interpret '$raw_string' as a valid date/time.", - ); + throw new ParserException("Unable to interpret '$raw_string' as a valid date/time."); } return (int) $timestamp; diff --git a/src/Psl/DateTime/Internal/system_time.php b/src/Psl/DateTime/Internal/system_time.php index e93ff8ad..38dba8d5 100644 --- a/src/Psl/DateTime/Internal/system_time.php +++ b/src/Psl/DateTime/Internal/system_time.php @@ -26,7 +26,7 @@ function system_time(): array $parts = Str\split($time, ' '); $seconds = (int) $parts[1]; - $nanoseconds = (int) (((float)$parts[0]) * ((float)NANOSECONDS_PER_SECOND)); + $nanoseconds = (int) (((float) $parts[0]) * ((float) NANOSECONDS_PER_SECOND)); return [$seconds, $nanoseconds]; } diff --git a/src/Psl/DateTime/SecondsStyle.php b/src/Psl/DateTime/SecondsStyle.php index d7c31398..b5a4a362 100644 --- a/src/Psl/DateTime/SecondsStyle.php +++ b/src/Psl/DateTime/SecondsStyle.php @@ -38,8 +38,8 @@ public static function fromTimestamp(Timestamp $timestamp): SecondsStyle return match (true) { $nanoseconds === 0 => static::Seconds, - $nanoseconds % 1000000 === 0 => static::Milliseconds, - $nanoseconds % 1000 === 0 => static::Microseconds, + ($nanoseconds % 1000000) === 0 => static::Milliseconds, + ($nanoseconds % 1000) === 0 => static::Microseconds, default => static::Nanoseconds, }; } diff --git a/src/Psl/DateTime/TemporalConvenienceMethodsTrait.php b/src/Psl/DateTime/TemporalConvenienceMethodsTrait.php index 6b6a94f2..2d082b0b 100644 --- a/src/Psl/DateTime/TemporalConvenienceMethodsTrait.php +++ b/src/Psl/DateTime/TemporalConvenienceMethodsTrait.php @@ -282,16 +282,20 @@ public function convertToTimezone(Timezone $timezone): DateTimeInterface * * @psalm-mutation-free */ - public function format(null|FormatPattern|string $pattern = null, null|Timezone $timezone = null, null|Locale $locale = null): string - { + public function format( + null|FormatPattern|string $pattern = null, + null|Timezone $timezone = null, + null|Locale $locale = null, + ): string { $timestamp = $this->getTimestamp(); /** * @psalm-suppress InvalidOperand * @psalm-suppress ImpureMethodCall */ - return Internal\create_intl_date_formatter(null, null, $pattern, $timezone, $locale) - ->format($timestamp->getSeconds() + ($timestamp->getNanoseconds() / NANOSECONDS_PER_SECOND)); + return Internal\create_intl_date_formatter(null, null, $pattern, $timezone, $locale)->format( + $timestamp->getSeconds() + ($timestamp->getNanoseconds() / NANOSECONDS_PER_SECOND), + ); } /** @@ -321,7 +325,7 @@ public function format(null|FormatPattern|string $pattern = null, null|Timezone * * @psalm-mutation-free */ - public function toRfc3339(?SecondsStyle $seconds_style = null, bool $use_z = false): string + public function toRfc3339(null|SecondsStyle $seconds_style = null, bool $use_z = false): string { return Internal\format_rfc3339($this->getTimestamp(), $seconds_style, $use_z); } @@ -353,16 +357,21 @@ public function toRfc3339(?SecondsStyle $seconds_style = null, bool $use_z = fal * * @psalm-mutation-free */ - public function toString(null|DateStyle $date_style = null, null|TimeStyle $time_style = null, null|Timezone $timezone = null, null|Locale $locale = null): string - { + public function toString( + null|DateStyle $date_style = null, + null|TimeStyle $time_style = null, + null|Timezone $timezone = null, + null|Locale $locale = null, + ): string { $timestamp = $this->getTimestamp(); /** * @psalm-suppress InvalidOperand * @psalm-suppress ImpureMethodCall */ - return Internal\create_intl_date_formatter($date_style, $time_style, null, $timezone, $locale) - ->format($timestamp->getSeconds() + ($timestamp->getNanoseconds() / NANOSECONDS_PER_SECOND)); + return Internal\create_intl_date_formatter($date_style, $time_style, null, $timezone, $locale)->format( + $timestamp->getSeconds() + ($timestamp->getNanoseconds() / NANOSECONDS_PER_SECOND), + ); } /** diff --git a/src/Psl/DateTime/TemporalInterface.php b/src/Psl/DateTime/TemporalInterface.php index 85d815e2..40378f7d 100644 --- a/src/Psl/DateTime/TemporalInterface.php +++ b/src/Psl/DateTime/TemporalInterface.php @@ -231,7 +231,11 @@ public function since(TemporalInterface $other): Duration; * * @psalm-mutation-free */ - public function format(null|FormatPattern|string $pattern = null, null|Timezone $timezone = null, null|Locale $locale = null): string; + public function format( + null|FormatPattern|string $pattern = null, + null|Timezone $timezone = null, + null|Locale $locale = null, + ): string; /** * Formats this {@see TemporalInterface} instance to a string based on the RFC 3339 format, with additional @@ -260,7 +264,7 @@ public function format(null|FormatPattern|string $pattern = null, null|Timezone * * @psalm-mutation-free */ - public function toRfc3339(?SecondsStyle $seconds_style = null, bool $use_z = false): string; + public function toRfc3339(null|SecondsStyle $seconds_style = null, bool $use_z = false): string; /** * Provides a string representation of this {@see TemporalInterface} instance, formatted according to specified styles for date and time, @@ -291,7 +295,12 @@ public function toRfc3339(?SecondsStyle $seconds_style = null, bool $use_z = fal * * @psalm-mutation-free */ - public function toString(null|DateStyle $date_style = null, null|TimeStyle $time_style = null, null|Timezone $timezone = null, null|Locale $locale = null): string; + public function toString( + null|DateStyle $date_style = null, + null|TimeStyle $time_style = null, + null|Timezone $timezone = null, + null|Locale $locale = null, + ): string; /** * Magic method that provides a default string representation of the date and time. diff --git a/src/Psl/DateTime/Timestamp.php b/src/Psl/DateTime/Timestamp.php index 4cb9a129..acb6e44d 100644 --- a/src/Psl/DateTime/Timestamp.php +++ b/src/Psl/DateTime/Timestamp.php @@ -49,11 +49,11 @@ public static function fromParts(int $seconds, int $nanoseconds = 0): Timestamp { // Check for potential overflow or underflow before doing any operation if ($seconds === Math\INT64_MAX && $nanoseconds >= NANOSECONDS_PER_SECOND) { - throw new Exception\OverflowException("Adding nanoseconds would cause an overflow."); + throw new Exception\OverflowException('Adding nanoseconds would cause an overflow.'); } if ($seconds === Math\INT64_MIN && $nanoseconds <= -NANOSECONDS_PER_SECOND) { - throw new Exception\UnderflowException("Subtracting nanoseconds would cause an underflow."); + throw new Exception\UnderflowException('Subtracting nanoseconds would cause an underflow.'); } /** @psalm-suppress MissingThrowsDocblock */ @@ -131,12 +131,19 @@ public static function monotonic(): self * * @psalm-mutation-free */ - public static function parse(string $raw_string, null|FormatPattern|string $pattern = null, null|Timezone $timezone = null, null|Locale $locale = null): static - { + public static function parse( + string $raw_string, + null|FormatPattern|string $pattern = null, + null|Timezone $timezone = null, + null|Locale $locale = null, + ): static { /** @psalm-suppress MissingThrowsDocblock */ - return self::fromParts( - Internal\parse(raw_string: $raw_string, pattern: $pattern, timezone: $timezone, locale: $locale) - ); + return self::fromParts(Internal\parse( + raw_string: $raw_string, + pattern: $pattern, + timezone: $timezone, + locale: $locale, + )); } /** @@ -171,12 +178,21 @@ public static function parse(string $raw_string, null|FormatPattern|string $patt * * @psalm-mutation-free */ - public static function fromString(string $raw_string, null|DateStyle $date_style = null, null|TimeStyle $time_style = null, null|Timezone $timezone = null, null|Locale $locale = null): static - { + public static function fromString( + string $raw_string, + null|DateStyle $date_style = null, + null|TimeStyle $time_style = null, + null|Timezone $timezone = null, + null|Locale $locale = null, + ): static { /** @psalm-suppress MissingThrowsDocblock */ - return self::fromParts( - Internal\parse(raw_string: $raw_string, date_style: $date_style, time_style: $time_style, timezone: $timezone, locale: $locale) - ); + return self::fromParts(Internal\parse( + raw_string: $raw_string, + date_style: $date_style, + time_style: $time_style, + timezone: $timezone, + locale: $locale, + )); } /** @@ -236,7 +252,7 @@ public function getNanoseconds(): int public function plus(Duration $duration): static { [$h, $m, $s, $ns] = $duration->getParts(); - $totalSeconds = SECONDS_PER_MINUTE * $m + SECONDS_PER_HOUR * $h + $s; + $totalSeconds = (SECONDS_PER_MINUTE * $m) + (SECONDS_PER_HOUR * $h) + $s; $newSeconds = $this->seconds + $totalSeconds; $newNanoseconds = $this->nanoseconds + $ns; @@ -255,7 +271,7 @@ public function plus(Duration $duration): static public function minus(Duration $duration): static { [$h, $m, $s, $ns] = $duration->getParts(); - $totalSeconds = SECONDS_PER_MINUTE * $m + SECONDS_PER_HOUR * $h + $s; + $totalSeconds = (SECONDS_PER_MINUTE * $m) + (SECONDS_PER_HOUR * $h) + $s; $newSeconds = $this->seconds - $totalSeconds; $newNanoseconds = $this->nanoseconds - $ns; diff --git a/src/Psl/DateTime/Timezone.php b/src/Psl/DateTime/Timezone.php index 949b1c05..68987f78 100644 --- a/src/Psl/DateTime/Timezone.php +++ b/src/Psl/DateTime/Timezone.php @@ -18,7 +18,7 @@ * and the historical changes in time zone definitions. Time zone identifiers like "America/Los_Angeles" automatically * account for these variations correctly across different dates. */ -enum Timezone : string +enum Timezone: string { case UTC = 'UTC'; case Minus1100 = '-11:00'; diff --git a/src/Psl/DateTime/is_leap_year.php b/src/Psl/DateTime/is_leap_year.php index 644a9206..0d41d030 100644 --- a/src/Psl/DateTime/is_leap_year.php +++ b/src/Psl/DateTime/is_leap_year.php @@ -16,5 +16,5 @@ */ function is_leap_year(int $year): bool { - return $year % 4 === 0 && ($year % 100 !== 0 || $year % 400 === 0); + return ($year % 4) === 0 && (($year % 100) !== 0 || ($year % 400) === 0); } diff --git a/src/Psl/Dict/diff.php b/src/Psl/Dict/diff.php index b5635b44..e4a98e85 100644 --- a/src/Psl/Dict/diff.php +++ b/src/Psl/Dict/diff.php @@ -27,13 +27,17 @@ function diff(iterable $first, iterable $second, iterable ...$rest): array return []; } - return array_diff(from_iterable($first), from_iterable($second), ...Vec\map( - $rest, - /** - * @param iterable $iterable - * - * @return array - */ - static fn(iterable $iterable): array => from_iterable($iterable) - )); + return array_diff( + from_iterable($first), + from_iterable($second), + ...Vec\map( + $rest, + /** + * @param iterable $iterable + * + * @return array + */ + static fn(iterable $iterable): array => from_iterable($iterable), + ), + ); } diff --git a/src/Psl/Dict/diff_by_key.php b/src/Psl/Dict/diff_by_key.php index 5b9d2a18..43481a24 100644 --- a/src/Psl/Dict/diff_by_key.php +++ b/src/Psl/Dict/diff_by_key.php @@ -27,13 +27,17 @@ function diff_by_key(iterable $first, iterable $second, iterable ...$rest): arra return []; } - return array_diff_key(from_iterable($first), from_iterable($second), ...Vec\map( - $rest, - /** - * @param iterable $iterable - * - * @return array - */ - static fn(iterable $iterable): array => from_iterable($iterable) - )); + return array_diff_key( + from_iterable($first), + from_iterable($second), + ...Vec\map( + $rest, + /** + * @param iterable $iterable + * + * @return array + */ + static fn(iterable $iterable): array => from_iterable($iterable), + ), + ); } diff --git a/src/Psl/Dict/filter.php b/src/Psl/Dict/filter.php index f5113d84..71d6b08e 100644 --- a/src/Psl/Dict/filter.php +++ b/src/Psl/Dict/filter.php @@ -31,7 +31,7 @@ * * @return array */ -function filter(iterable $iterable, ?Closure $predicate = null): array +function filter(iterable $iterable, null|Closure $predicate = null): array { /** @var (Closure(Tv): bool) $predicate */ $predicate = $predicate ?? static fn(mixed $value): bool => (bool) $value; @@ -42,11 +42,11 @@ function filter(iterable $iterable, ?Closure $predicate = null): array /** * @param Tv $v */ - static fn(mixed $v): bool => $predicate($v) + static fn(mixed $v): bool => $predicate($v), ); } - $result = []; + $result = []; foreach ($iterable as $k => $v) { if ($predicate($v)) { $result[$k] = $v; diff --git a/src/Psl/Dict/filter_keys.php b/src/Psl/Dict/filter_keys.php index e9fdfd96..22f07919 100644 --- a/src/Psl/Dict/filter_keys.php +++ b/src/Psl/Dict/filter_keys.php @@ -33,7 +33,7 @@ * * @return array */ -function filter_keys(iterable $iterable, ?Closure $predicate = null): array +function filter_keys(iterable $iterable, null|Closure $predicate = null): array { /** @var (Closure(Tk): bool) $predicate */ $predicate = $predicate ?? static fn(mixed $value): bool => (bool) $value; @@ -45,11 +45,11 @@ function filter_keys(iterable $iterable, ?Closure $predicate = null): array * @param Tk $k */ static fn($k): bool => $predicate($k), - ARRAY_FILTER_USE_KEY + ARRAY_FILTER_USE_KEY, ); } - $result = []; + $result = []; foreach ($iterable as $k => $v) { if ($predicate($k)) { $result[$k] = $v; diff --git a/src/Psl/Dict/filter_nulls.php b/src/Psl/Dict/filter_nulls.php index f94b5a36..a5de736d 100644 --- a/src/Psl/Dict/filter_nulls.php +++ b/src/Psl/Dict/filter_nulls.php @@ -26,6 +26,6 @@ function filter_nulls(iterable $iterable): array /** * @param Tv|null $value */ - static fn($value): bool => $value !== null + static fn($value): bool => $value !== null, ); } diff --git a/src/Psl/Dict/filter_with_key.php b/src/Psl/Dict/filter_with_key.php index 603b789c..728dd490 100644 --- a/src/Psl/Dict/filter_with_key.php +++ b/src/Psl/Dict/filter_with_key.php @@ -36,14 +36,15 @@ * * @return array */ -function filter_with_key(iterable $iterable, ?Closure $predicate = null): array +function filter_with_key(iterable $iterable, null|Closure $predicate = null): array { - $predicate = $predicate ?? + $predicate = + $predicate ?? /** * @param Tk $_k * @param Tv $v */ - static fn (mixed $_k, mixed $v): bool => (bool)$v; + static fn(mixed $_k, mixed $v): bool => (bool) $v; if (is_array($iterable)) { return array_filter( @@ -52,8 +53,8 @@ function filter_with_key(iterable $iterable, ?Closure $predicate = null): array * @param Tv $v * @param Tk $k */ - static fn (mixed $v, string|int $k): bool => $predicate($k, $v), - ARRAY_FILTER_USE_BOTH + static fn(mixed $v, string|int $k): bool => $predicate($k, $v), + ARRAY_FILTER_USE_BOTH, ); } diff --git a/src/Psl/Dict/flip.php b/src/Psl/Dict/flip.php index b910f21d..b0bffa55 100644 --- a/src/Psl/Dict/flip.php +++ b/src/Psl/Dict/flip.php @@ -31,7 +31,7 @@ function flip(iterable $iterable): array Psl\invariant( Type\array_key()->matches($value), 'Expected all values to be of type array-key, value of type (%s) provided.', - gettype($value) + gettype($value), ); /** @var Tv $value */ diff --git a/src/Psl/Dict/group_by.php b/src/Psl/Dict/group_by.php index 373c94a5..296865c1 100644 --- a/src/Psl/Dict/group_by.php +++ b/src/Psl/Dict/group_by.php @@ -51,11 +51,11 @@ function group_by(iterable $values, Closure $key_func): array Psl\invariant( Type\array_key()->matches($key), 'Expected $key_func to return a value of type array-key, value of type (%s) returned.', - gettype($key) + gettype($key), ); /** @var Tk $key */ - $result[$key] = $result[$key] ?? []; + $result[$key] = $result[$key] ?? []; $result[$key][] = $value; } diff --git a/src/Psl/Dict/intersect.php b/src/Psl/Dict/intersect.php index f569a24e..c9fb629e 100644 --- a/src/Psl/Dict/intersect.php +++ b/src/Psl/Dict/intersect.php @@ -27,13 +27,17 @@ function intersect(iterable $first, iterable $second, iterable ...$rest): array return []; } - return array_intersect(from_iterable($first), from_iterable($second), ...Vec\map( - $rest, - /** - * @param iterable $iterable - * - * @return array - */ - static fn(iterable $iterable): array => from_iterable($iterable) - )); + return array_intersect( + from_iterable($first), + from_iterable($second), + ...Vec\map( + $rest, + /** + * @param iterable $iterable + * + * @return array + */ + static fn(iterable $iterable): array => from_iterable($iterable), + ), + ); } diff --git a/src/Psl/Dict/intersect_by_key.php b/src/Psl/Dict/intersect_by_key.php index 212ab509..d98362cf 100644 --- a/src/Psl/Dict/intersect_by_key.php +++ b/src/Psl/Dict/intersect_by_key.php @@ -27,13 +27,17 @@ function intersect_by_key(iterable $first, iterable $second, iterable ...$rest): return []; } - return array_intersect_key(from_iterable($first), from_iterable($second), ...Vec\map( - $rest, - /** - * @param iterable $iterable - * - * @return array - */ - static fn(iterable $iterable): array => from_iterable($iterable) - )); + return array_intersect_key( + from_iterable($first), + from_iterable($second), + ...Vec\map( + $rest, + /** + * @param iterable $iterable + * + * @return array + */ + static fn(iterable $iterable): array => from_iterable($iterable), + ), + ); } diff --git a/src/Psl/Dict/slice.php b/src/Psl/Dict/slice.php index c4a43c21..9d5d51bb 100644 --- a/src/Psl/Dict/slice.php +++ b/src/Psl/Dict/slice.php @@ -24,7 +24,7 @@ * * @return array */ -function slice(iterable $iterable, int $start, ?int $length = null): array +function slice(iterable $iterable, int $start, null|int $length = null): array { $result = []; if (0 === $length) { @@ -38,7 +38,7 @@ function slice(iterable $iterable, int $start, ?int $length = null): array } $result[$key] = $value; - if (null !== $length && $i >= $start + $length) { + if (null !== $length && $i >= ($start + $length)) { break; } } diff --git a/src/Psl/Dict/sort.php b/src/Psl/Dict/sort.php index 35bde3ae..99c157f8 100644 --- a/src/Psl/Dict/sort.php +++ b/src/Psl/Dict/sort.php @@ -23,7 +23,7 @@ * * @return array */ -function sort(iterable $iterable, ?Closure $comparator = null): array +function sort(iterable $iterable, null|Closure $comparator = null): array { $array = []; foreach ($iterable as $k => $v) { @@ -37,7 +37,7 @@ function sort(iterable $iterable, ?Closure $comparator = null): array * @param Tv $a * @param Tv $b */ - static fn(mixed $a, mixed $b): int => $comparator($a, $b) + static fn(mixed $a, mixed $b): int => $comparator($a, $b), ); } else { asort($array); diff --git a/src/Psl/Dict/sort_by.php b/src/Psl/Dict/sort_by.php index 9960dadf..3dc0f7df 100644 --- a/src/Psl/Dict/sort_by.php +++ b/src/Psl/Dict/sort_by.php @@ -23,21 +23,21 @@ * * @return array */ -function sort_by(iterable $iterable, Closure $scalar_func, ?Closure $comparator = null): array +function sort_by(iterable $iterable, Closure $scalar_func, null|Closure $comparator = null): array { $comparator ??= /** * @param Ts $a * @param Ts $b */ - static fn ($a, $b): int => $a <=> $b; + static fn($a, $b): int => $a <=> $b; $tuple_comparator = /** * @param array{0: Ts, 1: Tv} $a * @param array{0: Ts, 1: Tv} $b */ - static fn ($a, $b): int => $comparator($a[0], $b[0]); + static fn($a, $b): int => $comparator($a[0], $b[0]); /** * @var array $tuples diff --git a/src/Psl/Dict/sort_by_key.php b/src/Psl/Dict/sort_by_key.php index dce3eed5..618768f2 100644 --- a/src/Psl/Dict/sort_by_key.php +++ b/src/Psl/Dict/sort_by_key.php @@ -23,7 +23,7 @@ * * @return array */ -function sort_by_key(iterable $iterable, ?Closure $comparator = null): array +function sort_by_key(iterable $iterable, null|Closure $comparator = null): array { $result = []; foreach ($iterable as $k => $v) { diff --git a/src/Psl/Dict/take_while.php b/src/Psl/Dict/take_while.php index ba05e877..a319afd6 100644 --- a/src/Psl/Dict/take_while.php +++ b/src/Psl/Dict/take_while.php @@ -36,6 +36,5 @@ function take_while(iterable $iterable, Closure $predicate): array $result[$key] = $value; } - return $result; } diff --git a/src/Psl/Dict/unique.php b/src/Psl/Dict/unique.php index 89e08d32..4fa71403 100644 --- a/src/Psl/Dict/unique.php +++ b/src/Psl/Dict/unique.php @@ -25,6 +25,6 @@ function unique(iterable $iterable): array * * @pure */ - static fn($v) => $v + static fn($v) => $v, ); } diff --git a/src/Psl/Dict/unique_scalar.php b/src/Psl/Dict/unique_scalar.php index 12d286e0..b1700847 100644 --- a/src/Psl/Dict/unique_scalar.php +++ b/src/Psl/Dict/unique_scalar.php @@ -33,6 +33,6 @@ function unique_scalar(iterable $iterable): array * * @pure */ - static fn($v) => $v + static fn($v) => $v, ); } diff --git a/src/Psl/Encoding/Base64/Internal/Base64.php b/src/Psl/Encoding/Base64/Internal/Base64.php index 04483a14..87300723 100644 --- a/src/Psl/Encoding/Base64/Internal/Base64.php +++ b/src/Psl/Encoding/Base64/Internal/Base64.php @@ -38,13 +38,14 @@ public static function encode(string $binary, bool $padding = true): string $dest = ''; $binary_length = Str\length($binary, encoding: Str\Encoding::Ascii8bit); - for ($i = 0; $i + 3 <= $binary_length; $i += 3) { + for ($i = 0; ($i + 3) <= $binary_length; $i += 3) { /** @var array $chunk */ $chunk = unpack('C*', Str\slice($binary, $i, 3, encoding: Str\Encoding::Ascii8bit)); $byte0 = $chunk[1]; $byte1 = $chunk[2]; $byte2 = $chunk[3]; - $dest .= static::encode6Bits($byte0 >> 2) . + $dest .= + static::encode6Bits($byte0 >> 2) . static::encode6Bits((($byte0 << 4) | ($byte1 >> 4)) & 63) . static::encode6Bits((($byte1 << 2) | ($byte2 >> 6)) & 63) . static::encode6Bits($byte2 & 63); @@ -57,17 +58,17 @@ public static function encode(string $binary, bool $padding = true): string */ $chunk = unpack('C*', Str\slice($binary, $i, $binary_length - $i, encoding: Str\Encoding::Ascii8bit)); $byte0 = $chunk[1]; - if ($i + 1 < $binary_length) { + if (($i + 1) < $binary_length) { $byte1 = $chunk[2]; - $dest .= static::encode6Bits($byte0 >> 2) . + $dest .= + static::encode6Bits($byte0 >> 2) . static::encode6Bits((($byte0 << 4) | ($byte1 >> 4)) & 63) . static::encode6Bits(($byte1 << 2) & 63); if ($padding) { $dest .= '='; } } else { - $dest .= static::encode6Bits($byte0 >> 2) . - static::encode6Bits(($byte0 << 4) & 63); + $dest .= static::encode6Bits($byte0 >> 2) . static::encode6Bits(($byte0 << 4) & 63); if ($padding) { $dest .= '=='; } @@ -99,7 +100,7 @@ public static function decode(string $base64, bool $explicit_padding = true): st static::checkRange($base64); - if ($explicit_padding && $base64_length % 4 !== 0) { + if ($explicit_padding && ($base64_length % 4) !== 0) { throw new Exception\IncorrectPaddingException('The given base64 string has incorrect padding.'); } @@ -109,7 +110,7 @@ public static function decode(string $base64, bool $explicit_padding = true): st $err = 0; $dest = ''; - for ($i = 0; $i + 4 <= $base64_length; $i += 4) { + for ($i = 0; ($i + 4) <= $base64_length; $i += 4) { /** @var array $chunk */ $chunk = unpack('C*', Str\slice($base64, $i, 4, encoding: Str\Encoding::Ascii8bit)); $char0 = static::decode6Bits($chunk[1]); @@ -118,9 +119,9 @@ public static function decode(string $base64, bool $explicit_padding = true): st $char3 = static::decode6Bits($chunk[4]); $dest .= pack( 'CCC', - ((($char0 << 2) | ($char1 >> 4)) & 0xff), - ((($char1 << 4) | ($char2 >> 2)) & 0xff), - ((($char2 << 6) | $char3) & 0xff), + (($char0 << 2) | ($char1 >> 4)) & 0xff, + (($char1 << 4) | ($char2 >> 2)) & 0xff, + (($char2 << 6) | $char3) & 0xff, ); $err |= ($char0 | $char1 | $char2 | $char3) >> 8; } @@ -132,28 +133,22 @@ public static function decode(string $base64, bool $explicit_padding = true): st */ $chunk = unpack('C*', Str\slice($base64, $i, $base64_length - $i, encoding: Str\Encoding::Ascii8bit)); $char0 = static::decode6Bits($chunk[1]); - if ($i + 2 < $base64_length) { + if (($i + 2) < $base64_length) { $char1 = static::decode6Bits($chunk[2]); $char2 = static::decode6Bits($chunk[3]); - $dest .= pack( - 'CC', - ((($char0 << 2) | ($char1 >> 4)) & 0xff), - ((($char1 << 4) | ($char2 >> 2)) & 0xff), - ); + $dest .= pack('CC', (($char0 << 2) | ($char1 >> 4)) & 0xff, (($char1 << 4) | ($char2 >> 2)) & 0xff); $err |= ($char0 | $char1 | $char2) >> 8; - } elseif ($i + 1 < $base64_length) { + } elseif (($i + 1) < $base64_length) { $char1 = static::decode6Bits($chunk[2]); - $dest .= pack('C', ((($char0 << 2) | ($char1 >> 4)) & 0xff)); + $dest .= pack('C', (($char0 << 2) | ($char1 >> 4)) & 0xff); $err |= ($char0 | $char1) >> 8; } elseif ($explicit_padding) { $err |= 1; } } - $check = ($err === 0); + $check = $err === 0; if (!$check) { - throw new Exception\RangeException( - 'Expected characters in the correct base64 alphabet', - ); + throw new Exception\RangeException('Expected characters in the correct base64 alphabet'); } return $dest; @@ -169,9 +164,7 @@ protected static function checkRange(string $base64): void { /** @psalm-suppress MissingThrowsDocblock - pattern is valid */ if (!Regex\matches($base64, '%^[a-zA-Z0-9/+]*={0,2}$%')) { - throw new Exception\RangeException( - 'The given base64 string contains characters outside the base64 range.' - ); + throw new Exception\RangeException('The given base64 string contains characters outside the base64 range.'); } } diff --git a/src/Psl/Encoding/Base64/Internal/Base64DotSlash.php b/src/Psl/Encoding/Base64/Internal/Base64DotSlash.php index 93ed690f..73ecdbb7 100644 --- a/src/Psl/Encoding/Base64/Internal/Base64DotSlash.php +++ b/src/Psl/Encoding/Base64/Internal/Base64DotSlash.php @@ -30,7 +30,7 @@ protected static function checkRange(string $base64): void /** @psalm-suppress MissingThrowsDocblock - pattern is valid */ if (!Regex\matches($base64, '%^[a-zA-Z0-9./]*={0,2}$%')) { throw new Exception\RangeException( - 'The given string contains characters outside the base64 range for the current variant.' + 'The given string contains characters outside the base64 range for the current variant.', ); } } diff --git a/src/Psl/Encoding/Base64/Internal/Base64DotSlashOrdered.php b/src/Psl/Encoding/Base64/Internal/Base64DotSlashOrdered.php index cdbf9876..a94603dd 100644 --- a/src/Psl/Encoding/Base64/Internal/Base64DotSlashOrdered.php +++ b/src/Psl/Encoding/Base64/Internal/Base64DotSlashOrdered.php @@ -30,7 +30,7 @@ protected static function checkRange(string $base64): void /** @psalm-suppress MissingThrowsDocblock - pattern is valid */ if (!Regex\matches($base64, '%^[a-zA-Z.-9]*={0,2}$%')) { throw new Exception\RangeException( - 'The given string contains characters outside the base64 range for the current variant.' + 'The given string contains characters outside the base64 range for the current variant.', ); } } diff --git a/src/Psl/Encoding/Base64/Internal/Base64UrlSafe.php b/src/Psl/Encoding/Base64/Internal/Base64UrlSafe.php index 819a8cf4..d721101b 100644 --- a/src/Psl/Encoding/Base64/Internal/Base64UrlSafe.php +++ b/src/Psl/Encoding/Base64/Internal/Base64UrlSafe.php @@ -30,7 +30,7 @@ protected static function checkRange(string $base64): void /** @psalm-suppress MissingThrowsDocblock - pattern is valid */ if (!Regex\matches($base64, '%^[a-zA-Z0-9-_]*={0,2}$%')) { throw new Exception\RangeException( - 'The given string contains characters outside the base64 range for the current variant.' + 'The given string contains characters outside the base64 range for the current variant.', ); } } diff --git a/src/Psl/Encoding/Hex/decode.php b/src/Psl/Encoding/Hex/decode.php index f187b919..a922a833 100644 --- a/src/Psl/Encoding/Hex/decode.php +++ b/src/Psl/Encoding/Hex/decode.php @@ -23,15 +23,13 @@ function decode(string $hexadecimal): string { if (!ctype_xdigit($hexadecimal)) { throw new Exception\RangeException( - 'The given hexadecimal string contains characters outside the base16 range.' + 'The given hexadecimal string contains characters outside the base16 range.', ); } $hex_len = Str\length($hexadecimal, Str\Encoding::Ascii8bit); if (($hex_len & 1) !== 0) { - throw new Exception\RangeException( - 'Expected an even number of hexadecimal characters.', - ); + throw new Exception\RangeException('Expected an even number of hexadecimal characters.'); } return hex2bin($hexadecimal); diff --git a/src/Psl/Env/get_var.php b/src/Psl/Env/get_var.php index 145b0cd8..333ba0e6 100644 --- a/src/Psl/Env/get_var.php +++ b/src/Psl/Env/get_var.php @@ -16,7 +16,7 @@ * * @throws Psl\Exception\InvariantViolationException If $key contains an ASCII equals sign `=`, or the NUL character `\0`. */ -function get_var(string $key): ?string +function get_var(string $key): null|string { if (str_contains($key, '=') || str_contains($key, "\0")) { Psl\invariant_violation('Invalid environment variable key provided.'); diff --git a/src/Psl/File/Internal/AbstractHandleWrapper.php b/src/Psl/File/Internal/AbstractHandleWrapper.php index 03eebbc4..fac0ca27 100644 --- a/src/Psl/File/Internal/AbstractHandleWrapper.php +++ b/src/Psl/File/Internal/AbstractHandleWrapper.php @@ -10,8 +10,9 @@ abstract class AbstractHandleWrapper implements File\HandleInterface { - public function __construct(private File\HandleInterface $handle) - { + public function __construct( + private File\HandleInterface $handle, + ) { } /** diff --git a/src/Psl/File/Lock.php b/src/Psl/File/Lock.php index b74c0668..af0c0b58 100644 --- a/src/Psl/File/Lock.php +++ b/src/Psl/File/Lock.php @@ -10,7 +10,6 @@ final class Lock { private bool $released = false; - /** * @param (Closure(): void) $releaseCallback * diff --git a/src/Psl/File/ReadHandle.php b/src/Psl/File/ReadHandle.php index 57919f36..b2599d77 100644 --- a/src/Psl/File/ReadHandle.php +++ b/src/Psl/File/ReadHandle.php @@ -51,7 +51,7 @@ public function reachedEndOfDataSource(): bool /** * {@inheritDoc} */ - public function tryRead(?int $max_bytes = null): string + public function tryRead(null|int $max_bytes = null): string { return $this->readHandle->tryRead($max_bytes); } @@ -59,7 +59,7 @@ public function tryRead(?int $max_bytes = null): string /** * {@inheritDoc} */ - public function read(?int $max_bytes = null, ?Duration $timeout = null): string + public function read(null|int $max_bytes = null, null|Duration $timeout = null): string { return $this->readHandle->read($max_bytes, $timeout); } diff --git a/src/Psl/File/ReadWriteHandle.php b/src/Psl/File/ReadWriteHandle.php index 1f6cbe1c..d3ef7aea 100644 --- a/src/Psl/File/ReadWriteHandle.php +++ b/src/Psl/File/ReadWriteHandle.php @@ -59,11 +59,14 @@ public function __construct(string $file, WriteMode $write_mode = WriteMode::Ope throw Exception\NotReadableException::for($file); } } catch (Filesystem\Exception\RuntimeException $previous) { - throw new Exception\RuntimeException(Str\format('Failed to create the directory for file "%s".', $file), previous: $previous); + throw new Exception\RuntimeException( + Str\format('Failed to create the directory for file "%s".', $file), + previous: $previous, + ); } } - $this->readWriteHandle = Internal\open($file, ($write_mode->value) . 'r+', read: true, write: true); + $this->readWriteHandle = Internal\open($file, $write_mode->value . 'r+', read: true, write: true); parent::__construct($this->readWriteHandle); } @@ -79,7 +82,7 @@ public function reachedEndOfDataSource(): bool /** * {@inheritDoc} */ - public function tryRead(?int $max_bytes = null): string + public function tryRead(null|int $max_bytes = null): string { return $this->readWriteHandle->tryRead($max_bytes); } @@ -87,7 +90,7 @@ public function tryRead(?int $max_bytes = null): string /** * {@inheritDoc} */ - public function read(?int $max_bytes = null, ?Duration $timeout = null): string + public function read(null|int $max_bytes = null, null|Duration $timeout = null): string { return $this->readWriteHandle->read($max_bytes, $timeout); } @@ -103,7 +106,7 @@ public function tryWrite(string $bytes): int /** * {@inheritDoc} */ - public function write(string $bytes, ?Duration $timeout = null): int + public function write(string $bytes, null|Duration $timeout = null): int { return $this->readWriteHandle->write($bytes, $timeout); } diff --git a/src/Psl/File/WriteHandle.php b/src/Psl/File/WriteHandle.php index c0651575..99d83eac 100644 --- a/src/Psl/File/WriteHandle.php +++ b/src/Psl/File/WriteHandle.php @@ -47,7 +47,10 @@ public function __construct(string $file, WriteMode $write_mode = WriteMode::Ope throw Exception\NotWritableException::for($file); } } catch (Filesystem\Exception\RuntimeException $previous) { - throw new Exception\RuntimeException(Str\format('Failed to create the directory for file "%s".', $file), previous: $previous); + throw new Exception\RuntimeException( + Str\format('Failed to create the directory for file "%s".', $file), + previous: $previous, + ); } } @@ -67,7 +70,7 @@ public function tryWrite(string $bytes): int /** * {@inheritDoc} */ - public function write(string $bytes, ?Duration $timeout = null): int + public function write(string $bytes, null|Duration $timeout = null): int { return $this->writeHandle->write($bytes, $timeout); } diff --git a/src/Psl/File/read.php b/src/Psl/File/read.php index 2ac6e9c3..496bcec7 100644 --- a/src/Psl/File/read.php +++ b/src/Psl/File/read.php @@ -20,7 +20,7 @@ * @throws Exception\NotReadableException If $file exists, and is non-readable. * @throws Exception\RuntimeException In case of an error. */ -function read(string $file, int $offset = 0, ?int $length = null): string +function read(string $file, int $offset = 0, null|int $length = null): string { try { $handle = namespace\open_read_only($file); @@ -35,10 +35,7 @@ function read(string $file, int $offset = 0, ?int $length = null): string return $content; } catch (IO\Exception\ExceptionInterface $previous) { // @codeCoverageIgnoreStart - throw new Exception\RuntimeException(Str\format( - 'Failed to read file "%s".', - $file, - ), 0, $previous); + throw new Exception\RuntimeException(Str\format('Failed to read file "%s".', $file), 0, $previous); // @codeCoverageIgnoreEnd } } diff --git a/src/Psl/File/write.php b/src/Psl/File/write.php index fab7728c..eb8906d2 100644 --- a/src/Psl/File/write.php +++ b/src/Psl/File/write.php @@ -37,10 +37,7 @@ function write(string $file, string $content, WriteMode $mode = WriteMode::OpenO clearstatcache(); } catch (IO\Exception\ExceptionInterface $previous) { // @codeCoverageIgnoreStart - throw new Exception\RuntimeException(Str\format( - 'Failed to write to file "%s".', - $file, - ), 0, $previous); + throw new Exception\RuntimeException(Str\format('Failed to write to file "%s".', $file), 0, $previous); // @codeCoverageIgnoreEnd } } diff --git a/src/Psl/Filesystem/canonicalize.php b/src/Psl/Filesystem/canonicalize.php index 3ee95358..d6e772d8 100644 --- a/src/Psl/Filesystem/canonicalize.php +++ b/src/Psl/Filesystem/canonicalize.php @@ -12,7 +12,7 @@ * * @return non-empty-string|null */ -function canonicalize(string $path): ?string +function canonicalize(string $path): null|string { $path = realpath($path); diff --git a/src/Psl/Filesystem/copy.php b/src/Psl/Filesystem/copy.php index f49b9ca6..dae5d6ee 100644 --- a/src/Psl/Filesystem/copy.php +++ b/src/Psl/Filesystem/copy.php @@ -53,8 +53,11 @@ function copy(string $source, string $destination, bool $overwrite = false): voi unset($chunk); } // @codeCoverageIgnoreStart - } catch (IO\Exception\ExceptionInterface | File\Exception\ExceptionInterface | Psl\Exception\InvariantViolationException $exception) { - throw new Exception\RuntimeException(Str\format('Failed to copy source file "%s" to destination "%s".', $source, $destination), previous: $exception); + } catch (IO\Exception\ExceptionInterface|File\Exception\ExceptionInterface|Psl\Exception\InvariantViolationException $exception) { + throw new Exception\RuntimeException( + Str\format('Failed to copy source file "%s" to destination "%s".', $source, $destination), + previous: $exception, + ); } finally { // @codeCoverageIgnoreEnd $source_lock?->release(); @@ -62,8 +65,5 @@ function copy(string $source, string $destination, bool $overwrite = false): voi } // preserve executable permission bits - change_permissions( - $destination, - get_permissions($destination) | (get_permissions($source) & 0111) - ); + change_permissions($destination, get_permissions($destination) | (get_permissions($source) & 0o111)); } diff --git a/src/Psl/Filesystem/create_directory.php b/src/Psl/Filesystem/create_directory.php index a1fb02e4..fff8a514 100644 --- a/src/Psl/Filesystem/create_directory.php +++ b/src/Psl/Filesystem/create_directory.php @@ -16,22 +16,20 @@ * * @throws Exception\RuntimeException If unable to create the directory. */ -function create_directory(string $directory, int $permissions = 0777): void +function create_directory(string $directory, int $permissions = 0o777): void { if (namespace\is_directory($directory)) { return; } - [$result, $error_message] = Internal\box( - static fn() => mkdir($directory, $permissions, true) - ); + [$result, $error_message] = Internal\box(static fn() => mkdir($directory, $permissions, true)); // @codeCoverageIgnoreStart if (false === $result && !namespace\is_directory($directory)) { throw new Exception\RuntimeException(Str\format( 'Failed to create directory "%s": %s.', $directory, - $error_message ?? 'internal error' + $error_message ?? 'internal error', )); } // @codeCoverageIgnoreEnd diff --git a/src/Psl/Filesystem/create_directory_for_file.php b/src/Psl/Filesystem/create_directory_for_file.php index a2e9a6ce..991cd160 100644 --- a/src/Psl/Filesystem/create_directory_for_file.php +++ b/src/Psl/Filesystem/create_directory_for_file.php @@ -13,7 +13,7 @@ * * @return non-empty-string */ -function create_directory_for_file(string $filename, int $permissions = 0777): string +function create_directory_for_file(string $filename, int $permissions = 0o777): string { $directory = namespace\get_directory($filename); namespace\create_directory($directory, $permissions); diff --git a/src/Psl/Filesystem/create_file.php b/src/Psl/Filesystem/create_file.php index af657b72..15e5477a 100644 --- a/src/Psl/Filesystem/create_file.php +++ b/src/Psl/Filesystem/create_file.php @@ -21,7 +21,7 @@ * * @throws Exception\RuntimeException If unable to create the file. */ -function create_file(string $filename, ?int $time = null, ?int $access_time = null): void +function create_file(string $filename, null|int $time = null, null|int $access_time = null): void { if (null === $access_time && null === $time) { $fun = static fn(): bool => touch($filename); @@ -41,7 +41,7 @@ function create_file(string $filename, ?int $time = null, ?int $access_time = nu throw new Exception\RuntimeException(Str\format( 'Failed to create file "%s": %s.', $filename, - $error_message ?? 'internal error' + $error_message ?? 'internal error', )); } // @codeCoverageIgnoreEnd diff --git a/src/Psl/Filesystem/create_hard_link.php b/src/Psl/Filesystem/create_hard_link.php index b576b6da..6ae4b6ea 100644 --- a/src/Psl/Filesystem/create_hard_link.php +++ b/src/Psl/Filesystem/create_hard_link.php @@ -52,7 +52,7 @@ function create_hard_link(string $source, string $destination): void 'Failed to create hard link "%s" from "%s": %s.', $destination, $source, - $error_message ?? 'internal error' + $error_message ?? 'internal error', )); } // @codeCoverageIgnoreEnd diff --git a/src/Psl/Filesystem/create_symbolic_link.php b/src/Psl/Filesystem/create_symbolic_link.php index 2c04b2f9..92e37126 100644 --- a/src/Psl/Filesystem/create_symbolic_link.php +++ b/src/Psl/Filesystem/create_symbolic_link.php @@ -48,7 +48,7 @@ function create_symbolic_link(string $source, string $destination): void 'Failed to create symbolic link "%s" from "%s": %s.', $destination, $source, - $error_message ?? 'internal error' + $error_message ?? 'internal error', )); } // @codeCoverageIgnoreEnd diff --git a/src/Psl/Filesystem/create_temporary_file.php b/src/Psl/Filesystem/create_temporary_file.php index 52d12bbb..7f5b2625 100644 --- a/src/Psl/Filesystem/create_temporary_file.php +++ b/src/Psl/Filesystem/create_temporary_file.php @@ -23,7 +23,7 @@ * * @return non-empty-string The absolute path to the temporary file. */ -function create_temporary_file(?string $directory = null, ?string $prefix = null): string +function create_temporary_file(null|string $directory = null, null|string $prefix = null): string { $directory ??= Env\temp_dir(); if (!namespace\exists($directory)) { @@ -38,7 +38,10 @@ function create_temporary_file(?string $directory = null, ?string $prefix = null if (null !== $prefix) { /** @psalm-suppress MissingThrowsDocblock - $offset is within bounds. */ if (Str\contains($prefix, $separator)) { - throw new Exception\InvalidArgumentException(Str\format('$prefix should not contain a directory separator ( "%s" ).', $separator)); + throw new Exception\InvalidArgumentException(Str\format( + '$prefix should not contain a directory separator ( "%s" ).', + $separator, + )); } } else { $prefix = ''; diff --git a/src/Psl/Filesystem/delete_directory.php b/src/Psl/Filesystem/delete_directory.php index 7fd04273..ca6d7c11 100644 --- a/src/Psl/Filesystem/delete_directory.php +++ b/src/Psl/Filesystem/delete_directory.php @@ -60,7 +60,7 @@ function delete_directory(string $directory, bool $recursive = false): void throw new Exception\RuntimeException(Str\format( 'Failed to delete directory "%s": %s.', $directory, - $error_message ?? 'internal error' + $error_message ?? 'internal error', )); } // @codeCoverageIgnoreEnd diff --git a/src/Psl/Filesystem/delete_file.php b/src/Psl/Filesystem/delete_file.php index 97448b18..47799130 100644 --- a/src/Psl/Filesystem/delete_file.php +++ b/src/Psl/Filesystem/delete_file.php @@ -34,7 +34,7 @@ function delete_file(string $file): void throw new Exception\RuntimeException(Str\format( 'Failed to delete file "%s": %s.', $file, - $error_message ?? 'internal error' + $error_message ?? 'internal error', )); } // @codeCoverageIgnoreEnd diff --git a/src/Psl/Filesystem/file_size.php b/src/Psl/Filesystem/file_size.php index 7a2922b6..a62901ce 100644 --- a/src/Psl/Filesystem/file_size.php +++ b/src/Psl/Filesystem/file_size.php @@ -39,7 +39,7 @@ function file_size(string $file): int throw new Exception\RuntimeException(Str\format( 'Error reading the size of file "%s": %s', $file, - $message ?? 'internal error' + $message ?? 'internal error', )); } // @codeCoverageIgnoreEnd diff --git a/src/Psl/Filesystem/get_access_time.php b/src/Psl/Filesystem/get_access_time.php index a0c08ae5..7e413bdb 100644 --- a/src/Psl/Filesystem/get_access_time.php +++ b/src/Psl/Filesystem/get_access_time.php @@ -27,7 +27,7 @@ function get_access_time(string $node): int /** * @return false|int */ - static fn() => fileatime($node) + static fn() => fileatime($node), ); // @codeCoverageIgnoreStart @@ -35,7 +35,7 @@ function get_access_time(string $node): int throw new Exception\RuntimeException(Str\format( 'Failed to retrieve the access time of "%s": %s', $node, - $message ?? 'internal error' + $message ?? 'internal error', )); } // @codeCoverageIgnoreEnd diff --git a/src/Psl/Filesystem/get_basename.php b/src/Psl/Filesystem/get_basename.php index 6a0b88b3..41511cc1 100644 --- a/src/Psl/Filesystem/get_basename.php +++ b/src/Psl/Filesystem/get_basename.php @@ -20,7 +20,7 @@ * * @pure */ -function get_basename(string $path, ?string $suffix = null): string +function get_basename(string $path, null|string $suffix = null): string { if (null === $suffix) { /** @var non-empty-string */ diff --git a/src/Psl/Filesystem/get_change_time.php b/src/Psl/Filesystem/get_change_time.php index f77c094e..2c03ab3f 100644 --- a/src/Psl/Filesystem/get_change_time.php +++ b/src/Psl/Filesystem/get_change_time.php @@ -33,7 +33,7 @@ function get_change_time(string $node): int throw new Exception\RuntimeException(Str\format( 'Failed to retrieve the change time of "%s": %s', $node, - $message ?? 'internal error' + $message ?? 'internal error', )); } // @codeCoverageIgnoreEnd diff --git a/src/Psl/Filesystem/get_extension.php b/src/Psl/Filesystem/get_extension.php index 6ebc89df..c49d8ceb 100644 --- a/src/Psl/Filesystem/get_extension.php +++ b/src/Psl/Filesystem/get_extension.php @@ -15,7 +15,7 @@ * * @pure */ -function get_extension(string $node): ?string +function get_extension(string $node): null|string { $extension = pathinfo($node)['extension'] ?? null; diff --git a/src/Psl/Filesystem/get_group.php b/src/Psl/Filesystem/get_group.php index 173dccb4..28b36caa 100644 --- a/src/Psl/Filesystem/get_group.php +++ b/src/Psl/Filesystem/get_group.php @@ -27,14 +27,14 @@ function get_group(string $node): int /** * @return false|int */ - static fn() => filegroup($node) + static fn() => filegroup($node), ); if (false === $result) { throw new Exception\RuntimeException(Str\format( 'Failed to retrieve group of file "%s": %s', $node, - $message ?? 'internal error' + $message ?? 'internal error', )); } diff --git a/src/Psl/Filesystem/get_inode.php b/src/Psl/Filesystem/get_inode.php index 7e0a28d9..d2f4c7e1 100644 --- a/src/Psl/Filesystem/get_inode.php +++ b/src/Psl/Filesystem/get_inode.php @@ -29,7 +29,7 @@ function get_inode(string $node): int throw new Exception\RuntimeException(Str\format( 'Failed to retrieve the inode of "%s": %s', $node, - $message ?? 'internal error' + $message ?? 'internal error', )); } // @codeCoverageIgnoreEnd diff --git a/src/Psl/Filesystem/get_modification_time.php b/src/Psl/Filesystem/get_modification_time.php index f311678a..2bc6d171 100644 --- a/src/Psl/Filesystem/get_modification_time.php +++ b/src/Psl/Filesystem/get_modification_time.php @@ -31,7 +31,7 @@ function get_modification_time(string $node): int throw new Exception\RuntimeException(Str\format( 'Failed to retrieve the modification time of "%s": %s', $node, - $message ?? 'internal error' + $message ?? 'internal error', )); } // @codeCoverageIgnoreEnd diff --git a/src/Psl/Filesystem/get_owner.php b/src/Psl/Filesystem/get_owner.php index a2244be4..ace4ed1e 100644 --- a/src/Psl/Filesystem/get_owner.php +++ b/src/Psl/Filesystem/get_owner.php @@ -28,7 +28,7 @@ function get_owner(string $node): int throw new Exception\RuntimeException(Str\format( 'Failed to retrieve owner of file "%s": %s', $node, - $message ?? 'internal error' + $message ?? 'internal error', )); } diff --git a/src/Psl/Filesystem/get_permissions.php b/src/Psl/Filesystem/get_permissions.php index 5b2a767a..1a80e5f2 100644 --- a/src/Psl/Filesystem/get_permissions.php +++ b/src/Psl/Filesystem/get_permissions.php @@ -29,7 +29,7 @@ function get_permissions(string $node): int throw new Exception\RuntimeException(Str\format( 'Failed to retrieve permissions of file "%s": %s', $node, - $message ?? 'internal error' + $message ?? 'internal error', )); } // @codeCoverageIgnoreEnd diff --git a/src/Psl/Filesystem/read_directory.php b/src/Psl/Filesystem/read_directory.php index 2ab877b0..349d4ea7 100644 --- a/src/Psl/Filesystem/read_directory.php +++ b/src/Psl/Filesystem/read_directory.php @@ -33,8 +33,7 @@ function read_directory(string $directory): array } /** @var list */ - return Vec\values(new FilesystemIterator( - $directory, - FilesystemIterator::CURRENT_AS_PATHNAME | FilesystemIterator::SKIP_DOTS - )); + return Vec\values( + new FilesystemIterator($directory, FilesystemIterator::CURRENT_AS_PATHNAME | FilesystemIterator::SKIP_DOTS), + ); } diff --git a/src/Psl/Filesystem/read_symbolic_link.php b/src/Psl/Filesystem/read_symbolic_link.php index ef94b83a..932badcd 100644 --- a/src/Psl/Filesystem/read_symbolic_link.php +++ b/src/Psl/Filesystem/read_symbolic_link.php @@ -34,7 +34,7 @@ function read_symbolic_link(string $symbolic_link): string /** * @return false|string */ - static fn() => readlink($symbolic_link) + static fn() => readlink($symbolic_link), ); // @codeCoverageIgnoreStart @@ -42,7 +42,7 @@ function read_symbolic_link(string $symbolic_link): string throw new Exception\RuntimeException(Str\format( 'Failed to retrieve the target of symbolic link "%s": %s', $symbolic_link, - $message ?? 'internal error' + $message ?? 'internal error', )); } // @codeCoverageIgnoreEnd diff --git a/src/Psl/Fun/Internal/LazyEvaluator.php b/src/Psl/Fun/Internal/LazyEvaluator.php index 9fd9d50c..305cd03c 100644 --- a/src/Psl/Fun/Internal/LazyEvaluator.php +++ b/src/Psl/Fun/Internal/LazyEvaluator.php @@ -24,7 +24,7 @@ final class LazyEvaluator * @param (Closure(): T) $initializer */ public function __construct( - private Closure $initializer + private Closure $initializer, ) { } diff --git a/src/Psl/Fun/after.php b/src/Psl/Fun/after.php index 33704542..a869b2e7 100644 --- a/src/Psl/Fun/after.php +++ b/src/Psl/Fun/after.php @@ -22,5 +22,5 @@ */ function after(Closure $first, Closure $next): Closure { - return static fn ($input) => $next($first($input)); + return static fn($input) => $next($first($input)); } diff --git a/src/Psl/Fun/identity.php b/src/Psl/Fun/identity.php index c4078881..2a2bc0e3 100644 --- a/src/Psl/Fun/identity.php +++ b/src/Psl/Fun/identity.php @@ -17,5 +17,5 @@ */ function identity(): Closure { - return static fn ($result) => $result; + return static fn($result) => $result; } diff --git a/src/Psl/Fun/pipe.php b/src/Psl/Fun/pipe.php index 69163541..6adad1e2 100644 --- a/src/Psl/Fun/pipe.php +++ b/src/Psl/Fun/pipe.php @@ -20,7 +20,7 @@ */ function pipe(Closure ...$stages): Closure { - return static fn ($input) => Iter\reduce( + return static fn($input) => Iter\reduce( $stages, /** * @param T $input @@ -28,7 +28,7 @@ function pipe(Closure ...$stages): Closure * * @return T */ - static fn (mixed $input, Closure $next): mixed => $next($input), - $input + static fn(mixed $input, Closure $next): mixed => $next($input), + $input, ); } diff --git a/src/Psl/Fun/when.php b/src/Psl/Fun/when.php index df74babd..1b0f3446 100644 --- a/src/Psl/Fun/when.php +++ b/src/Psl/Fun/when.php @@ -23,5 +23,5 @@ */ function when(Closure $condition, Closure $then, Closure $else): Closure { - return static fn ($value) => $condition($value) ? $then($value) : $else($value); + return static fn($value) => $condition($value) ? $then($value) : $else($value); } diff --git a/src/Psl/Hash/Algorithm.php b/src/Psl/Hash/Algorithm.php index 0ee12cd6..ed32abb8 100644 --- a/src/Psl/Hash/Algorithm.php +++ b/src/Psl/Hash/Algorithm.php @@ -6,64 +6,64 @@ enum Algorithm: string { - case Md2 = "md2"; - case Md4 = "md4"; - case Md5 = "md5"; - case Sha1 = "sha1"; - case Sha224 = "sha224"; - case Sha256 = "sha256"; - case Sha384 = "sha384"; - case Sha512224 = "sha512/224"; - case Sha512256 = "sha512/256"; - case Sha512 = "sha512"; - case Sha3224 = "sha3-224"; - case Sha3256 = "sha3-256"; - case Sha3384 = "sha3-384"; - case Sha3512 = "sha3-512"; - case Ripemd128 = "ripemd128"; - case Ripemd160 = "ripemd160"; - case Ripemd256 = "ripemd256"; - case Ripemd320 = "ripemd320"; - case Whirlpool = "whirlpool"; - case Tiger1283 = "tiger128,3"; - case Tiger1603 = "tiger160,3"; - case Tiger1923 = "tiger192,3"; - case Tiger1284 = "tiger128,4"; - case Tiger1604 = "tiger160,4"; - case Tiger1924 = "tiger192,4"; - case Snefru = "snefru"; - case Snefru256 = "snefru256"; - case Gost = "gost"; - case GostCrypto = "gost-crypto"; - case Adler32 = "adler32"; - case Crc32 = "crc32"; - case Crc32B = "crc32b"; - case Crc32C = "crc32c"; - case Fnv132 = "fnv132"; - case Fnv1A32 = "fnv1a32"; - case Fnv164 = "fnv164"; - case Fnv1A64 = "fnv1a64"; - case Joaat = "joaat"; - case Murmur3A = "murmur3a"; - case Murmur3C = "murmur3c"; - case Murmur3F = "murmur3f"; - case Xxh32 = "xxh32"; - case Xxh64 = "xxh64"; - case Xxh3 = "xxh3"; - case Xxh128 = "xxh128"; - case Haval1283 = "haval128,3"; - case Haval1603 = "haval160,3"; - case Haval1923 = "haval192,3"; - case Haval2243 = "haval224,3"; - case Haval2563 = "haval256,3"; - case Haval1284 = "haval128,4"; - case Haval1604 = "haval160,4"; - case Haval1924 = "haval192,4"; - case Haval2244 = "haval224,4"; - case Haval2564 = "haval256,4"; - case Haval1285 = "haval128,5"; - case Haval1605 = "haval160,5"; - case Haval1925 = "haval192,5"; - case Haval2245 = "haval224,5"; - case Haval2565 = "haval256,5"; + case Md2 = 'md2'; + case Md4 = 'md4'; + case Md5 = 'md5'; + case Sha1 = 'sha1'; + case Sha224 = 'sha224'; + case Sha256 = 'sha256'; + case Sha384 = 'sha384'; + case Sha512224 = 'sha512/224'; + case Sha512256 = 'sha512/256'; + case Sha512 = 'sha512'; + case Sha3224 = 'sha3-224'; + case Sha3256 = 'sha3-256'; + case Sha3384 = 'sha3-384'; + case Sha3512 = 'sha3-512'; + case Ripemd128 = 'ripemd128'; + case Ripemd160 = 'ripemd160'; + case Ripemd256 = 'ripemd256'; + case Ripemd320 = 'ripemd320'; + case Whirlpool = 'whirlpool'; + case Tiger1283 = 'tiger128,3'; + case Tiger1603 = 'tiger160,3'; + case Tiger1923 = 'tiger192,3'; + case Tiger1284 = 'tiger128,4'; + case Tiger1604 = 'tiger160,4'; + case Tiger1924 = 'tiger192,4'; + case Snefru = 'snefru'; + case Snefru256 = 'snefru256'; + case Gost = 'gost'; + case GostCrypto = 'gost-crypto'; + case Adler32 = 'adler32'; + case Crc32 = 'crc32'; + case Crc32B = 'crc32b'; + case Crc32C = 'crc32c'; + case Fnv132 = 'fnv132'; + case Fnv1A32 = 'fnv1a32'; + case Fnv164 = 'fnv164'; + case Fnv1A64 = 'fnv1a64'; + case Joaat = 'joaat'; + case Murmur3A = 'murmur3a'; + case Murmur3C = 'murmur3c'; + case Murmur3F = 'murmur3f'; + case Xxh32 = 'xxh32'; + case Xxh64 = 'xxh64'; + case Xxh3 = 'xxh3'; + case Xxh128 = 'xxh128'; + case Haval1283 = 'haval128,3'; + case Haval1603 = 'haval160,3'; + case Haval1923 = 'haval192,3'; + case Haval2243 = 'haval224,3'; + case Haval2563 = 'haval256,3'; + case Haval1284 = 'haval128,4'; + case Haval1604 = 'haval160,4'; + case Haval1924 = 'haval192,4'; + case Haval2244 = 'haval224,4'; + case Haval2564 = 'haval256,4'; + case Haval1285 = 'haval128,5'; + case Haval1605 = 'haval160,5'; + case Haval1925 = 'haval192,5'; + case Haval2245 = 'haval224,5'; + case Haval2565 = 'haval256,5'; } diff --git a/src/Psl/Hash/Context.php b/src/Psl/Hash/Context.php index 0fe2b7c9..e31c0a3a 100644 --- a/src/Psl/Hash/Context.php +++ b/src/Psl/Hash/Context.php @@ -25,13 +25,13 @@ * * @psalm-immutable */ -final class Context +final readonly class Context { /** * @pure */ private function __construct( - private readonly HashContext $internalContext + private HashContext $internalContext, ) { } diff --git a/src/Psl/Hash/Hmac/Algorithm.php b/src/Psl/Hash/Hmac/Algorithm.php index e8c430a6..d6f2815b 100644 --- a/src/Psl/Hash/Hmac/Algorithm.php +++ b/src/Psl/Hash/Hmac/Algorithm.php @@ -6,48 +6,48 @@ enum Algorithm: string { - case Md2 = "md2"; - case Md4 = "md4"; - case Md5 = "md5"; - case Sha1 = "sha1"; - case Sha224 = "sha224"; - case Sha256 = "sha256"; - case Sha384 = "sha384"; - case Sha512224 = "sha512/224"; - case Sha512256 = "sha512/256"; - case Sha512 = "sha512"; - case Sha3224 = "sha3-224"; - case Sha3256 = "sha3-256"; - case Sha3384 = "sha3-384"; - case Sha3512 = "sha3-512"; - case Ripemd128 = "ripemd128"; - case Ripemd160 = "ripemd160"; - case Ripemd256 = "ripemd256"; - case Ripemd320 = "ripemd320"; - case Whirlpool = "whirlpool"; - case Tiger1283 = "tiger128,3"; - case Tiger1603 = "tiger160,3"; - case Tiger1923 = "tiger192,3"; - case Tiger1284 = "tiger128,4"; - case Tiger1604 = "tiger160,4"; - case Tiger1924 = "tiger192,4"; - case Snefru = "snefru"; - case Snefru256 = "snefru256"; - case Gost = "gost"; - case GostCrypto = "gost-crypto"; - case Haval1283 = "haval128,3"; - case Haval1603 = "haval160,3"; - case Haval1923 = "haval192,3"; - case Haval2243 = "haval224,3"; - case Haval2563 = "haval256,3"; - case Haval1284 = "haval128,4"; - case Haval1604 = "haval160,4"; - case Haval1924 = "haval192,4"; - case Haval2244 = "haval224,4"; - case Haval2564 = "haval256,4"; - case Haval1285 = "haval128,5"; - case Haval1605 = "haval160,5"; - case Haval1925 = "haval192,5"; - case Haval2245 = "haval224,5"; - case Haval2565 = "haval256,5"; + case Md2 = 'md2'; + case Md4 = 'md4'; + case Md5 = 'md5'; + case Sha1 = 'sha1'; + case Sha224 = 'sha224'; + case Sha256 = 'sha256'; + case Sha384 = 'sha384'; + case Sha512224 = 'sha512/224'; + case Sha512256 = 'sha512/256'; + case Sha512 = 'sha512'; + case Sha3224 = 'sha3-224'; + case Sha3256 = 'sha3-256'; + case Sha3384 = 'sha3-384'; + case Sha3512 = 'sha3-512'; + case Ripemd128 = 'ripemd128'; + case Ripemd160 = 'ripemd160'; + case Ripemd256 = 'ripemd256'; + case Ripemd320 = 'ripemd320'; + case Whirlpool = 'whirlpool'; + case Tiger1283 = 'tiger128,3'; + case Tiger1603 = 'tiger160,3'; + case Tiger1923 = 'tiger192,3'; + case Tiger1284 = 'tiger128,4'; + case Tiger1604 = 'tiger160,4'; + case Tiger1924 = 'tiger192,4'; + case Snefru = 'snefru'; + case Snefru256 = 'snefru256'; + case Gost = 'gost'; + case GostCrypto = 'gost-crypto'; + case Haval1283 = 'haval128,3'; + case Haval1603 = 'haval160,3'; + case Haval1923 = 'haval192,3'; + case Haval2243 = 'haval224,3'; + case Haval2563 = 'haval256,3'; + case Haval1284 = 'haval128,4'; + case Haval1604 = 'haval160,4'; + case Haval1924 = 'haval192,4'; + case Haval2244 = 'haval224,4'; + case Haval2564 = 'haval256,4'; + case Haval1285 = 'haval128,5'; + case Haval1605 = 'haval160,5'; + case Haval1925 = 'haval192,5'; + case Haval2245 = 'haval224,5'; + case Haval2565 = 'haval256,5'; } diff --git a/src/Psl/Html/encode_special_characters.php b/src/Psl/Html/encode_special_characters.php index b1c49ed0..a2156c99 100644 --- a/src/Psl/Html/encode_special_characters.php +++ b/src/Psl/Html/encode_special_characters.php @@ -21,7 +21,10 @@ * * @pure */ -function encode_special_characters(string $html, bool $double_encoding = true, Encoding $encoding = Encoding::Utf8): string -{ +function encode_special_characters( + string $html, + bool $double_encoding = true, + Encoding $encoding = Encoding::Utf8, +): string { return htmlspecialchars($html, ENT_QUOTES | ENT_HTML5 | ENT_SUBSTITUTE, $encoding->value, $double_encoding); } diff --git a/src/Psl/IO/CloseReadStreamHandle.php b/src/Psl/IO/CloseReadStreamHandle.php index f61dba4c..b384bc14 100644 --- a/src/Psl/IO/CloseReadStreamHandle.php +++ b/src/Psl/IO/CloseReadStreamHandle.php @@ -35,7 +35,7 @@ public function reachedEndOfDataSource(): bool /** * {@inheritDoc} */ - public function tryRead(?int $max_bytes = null): string + public function tryRead(null|int $max_bytes = null): string { return $this->handle->tryRead($max_bytes); } @@ -43,7 +43,7 @@ public function tryRead(?int $max_bytes = null): string /** * {@inheritDoc} */ - public function read(?int $max_bytes = null, ?Duration $timeout = null): string + public function read(null|int $max_bytes = null, null|Duration $timeout = null): string { return $this->handle->read($max_bytes, $timeout); } diff --git a/src/Psl/IO/CloseReadStreamHandleInterface.php b/src/Psl/IO/CloseReadStreamHandleInterface.php index c0a37dfa..3f3c617c 100644 --- a/src/Psl/IO/CloseReadStreamHandleInterface.php +++ b/src/Psl/IO/CloseReadStreamHandleInterface.php @@ -6,6 +6,9 @@ use Psl\IO; -interface CloseReadStreamHandleInterface extends CloseStreamHandleInterface, IO\CloseReadHandleInterface, ReadStreamHandleInterface +interface CloseReadStreamHandleInterface extends + CloseStreamHandleInterface, + IO\CloseReadHandleInterface, + ReadStreamHandleInterface { } diff --git a/src/Psl/IO/CloseReadWriteStreamHandle.php b/src/Psl/IO/CloseReadWriteStreamHandle.php index d3a56f14..2209f13b 100644 --- a/src/Psl/IO/CloseReadWriteStreamHandle.php +++ b/src/Psl/IO/CloseReadWriteStreamHandle.php @@ -36,7 +36,7 @@ public function reachedEndOfDataSource(): bool /** * {@inheritDoc} */ - public function tryRead(?int $max_bytes = null): string + public function tryRead(null|int $max_bytes = null): string { return $this->handle->tryRead($max_bytes); } @@ -44,7 +44,7 @@ public function tryRead(?int $max_bytes = null): string /** * {@inheritDoc} */ - public function read(?int $max_bytes = null, ?Duration $timeout = null): string + public function read(null|int $max_bytes = null, null|Duration $timeout = null): string { return $this->handle->read($max_bytes, $timeout); } @@ -60,7 +60,7 @@ public function tryWrite(string $bytes): int /** * {@inheritDoc} */ - public function write(string $bytes, ?Duration $timeout = null): int + public function write(string $bytes, null|Duration $timeout = null): int { return $this->handle->write($bytes, $timeout); } diff --git a/src/Psl/IO/CloseSeekHandleInterface.php b/src/Psl/IO/CloseSeekHandleInterface.php index 7c3f8a68..fe10abee 100644 --- a/src/Psl/IO/CloseSeekHandleInterface.php +++ b/src/Psl/IO/CloseSeekHandleInterface.php @@ -4,8 +4,6 @@ namespace Psl\IO; -interface CloseSeekHandleInterface extends - CloseHandleInterface, - SeekHandleInterface +interface CloseSeekHandleInterface extends CloseHandleInterface, SeekHandleInterface { } diff --git a/src/Psl/IO/CloseSeekReadStreamHandle.php b/src/Psl/IO/CloseSeekReadStreamHandle.php index b88fbd56..d4613876 100644 --- a/src/Psl/IO/CloseSeekReadStreamHandle.php +++ b/src/Psl/IO/CloseSeekReadStreamHandle.php @@ -35,7 +35,7 @@ public function reachedEndOfDataSource(): bool /** * {@inheritDoc} */ - public function tryRead(?int $max_bytes = null): string + public function tryRead(null|int $max_bytes = null): string { return $this->handle->tryRead($max_bytes); } @@ -43,7 +43,7 @@ public function tryRead(?int $max_bytes = null): string /** * {@inheritDoc} */ - public function read(?int $max_bytes = null, ?Duration $timeout = null): string + public function read(null|int $max_bytes = null, null|Duration $timeout = null): string { return $this->handle->read($max_bytes, $timeout); } diff --git a/src/Psl/IO/CloseSeekReadWriteStreamHandle.php b/src/Psl/IO/CloseSeekReadWriteStreamHandle.php index 02fc796e..612cd6bd 100644 --- a/src/Psl/IO/CloseSeekReadWriteStreamHandle.php +++ b/src/Psl/IO/CloseSeekReadWriteStreamHandle.php @@ -36,7 +36,7 @@ public function reachedEndOfDataSource(): bool /** * {@inheritDoc} */ - public function tryRead(?int $max_bytes = null): string + public function tryRead(null|int $max_bytes = null): string { return $this->handle->tryRead($max_bytes); } @@ -44,7 +44,7 @@ public function tryRead(?int $max_bytes = null): string /** * {@inheritDoc} */ - public function read(?int $max_bytes = null, ?Duration $timeout = null): string + public function read(null|int $max_bytes = null, null|Duration $timeout = null): string { return $this->handle->read($max_bytes, $timeout); } @@ -60,7 +60,7 @@ public function tryWrite(string $bytes): int /** * {@inheritDoc} */ - public function write(string $bytes, ?Duration $timeout = null): int + public function write(string $bytes, null|Duration $timeout = null): int { return $this->handle->write($bytes, $timeout); } diff --git a/src/Psl/IO/CloseSeekWriteStreamHandle.php b/src/Psl/IO/CloseSeekWriteStreamHandle.php index 480ae3e0..4994c695 100644 --- a/src/Psl/IO/CloseSeekWriteStreamHandle.php +++ b/src/Psl/IO/CloseSeekWriteStreamHandle.php @@ -35,7 +35,7 @@ public function tryWrite(string $bytes): int /** * {@inheritDoc} */ - public function write(string $bytes, ?Duration $timeout = null): int + public function write(string $bytes, null|Duration $timeout = null): int { return $this->handle->write($bytes, $timeout); } diff --git a/src/Psl/IO/CloseWriteStreamHandle.php b/src/Psl/IO/CloseWriteStreamHandle.php index 76017268..193fc9c9 100644 --- a/src/Psl/IO/CloseWriteStreamHandle.php +++ b/src/Psl/IO/CloseWriteStreamHandle.php @@ -35,7 +35,7 @@ public function tryWrite(string $bytes): int /** * {@inheritDoc} */ - public function write(string $bytes, ?Duration $timeout = null): int + public function write(string $bytes, null|Duration $timeout = null): int { return $this->handle->write($bytes, $timeout); } diff --git a/src/Psl/IO/CloseWriteStreamHandleInterface.php b/src/Psl/IO/CloseWriteStreamHandleInterface.php index 0900bb6a..f096388e 100644 --- a/src/Psl/IO/CloseWriteStreamHandleInterface.php +++ b/src/Psl/IO/CloseWriteStreamHandleInterface.php @@ -6,6 +6,9 @@ use Psl\IO; -interface CloseWriteStreamHandleInterface extends CloseStreamHandleInterface, IO\CloseWriteHandleInterface, WriteStreamHandleInterface +interface CloseWriteStreamHandleInterface extends + CloseStreamHandleInterface, + IO\CloseWriteHandleInterface, + WriteStreamHandleInterface { } diff --git a/src/Psl/IO/Internal/ResourceHandle.php b/src/Psl/IO/Internal/ResourceHandle.php index a42789e3..a328e907 100644 --- a/src/Psl/IO/Internal/ResourceHandle.php +++ b/src/Psl/IO/Internal/ResourceHandle.php @@ -54,15 +54,15 @@ class ResourceHandle implements IO\CloseSeekReadWriteStreamHandleInterface /** * @var null|Async\Sequence> */ - private ?Async\Sequence $writeSequence = null; - private ?Suspension $writeSuspension = null; + private null|Async\Sequence $writeSequence = null; + private null|Suspension $writeSuspension = null; private string $writeWatcher = 'invalid'; /** * @var null|Async\Sequence, null|Duration}, string> */ - private ?Async\Sequence $readSequence = null; - private ?Suspension $readSuspension = null; + private null|Async\Sequence $readSequence = null; + private null|Suspension $readSuspension = null; private string $readWatcher = 'invalid'; private bool $useSingleRead = false; @@ -71,8 +71,13 @@ class ResourceHandle implements IO\CloseSeekReadWriteStreamHandleInterface /** * @param resource $stream */ - public function __construct(mixed $stream, bool $read, bool $write, bool $seek, private readonly bool $close) - { + public function __construct( + mixed $stream, + bool $read, + bool $write, + bool $seek, + private readonly bool $close, + ) { /** @psalm-suppress RedundantConditionGivenDocblockType - The stream is always a resource, but we want to make sure it is a stream resource. */ $this->stream = Type\resource('stream')->assert($stream); @@ -80,7 +85,7 @@ public function __construct(mixed $stream, bool $read, bool $write, bool $seek, $meta = stream_get_meta_data($stream); if ($read) { - $this->useSingleRead = ($meta["stream_type"] === "udp_socket" || $meta["stream_type"] === "STDIO"); + $this->useSingleRead = $meta['stream_type'] === 'udp_socket' || $meta['stream_type'] === 'STDIO'; } $blocks = $meta['blocked'] || ($meta['wrapper_type'] ?? '') === 'plainfile'; @@ -118,10 +123,9 @@ function (array $input) use ($blocks): string { $delay_watcher = null; if (null !== $timeout) { $timeout = max($timeout->getTotalSeconds(), 0.0); - $delay_watcher = EventLoop::delay( - $timeout, - static fn () => $suspension->throw(new Exception\TimeoutException('Reached timeout while the handle is still not readable.')), - ); + $delay_watcher = EventLoop::delay($timeout, static fn() => $suspension->throw( + new Exception\TimeoutException('Reached timeout while the handle is still not readable.'), + )); EventLoop::unreference($delay_watcher); } @@ -137,18 +141,19 @@ function (array $input) use ($blocks): string { EventLoop::cancel($delay_watcher); } } - } + }, ); EventLoop::disable($this->readWatcher); } if ($write) { - $writable = str_contains($meta['mode'], 'x') - || str_contains($meta['mode'], 'w') - || str_contains($meta['mode'], 'c') - || str_contains($meta['mode'], 'a') - || str_contains($meta['mode'], '+'); + $writable = + str_contains($meta['mode'], 'x') || + str_contains($meta['mode'], 'w') || + str_contains($meta['mode'], 'c') || + str_contains($meta['mode'], 'a') || + str_contains($meta['mode'], '+'); Psl\invariant($writable, 'Handle is not writeable.'); @@ -177,10 +182,9 @@ function (array $input) use ($blocks): int { $delay_watcher = null; if (null !== $timeout) { $timeout = max($timeout->getTotalSeconds(), 0.0); - $delay_watcher = EventLoop::delay( - $timeout, - static fn () => $suspension->throw(new Exception\TimeoutException('Reached timeout while the handle is still not readable.')), - ); + $delay_watcher = EventLoop::delay($timeout, static fn() => $suspension->throw( + new Exception\TimeoutException('Reached timeout while the handle is still not readable.'), + )); EventLoop::unreference($delay_watcher); } @@ -205,7 +209,7 @@ function (array $input) use ($blocks): int { /** * {@inheritDoc} */ - public function write(string $bytes, ?Duration $timeout = null): int + public function write(string $bytes, null|Duration $timeout = null): int { Psl\invariant($this->writeSequence !== null, 'The resource handle is not writable.'); @@ -284,7 +288,7 @@ public function reachedEndOfDataSource(): bool /** * {@inheritDoc} */ - public function read(?int $max_bytes = null, ?Duration $timeout = null): string + public function read(null|int $max_bytes = null, null|Duration $timeout = null): string { Psl\invariant($this->readSequence !== null, 'The resource handle is not readable.'); @@ -294,7 +298,7 @@ public function read(?int $max_bytes = null, ?Duration $timeout = null): string /** * {@inheritDoc} */ - public function tryRead(?int $max_bytes = null): string + public function tryRead(null|int $max_bytes = null): string { if (!is_resource($this->stream)) { throw new Exception\AlreadyClosedException('Handle has already been closed.'); diff --git a/src/Psl/IO/MemoryHandle.php b/src/Psl/IO/MemoryHandle.php index f8182e43..134256a1 100644 --- a/src/Psl/IO/MemoryHandle.php +++ b/src/Psl/IO/MemoryHandle.php @@ -49,7 +49,7 @@ public function reachedEndOfDataSource(): bool * * @psalm-external-mutation-free */ - public function tryRead(?int $max_bytes = null): string + public function tryRead(null|int $max_bytes = null): string { $this->assertHandleIsOpen(); @@ -77,7 +77,7 @@ public function tryRead(?int $max_bytes = null): string * * @psalm-external-mutation-free */ - public function read(?int $max_bytes = null, ?Duration $timeout = null): string + public function read(null|int $max_bytes = null, null|Duration $timeout = null): string { return $this->tryRead($max_bytes); } @@ -111,7 +111,7 @@ public function tell(): int * * @psalm-external-mutation-free */ - public function tryWrite(string $bytes, ?Duration $timeout = null): int + public function tryWrite(string $bytes, null|Duration $timeout = null): int { $this->assertHandleIsOpen(); $length = strlen($this->buffer); @@ -138,7 +138,7 @@ public function tryWrite(string $bytes, ?Duration $timeout = null): int * * @psalm-external-mutation-free */ - public function write(string $bytes, ?Duration $timeout = null): int + public function write(string $bytes, null|Duration $timeout = null): int { return $this->tryWrite($bytes); } diff --git a/src/Psl/IO/ReadHandleConvenienceMethodsTrait.php b/src/Psl/IO/ReadHandleConvenienceMethodsTrait.php index 8cede651..d3734b1f 100644 --- a/src/Psl/IO/ReadHandleConvenienceMethodsTrait.php +++ b/src/Psl/IO/ReadHandleConvenienceMethodsTrait.php @@ -31,23 +31,20 @@ trait ReadHandleConvenienceMethodsTrait * @throws Exception\RuntimeException If an error occurred during the operation. * @throws Exception\TimeoutException If $timeout is reached before being able to read from the handle. */ - public function readAll(?int $max_bytes = null, ?Duration $timeout = null): string + public function readAll(null|int $max_bytes = null, null|Duration $timeout = null): string { $to_read = $max_bytes; /** @var Psl\Ref $data */ $data = new Psl\Ref(''); - $timer = new Psl\Async\OptionalIncrementalTimeout( - $timeout, - static function () use ($data): void { - // @codeCoverageIgnoreStart - throw new Exception\TimeoutException(Str\format( - "Reached timeout before %s data could be read.", - ($data->value === '') ? 'any' : 'all', - )); - // @codeCoverageIgnoreEnd - }, - ); + $timer = new Psl\Async\OptionalIncrementalTimeout($timeout, static function () use ($data): void { + // @codeCoverageIgnoreStart + throw new Exception\TimeoutException(Str\format( + 'Reached timeout before %s data could be read.', + $data->value === '' ? 'any' : 'all', + )); + // @codeCoverageIgnoreEnd + }); do { $chunk_size = $to_read; @@ -79,13 +76,13 @@ static function () use ($data): void { * @throws Exception\RuntimeException If an error occurred during the operation. * @throws Exception\TimeoutException If $timeout is reached before being able to read from the handle. */ - public function readFixedSize(int $size, ?Duration $timeout = null): string + public function readFixedSize(int $size, null|Duration $timeout = null): string { $data = $this->readAll($size, $timeout); if (($length = strlen($data)) !== $size) { throw new Exception\RuntimeException(Str\format( - "%d bytes were requested, but only able to read %d bytes", + '%d bytes were requested, but only able to read %d bytes', $size, $length, )); diff --git a/src/Psl/IO/ReadHandleInterface.php b/src/Psl/IO/ReadHandleInterface.php index 9de72326..5101dd80 100644 --- a/src/Psl/IO/ReadHandleInterface.php +++ b/src/Psl/IO/ReadHandleInterface.php @@ -47,7 +47,7 @@ public function reachedEndOfDataSource(): bool; * @see ReadStreamHandleInterface::read() * @see ReadStreamHandleInterface::readAll() */ - public function tryRead(?int $max_bytes = null): string; + public function tryRead(null|int $max_bytes = null): string; /** * Read from the handle, waiting for data if necessary. @@ -63,7 +63,7 @@ public function tryRead(?int $max_bytes = null): string; * Up to `$max_bytes` may be allocated in a buffer; large values may lead to * unnecessarily hitting the request memory limit. */ - public function read(?int $max_bytes = null, ?Duration $timeout = null): string; + public function read(null|int $max_bytes = null, null|Duration $timeout = null): string; /** * Read until there is no more data to read. @@ -81,7 +81,7 @@ public function read(?int $max_bytes = null, ?Duration $timeout = null): string; * @throws Exception\RuntimeException If an error occurred during the operation. * @throws Exception\TimeoutException If $timeout is reached before being able to read from the handle. */ - public function readAll(?int $max_bytes = null, ?Duration $timeout = null): string; + public function readAll(null|int $max_bytes = null, null|Duration $timeout = null): string; /** * Read a fixed amount of data. @@ -96,5 +96,5 @@ public function readAll(?int $max_bytes = null, ?Duration $timeout = null): stri * @throws Exception\RuntimeException If an error occurred during the operation. * @throws Exception\TimeoutException If $timeout is reached before being able to read from the handle. */ - public function readFixedSize(int $size, ?Duration $timeout = null): string; + public function readFixedSize(int $size, null|Duration $timeout = null): string; } diff --git a/src/Psl/IO/ReadStreamHandle.php b/src/Psl/IO/ReadStreamHandle.php index 9530daba..3bedbf10 100644 --- a/src/Psl/IO/ReadStreamHandle.php +++ b/src/Psl/IO/ReadStreamHandle.php @@ -35,7 +35,7 @@ public function reachedEndOfDataSource(): bool /** * {@inheritDoc} */ - public function tryRead(?int $max_bytes = null): string + public function tryRead(null|int $max_bytes = null): string { return $this->handle->tryRead($max_bytes); } @@ -43,7 +43,7 @@ public function tryRead(?int $max_bytes = null): string /** * {@inheritDoc} */ - public function read(?int $max_bytes = null, ?Duration $timeout = null): string + public function read(null|int $max_bytes = null, null|Duration $timeout = null): string { return $this->handle->read($max_bytes, $timeout); } diff --git a/src/Psl/IO/ReadWriteStreamHandle.php b/src/Psl/IO/ReadWriteStreamHandle.php index 9f30d5c4..4b83a405 100644 --- a/src/Psl/IO/ReadWriteStreamHandle.php +++ b/src/Psl/IO/ReadWriteStreamHandle.php @@ -36,7 +36,7 @@ public function reachedEndOfDataSource(): bool /** * {@inheritDoc} */ - public function tryRead(?int $max_bytes = null): string + public function tryRead(null|int $max_bytes = null): string { return $this->handle->tryRead($max_bytes); } @@ -44,7 +44,7 @@ public function tryRead(?int $max_bytes = null): string /** * {@inheritDoc} */ - public function read(?int $max_bytes = null, ?Duration $timeout = null): string + public function read(null|int $max_bytes = null, null|Duration $timeout = null): string { return $this->handle->read($max_bytes, $timeout); } @@ -60,7 +60,7 @@ public function tryWrite(string $bytes): int /** * {@inheritDoc} */ - public function write(string $bytes, ?Duration $timeout = null): int + public function write(string $bytes, null|Duration $timeout = null): int { return $this->handle->write($bytes, $timeout); } diff --git a/src/Psl/IO/ReadWriteStreamHandleInterface.php b/src/Psl/IO/ReadWriteStreamHandleInterface.php index dc70741e..52010f7b 100644 --- a/src/Psl/IO/ReadWriteStreamHandleInterface.php +++ b/src/Psl/IO/ReadWriteStreamHandleInterface.php @@ -6,6 +6,9 @@ use Psl\IO; -interface ReadWriteStreamHandleInterface extends IO\ReadWriteHandleInterface, ReadStreamHandleInterface, WriteStreamHandleInterface +interface ReadWriteStreamHandleInterface extends + IO\ReadWriteHandleInterface, + ReadStreamHandleInterface, + WriteStreamHandleInterface { } diff --git a/src/Psl/IO/Reader.php b/src/Psl/IO/Reader.php index ee5b3e0b..b81c684a 100644 --- a/src/Psl/IO/Reader.php +++ b/src/Psl/IO/Reader.php @@ -58,19 +58,16 @@ public function reachedEndOfDataSource(): bool /** * {@inheritDoc} */ - public function readFixedSize(int $size, ?Duration $timeout = null): string + public function readFixedSize(int $size, null|Duration $timeout = null): string { - $timer = new Async\OptionalIncrementalTimeout( - $timeout, - function (): void { - // @codeCoverageIgnoreStart - throw new Exception\TimeoutException(Str\format( - "Reached timeout before reading requested amount of data", - $this->buffer === '' ? 'any' : 'all', - )); - // @codeCoverageIgnoreEnd - }, - ); + $timer = new Async\OptionalIncrementalTimeout($timeout, function (): void { + // @codeCoverageIgnoreStart + throw new Exception\TimeoutException(Str\format( + 'Reached timeout before reading requested amount of data', + $this->buffer === '' ? 'any' : 'all', + )); + // @codeCoverageIgnoreEnd + }); while (($length = strlen($this->buffer)) < $size && !$this->eof) { /** @var positive-int $to_read */ @@ -101,7 +98,7 @@ function (): void { * @throws Exception\RuntimeException If an error occurred during the operation, or reached end of file. * @throws Exception\TimeoutException If $timeout is reached before being able to read from the handle. */ - public function readByte(?Duration $timeout = null): string + public function readByte(null|Duration $timeout = null): string { if ($this->buffer === '' && !$this->eof) { $this->fillBuffer(null, $timeout); @@ -129,18 +126,15 @@ public function readByte(?Duration $timeout = null): string * @throws Exception\RuntimeException If an error occurred during the operation. * @throws Exception\TimeoutException If $timeout is reached before being able to read from the handle. */ - public function readLine(?Duration $timeout = null): ?string + public function readLine(null|Duration $timeout = null): null|string { - $timer = new Async\OptionalIncrementalTimeout( - $timeout, - static function (): void { - // @codeCoverageIgnoreStart - throw new Exception\TimeoutException( - "Reached timeout before encountering reaching the current line terminator.", - ); - // @codeCoverageIgnoreEnd - }, - ); + $timer = new Async\OptionalIncrementalTimeout($timeout, static function (): void { + // @codeCoverageIgnoreStart + throw new Exception\TimeoutException( + 'Reached timeout before encountering reaching the current line terminator.', + ); + // @codeCoverageIgnoreEnd + }); $line = $this->readUntil(PHP_EOL, $timer->getRemaining()); if (null !== $line) { @@ -165,7 +159,7 @@ static function (): void { * @throws Exception\RuntimeException If an error occurred during the operation. * @throws Exception\TimeoutException If $timeout is reached before being able to read from the handle. */ - public function readUntil(string $suffix, ?Duration $timeout = null): ?string + public function readUntil(string $suffix, null|Duration $timeout = null): null|string { $buf = $this->buffer; $idx = strpos($buf, $suffix); @@ -175,22 +169,19 @@ public function readUntil(string $suffix, ?Duration $timeout = null): ?string return substr($buf, 0, $idx); } - $timer = new Async\OptionalIncrementalTimeout( - $timeout, - static function () use ($suffix): void { - // @codeCoverageIgnoreStart - throw new Exception\TimeoutException(Str\format( - "Reached timeout before encountering the suffix (\"%s\").", - $suffix, - )); - // @codeCoverageIgnoreEnd - }, - ); + $timer = new Async\OptionalIncrementalTimeout($timeout, static function () use ($suffix): void { + // @codeCoverageIgnoreStart + throw new Exception\TimeoutException(Str\format( + "Reached timeout before encountering the suffix (\"%s\").", + $suffix, + )); + // @codeCoverageIgnoreEnd + }); do { // + 1 as it would have been matched in the previous iteration if it // fully fit in the chunk - $offset = strlen($buf) - $suffix_len + 1; + $offset = (strlen($buf) - $suffix_len) + 1; $offset = $offset > 0 ? $offset : 0; $chunk = $this->handle->read(null, $timer->getRemaining()); if ($chunk === '') { @@ -209,7 +200,7 @@ static function () use ($suffix): void { /** * {@inheritDoc} */ - public function read(?int $max_bytes = null, ?Duration $timeout = null): string + public function read(null|int $max_bytes = null, null|Duration $timeout = null): string { if ($this->eof) { return ''; @@ -227,7 +218,7 @@ public function read(?int $max_bytes = null, ?Duration $timeout = null): string /** * {@inheritDoc} */ - public function tryRead(?int $max_bytes = null): string + public function tryRead(null|int $max_bytes = null): string { if ($this->eof) { return ''; @@ -263,7 +254,7 @@ public function getHandle(): ReadHandleInterface * @throws Exception\RuntimeException If an error occurred during the operation. * @throws Exception\TimeoutException If $timeout is reached before being able to read from the handle. */ - private function fillBuffer(?int $desired_bytes, ?Duration $timeout): void + private function fillBuffer(null|int $desired_bytes, null|Duration $timeout): void { $this->buffer .= $chunk = $this->handle->read($desired_bytes, $timeout); if ($chunk === '') { diff --git a/src/Psl/IO/SeekReadStreamHandle.php b/src/Psl/IO/SeekReadStreamHandle.php index bc0a0392..290a33de 100644 --- a/src/Psl/IO/SeekReadStreamHandle.php +++ b/src/Psl/IO/SeekReadStreamHandle.php @@ -35,7 +35,7 @@ public function reachedEndOfDataSource(): bool /** * {@inheritDoc} */ - public function tryRead(?int $max_bytes = null): string + public function tryRead(null|int $max_bytes = null): string { return $this->handle->tryRead($max_bytes); } @@ -43,7 +43,7 @@ public function tryRead(?int $max_bytes = null): string /** * {@inheritDoc} */ - public function read(?int $max_bytes = null, ?Duration $timeout = null): string + public function read(null|int $max_bytes = null, null|Duration $timeout = null): string { return $this->handle->read($max_bytes, $timeout); } diff --git a/src/Psl/IO/SeekReadStreamHandleInterface.php b/src/Psl/IO/SeekReadStreamHandleInterface.php index 310df8da..821a1908 100644 --- a/src/Psl/IO/SeekReadStreamHandleInterface.php +++ b/src/Psl/IO/SeekReadStreamHandleInterface.php @@ -6,6 +6,9 @@ use Psl\IO; -interface SeekReadStreamHandleInterface extends IO\SeekReadHandleInterface, ReadStreamHandleInterface, SeekStreamHandleInterface +interface SeekReadStreamHandleInterface extends + IO\SeekReadHandleInterface, + ReadStreamHandleInterface, + SeekStreamHandleInterface { } diff --git a/src/Psl/IO/SeekReadWriteStreamHandle.php b/src/Psl/IO/SeekReadWriteStreamHandle.php index 80b35fcc..1628974f 100644 --- a/src/Psl/IO/SeekReadWriteStreamHandle.php +++ b/src/Psl/IO/SeekReadWriteStreamHandle.php @@ -36,7 +36,7 @@ public function reachedEndOfDataSource(): bool /** * {@inheritDoc} */ - public function tryRead(?int $max_bytes = null): string + public function tryRead(null|int $max_bytes = null): string { return $this->handle->tryRead($max_bytes); } @@ -44,7 +44,7 @@ public function tryRead(?int $max_bytes = null): string /** * {@inheritDoc} */ - public function read(?int $max_bytes = null, ?Duration $timeout = null): string + public function read(null|int $max_bytes = null, null|Duration $timeout = null): string { return $this->handle->read($max_bytes, $timeout); } @@ -60,7 +60,7 @@ public function tryWrite(string $bytes): int /** * {@inheritDoc} */ - public function write(string $bytes, ?Duration $timeout = null): int + public function write(string $bytes, null|Duration $timeout = null): int { return $this->handle->write($bytes, $timeout); } diff --git a/src/Psl/IO/SeekWriteStreamHandle.php b/src/Psl/IO/SeekWriteStreamHandle.php index aaa6bb7e..bf79a923 100644 --- a/src/Psl/IO/SeekWriteStreamHandle.php +++ b/src/Psl/IO/SeekWriteStreamHandle.php @@ -35,7 +35,7 @@ public function tryWrite(string $bytes): int /** * {@inheritDoc} */ - public function write(string $bytes, ?Duration $timeout = null): int + public function write(string $bytes, null|Duration $timeout = null): int { return $this->handle->write($bytes, $timeout); } diff --git a/src/Psl/IO/SeekWriteStreamHandleInterface.php b/src/Psl/IO/SeekWriteStreamHandleInterface.php index 38632a96..b0a1c7b0 100644 --- a/src/Psl/IO/SeekWriteStreamHandleInterface.php +++ b/src/Psl/IO/SeekWriteStreamHandleInterface.php @@ -6,6 +6,9 @@ use Psl\IO; -interface SeekWriteStreamHandleInterface extends IO\SeekWriteHandleInterface, SeekStreamHandleInterface, WriteStreamHandleInterface +interface SeekWriteStreamHandleInterface extends + IO\SeekWriteHandleInterface, + SeekStreamHandleInterface, + WriteStreamHandleInterface { } diff --git a/src/Psl/IO/WriteHandleConvenienceMethodsTrait.php b/src/Psl/IO/WriteHandleConvenienceMethodsTrait.php index fd851c66..3cdca60e 100644 --- a/src/Psl/IO/WriteHandleConvenienceMethodsTrait.php +++ b/src/Psl/IO/WriteHandleConvenienceMethodsTrait.php @@ -31,7 +31,7 @@ trait WriteHandleConvenienceMethodsTrait * @throws Exception\RuntimeException If an error occurred during the operation. * @throws Exception\TimeoutException If reached timeout before completing the operation. */ - public function writeAll(string $bytes, ?Duration $timeout = null): void + public function writeAll(string $bytes, null|Duration $timeout = null): void { if ($bytes === '') { return; @@ -43,23 +43,17 @@ public function writeAll(string $bytes, ?Duration $timeout = null): void */ $written = new Psl\Ref(0); - $timer = new Psl\Async\OptionalIncrementalTimeout( - $timeout, - static function () use ($written): void { - // @codeCoverageIgnoreStart - throw new Exception\TimeoutException(Str\format( - "Reached timeout before %s data could be written.", - ($written->value === 0) ? 'any' : 'all', - )); - // @codeCoverageIgnoreEnd - }, - ); + $timer = new Psl\Async\OptionalIncrementalTimeout($timeout, static function () use ($written): void { + // @codeCoverageIgnoreStart + throw new Exception\TimeoutException(Str\format( + 'Reached timeout before %s data could be written.', + $written->value === 0 ? 'any' : 'all', + )); + // @codeCoverageIgnoreEnd + }); do { - $written->value = $this->write( - $bytes, - $timer->getRemaining(), - ); + $written->value = $this->write($bytes, $timer->getRemaining()); $bytes = substr($bytes, $written->value); } while ($written->value !== 0 && $bytes !== ''); @@ -67,7 +61,7 @@ static function () use ($written): void { if ($bytes !== '') { // @codeCoverageIgnoreStart throw new Exception\RuntimeException(Str\format( - "asked to write %d bytes, but only able to write %d bytes", + 'asked to write %d bytes, but only able to write %d bytes', $original_size, $original_size - strlen($bytes), )); diff --git a/src/Psl/IO/WriteHandleInterface.php b/src/Psl/IO/WriteHandleInterface.php index 406c1f92..ddad5d4c 100644 --- a/src/Psl/IO/WriteHandleInterface.php +++ b/src/Psl/IO/WriteHandleInterface.php @@ -36,7 +36,7 @@ public function tryWrite(string $bytes): int; * * @return int<0, max> the number of bytes written, which may be less than the length of input string. */ - public function write(string $bytes, ?Duration $timeout = null): int; + public function write(string $bytes, null|Duration $timeout = null): int; /** * Write all of the requested data. @@ -53,5 +53,5 @@ public function write(string $bytes, ?Duration $timeout = null): int; * @throws Exception\RuntimeException If an error occurred during the operation. * @throws Exception\TimeoutException If reached timeout before completing the operation. */ - public function writeAll(string $bytes, ?Duration $timeout = null): void; + public function writeAll(string $bytes, null|Duration $timeout = null): void; } diff --git a/src/Psl/IO/WriteStreamHandle.php b/src/Psl/IO/WriteStreamHandle.php index bf746997..bba2fef1 100644 --- a/src/Psl/IO/WriteStreamHandle.php +++ b/src/Psl/IO/WriteStreamHandle.php @@ -35,7 +35,7 @@ public function tryWrite(string $bytes): int /** * {@inheritDoc} */ - public function write(string $bytes, ?Duration $timeout = null): int + public function write(string $bytes, null|Duration $timeout = null): int { return $this->handle->write($bytes, $timeout); } diff --git a/src/Psl/IO/error_handle.php b/src/Psl/IO/error_handle.php index d8d9c6af..c984749c 100644 --- a/src/Psl/IO/error_handle.php +++ b/src/Psl/IO/error_handle.php @@ -17,7 +17,7 @@ * * @codeCoverageIgnore */ -function error_handle(): ?CloseWriteStreamHandleInterface +function error_handle(): null|CloseWriteStreamHandleInterface { /** @var WeakMap|null $cache */ static $cache = null; @@ -32,10 +32,8 @@ function error_handle(): ?CloseWriteStreamHandleInterface } $handle = null; - if (PHP_SAPI === "cli") { - $handle = new CloseWriteStreamHandle( - Internal\open_resource('php://stderr', 'wb') - ); + if (PHP_SAPI === 'cli') { + $handle = new CloseWriteStreamHandle(Internal\open_resource('php://stderr', 'wb')); } $cache->offsetSet($key, $handle); diff --git a/src/Psl/IO/input_handle.php b/src/Psl/IO/input_handle.php index 83150e43..fef1e5b4 100644 --- a/src/Psl/IO/input_handle.php +++ b/src/Psl/IO/input_handle.php @@ -31,14 +31,10 @@ function input_handle(): CloseReadStreamHandleInterface return $cache->offsetGet($key); } - if (PHP_SAPI === "cli") { - $handle = new CloseReadStreamHandle( - Internal\open_resource('php://stdin', 'rb') - ); + if (PHP_SAPI === 'cli') { + $handle = new CloseReadStreamHandle(Internal\open_resource('php://stdin', 'rb')); } else { - $handle = new CloseReadStreamHandle( - Internal\open_resource('php://input', 'rb') - ); + $handle = new CloseReadStreamHandle(Internal\open_resource('php://input', 'rb')); } $cache->offsetSet($key, $handle); diff --git a/src/Psl/IO/output_handle.php b/src/Psl/IO/output_handle.php index 4d2d6e4c..60201a99 100644 --- a/src/Psl/IO/output_handle.php +++ b/src/Psl/IO/output_handle.php @@ -31,14 +31,10 @@ function output_handle(): CloseWriteStreamHandleInterface return $cache->offsetGet($key); } - if (PHP_SAPI === "cli") { - $handle = new CloseWriteStreamHandle( - Internal\open_resource('php://stdout', 'wb') - ); + if (PHP_SAPI === 'cli') { + $handle = new CloseWriteStreamHandle(Internal\open_resource('php://stdout', 'wb')); } else { - $handle = new CloseWriteStreamHandle( - Internal\open_resource('php://output', 'wb') - ); + $handle = new CloseWriteStreamHandle(Internal\open_resource('php://output', 'wb')); } $cache->offsetSet($key, $handle); diff --git a/src/Psl/IO/streaming.php b/src/Psl/IO/streaming.php index 463d3c2d..6cb64148 100644 --- a/src/Psl/IO/streaming.php +++ b/src/Psl/IO/streaming.php @@ -38,7 +38,7 @@ * * @return Generator */ -function streaming(iterable $handles, ?Duration $timeout = null): Generator +function streaming(iterable $handles, null|Duration $timeout = null): Generator { /** * @psalm-suppress UnnecessaryVarAnnotation @@ -56,10 +56,15 @@ function streaming(iterable $handles, ?Duration $timeout = null): Generator throw new Exception\AlreadyClosedException(Str\format('Handle "%s" is already closed.', (string) $index)); } - $watchers->value[$index] = EventLoop::onReadable($stream, static function (string $watcher) use ($index, $handle, $sender, $watchers): void { + $watchers->value[$index] = EventLoop::onReadable($stream, static function (string $watcher) use ( + $index, + $handle, + $sender, + $watchers, + ): void { try { $result = Result\wrap($handle->tryRead(...)); - if ($result->isFailed() || ($result->isSucceeded() && $result->getResult() === '')) { + if ($result->isFailed() || $result->isSucceeded() && $result->getResult() === '') { EventLoop::cancel($watcher); unset($watchers->value[$index]); } @@ -80,7 +85,9 @@ function streaming(iterable $handles, ?Duration $timeout = null): Generator $timeout_watcher = EventLoop::delay($timeout, static function () use ($sender): void { /** @var Result\ResultInterface $failure */ $failure = new Result\Failure( - new Exception\TimeoutException('Reached timeout before being able to read all the handles until the end.') + new Exception\TimeoutException( + 'Reached timeout before being able to read all the handles until the end.', + ), ); $sender->send([null, $failure]); diff --git a/src/Psl/Internal/Loader.php b/src/Psl/Internal/Loader.php index e843124b..56893f2b 100644 --- a/src/Psl/Internal/Loader.php +++ b/src/Psl/Internal/Loader.php @@ -554,7 +554,8 @@ final class Loader 'Psl\\DateTime\\Internal\\default_timezone' => 'Psl/DateTime/Internal/default_timezone.php', 'Psl\\DateTime\\Internal\\system_time' => 'Psl/DateTime/Internal/system_time.php', 'Psl\\DateTime\\Internal\\high_resolution_time' => 'Psl/DateTime/Internal/high_resolution_time.php', - 'Psl\\DateTime\\Internal\\create_intl_calendar_from_date_time' => 'Psl/DateTime/Internal/create_intl_calendar_from_date_time.php', + 'Psl\\DateTime\\Internal\\create_intl_calendar_from_date_time' => + 'Psl/DateTime/Internal/create_intl_calendar_from_date_time.php', 'Psl\\DateTime\\Internal\\create_intl_date_formatter' => 'Psl/DateTime/Internal/create_intl_date_formatter.php', 'Psl\\DateTime\\Internal\\parse' => 'Psl/DateTime/Internal/parse.php', 'Psl\\DateTime\\Internal\\format_rfc3339' => 'Psl/DateTime/Internal/format_rfc3339.php', @@ -572,7 +573,8 @@ final class Loader 'Psl\\Collection\\MutableCollectionInterface' => 'Psl/Collection/MutableCollectionInterface.php', 'Psl\\Collection\\MutableIndexAccessInterface' => 'Psl/Collection/MutableIndexAccessInterface.php', 'Psl\\Collection\\AccessibleCollectionInterface' => 'Psl/Collection/AccessibleCollectionInterface.php', - 'Psl\\Collection\\MutableAccessibleCollectionInterface' => 'Psl/Collection/MutableAccessibleCollectionInterface.php', + 'Psl\\Collection\\MutableAccessibleCollectionInterface' => + 'Psl/Collection/MutableAccessibleCollectionInterface.php', 'Psl\\Collection\\VectorInterface' => 'Psl/Collection/VectorInterface.php', 'Psl\\Collection\\MutableVectorInterface' => 'Psl/Collection/MutableVectorInterface.php', 'Psl\\Collection\\MapInterface' => 'Psl/Collection/MapInterface.php', @@ -682,7 +684,8 @@ final class Loader 'Psl\\Encoding\\Base64\\Internal\\Base64' => 'Psl/Encoding/Base64/Internal/Base64.php', 'Psl\\Encoding\\Base64\\Internal\\Base64UrlSafe' => 'Psl/Encoding/Base64/Internal/Base64UrlSafe.php', 'Psl\\Encoding\\Base64\\Internal\\Base64DotSlash' => 'Psl/Encoding/Base64/Internal/Base64DotSlash.php', - 'Psl\\Encoding\\Base64\\Internal\\Base64DotSlashOrdered' => 'Psl/Encoding/Base64/Internal/Base64DotSlashOrdered.php', + 'Psl\\Encoding\\Base64\\Internal\\Base64DotSlashOrdered' => + 'Psl/Encoding/Base64/Internal/Base64DotSlashOrdered.php', 'Psl\\Exception\\OverflowException' => 'Psl/Exception/OverflowException.php', 'Psl\\Exception\\InvalidArgumentException' => 'Psl/Exception/InvalidArgumentException.php', 'Psl\\Exception\\UnexpectedValueException' => 'Psl/Exception/UnexpectedValueException.php', @@ -752,7 +755,8 @@ final class Loader 'Psl\\Hash\\Context' => 'Psl/Hash/Context.php', 'Psl\\Encoding\\Exception\\IncorrectPaddingException' => 'Psl/Encoding/Exception/IncorrectPaddingException.php', 'Psl\\Encoding\\Exception\\RangeException' => 'Psl/Encoding/Exception/RangeException.php', - 'Psl\\SecureRandom\\Exception\\InsufficientEntropyException' => 'Psl/SecureRandom/Exception/InsufficientEntropyException.php', + 'Psl\\SecureRandom\\Exception\\InsufficientEntropyException' => + 'Psl/SecureRandom/Exception/InsufficientEntropyException.php', 'Psl\\Regex\\Exception\\InvalidPatternException' => 'Psl/Regex/Exception/InvalidPatternException.php', 'Psl\\Regex\\Exception\\RuntimeException' => 'Psl/Regex/Exception/RuntimeException.php', 'Psl\\Shell\\Exception\\FailedExecutionException' => 'Psl/Shell/Exception/FailedExecutionException.php', @@ -763,11 +767,13 @@ final class Loader 'Psl\\Math\\Exception\\ArithmeticException' => 'Psl/Math/Exception/ArithmeticException.php', 'Psl\\Math\\Exception\\DivisionByZeroException' => 'Psl/Math/Exception/DivisionByZeroException.php', 'Psl\\Filesystem\\Exception\\RuntimeException' => 'Psl/Filesystem/Exception/RuntimeException.php', - 'Psl\\Filesystem\\Exception\\InvalidArgumentException' => 'Psl/Filesystem/Exception/InvalidArgumentException.php', + 'Psl\\Filesystem\\Exception\\InvalidArgumentException' => + 'Psl/Filesystem/Exception/InvalidArgumentException.php', 'Psl\\Filesystem\\Exception\\NotFileException' => 'Psl/Filesystem/Exception/NotFileException.php', 'Psl\\Filesystem\\Exception\\NotDirectoryException' => 'Psl/Filesystem/Exception/NotDirectoryException.php', 'Psl\\Filesystem\\Exception\\NotFoundException' => 'Psl/Filesystem/Exception/NotFoundException.php', - 'Psl\\Filesystem\\Exception\\NotSymbolicLinkException' => 'Psl/Filesystem/Exception/NotSymbolicLinkException.php', + 'Psl\\Filesystem\\Exception\\NotSymbolicLinkException' => + 'Psl/Filesystem/Exception/NotSymbolicLinkException.php', 'Psl\\Filesystem\\Exception\\NotReadableException' => 'Psl/Filesystem/Exception/NotReadableException.php', 'Psl\\IO\\Exception\\AlreadyClosedException' => 'Psl/IO/Exception/AlreadyClosedException.php', 'Psl\\IO\\Exception\\RuntimeException' => 'Psl/IO/Exception/RuntimeException.php', @@ -777,7 +783,8 @@ final class Loader 'Psl\\IO\\MemoryHandle' => 'Psl/IO/MemoryHandle.php', 'Psl\\Fun\\Internal\\LazyEvaluator' => 'Psl/Fun/Internal/LazyEvaluator.php', 'Psl\\RandomSequence\\MersenneTwisterSequence' => 'Psl/RandomSequence/MersenneTwisterSequence.php', - 'Psl\\RandomSequence\\MersenneTwisterPHPVariantSequence' => 'Psl/RandomSequence/MersenneTwisterPHPVariantSequence.php', + 'Psl\\RandomSequence\\MersenneTwisterPHPVariantSequence' => + 'Psl/RandomSequence/MersenneTwisterPHPVariantSequence.php', 'Psl\\RandomSequence\\SecureSequence' => 'Psl/RandomSequence/SecureSequence.php', 'Psl\\Async\\Exception\\CompositeException' => 'Psl/Async/Exception/CompositeException.php', 'Psl\\Async\\Exception\\RuntimeException' => 'Psl/Async/Exception/RuntimeException.php', @@ -858,7 +865,8 @@ final class Loader 'Psl\\Math\\Exception\\OverflowException' => 'Psl/Math/Exception/OverflowException.php', 'Psl\\Math\\Exception\\InvalidArgumentException' => 'Psl/Math/Exception/InvalidArgumentException.php', 'Psl\\Iter\\Exception\\InvalidArgumentException' => 'Psl/Iter/Exception/InvalidArgumentException.php', - 'Psl\\PseudoRandom\\Exception\\InvalidArgumentException' => 'Psl/PseudoRandom/Exception/InvalidArgumentException.php', + 'Psl\\PseudoRandom\\Exception\\InvalidArgumentException' => + 'Psl/PseudoRandom/Exception/InvalidArgumentException.php', 'Psl\\Async\\Exception\\InvalidArgumentException' => 'Psl/Async/Exception/InvalidArgumentException.php', 'Psl\\Option\\Exception\\NoneException' => 'Psl/Option/Exception/NoneException.php', 'Psl\\Option\\Option' => 'Psl/Option/Option.php', @@ -946,7 +954,7 @@ private static function load(string $file): void private static function autoload(Closure $callback): void { - $loader = static function (string $classname): ?bool { + $loader = static function (string $classname): null|bool { $file = self::lookupClassish($classname); if (!$file) { return null; @@ -1028,7 +1036,7 @@ private static function loadEnums(): void } } - private static function lookupClassish(string $classname): ?string + private static function lookupClassish(string $classname): null|string { static $lookup; if (!$lookup) { diff --git a/src/Psl/Internal/box.php b/src/Psl/Internal/box.php index 0f8098e6..3e74558c 100644 --- a/src/Psl/Internal/box.php +++ b/src/Psl/Internal/box.php @@ -33,7 +33,7 @@ function box(Closure $fun): array $last_message = Str\after( Str\lowercase($last_message), // how i feel toward PHP error handling: - '): ' + '): ', ); } diff --git a/src/Psl/Internal/constants.php b/src/Psl/Internal/constants.php index bbcbd65d..c4c3ef9e 100644 --- a/src/Psl/Internal/constants.php +++ b/src/Psl/Internal/constants.php @@ -4,9 +4,9 @@ namespace Psl\Internal; -const ALPHABET_BASE64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; +const ALPHABET_BASE64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; const ALPHABET_BASE64_URL = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; -const CASE_FOLD = [ +const CASE_FOLD = [ 'µ' => 'μ', 'ſ' => 's', "\xCD\x85" => 'ι', diff --git a/src/Psl/Iter/Iterator.php b/src/Psl/Iter/Iterator.php index 266a6a41..287adc7a 100644 --- a/src/Psl/Iter/Iterator.php +++ b/src/Psl/Iter/Iterator.php @@ -22,7 +22,7 @@ final class Iterator implements Countable, SeekableIterator /** * @var null|Generator */ - private ?Generator $generator; + private null|Generator $generator; /** * @var array @@ -44,7 +44,7 @@ final class Iterator implements Countable, SeekableIterator * * @var null|int<0, max> */ - private ?int $count = null; + private null|int $count = null; /** * @param Generator $generator @@ -203,7 +203,9 @@ public function next(): void { $this->position++; - if (array_key_exists($this->position, $this->entries) || null === $this->generator || !$this->generator->valid()) { + if ( + array_key_exists($this->position, $this->entries) || null === $this->generator || !$this->generator->valid() + ) { return; } diff --git a/src/Psl/Iter/random.php b/src/Psl/Iter/random.php index e168c0f9..eb222152 100644 --- a/src/Psl/Iter/random.php +++ b/src/Psl/Iter/random.php @@ -27,7 +27,7 @@ function random(iterable $iterable) if ([] === $values) { throw new Exception\InvalidArgumentException('Expected a non-empty iterable.'); } - + $size = namespace\count($values); if (1 === $size) { diff --git a/src/Psl/Json/decode.php b/src/Psl/Json/decode.php index 416678af..76c55e3c 100644 --- a/src/Psl/Json/decode.php +++ b/src/Psl/Json/decode.php @@ -23,12 +23,7 @@ function decode(string $json, bool $assoc = true): mixed { try { /** @var mixed $value */ - $value = json_decode( - $json, - $assoc, - 512, - JSON_BIGINT_AS_STRING | JSON_THROW_ON_ERROR, - ); + $value = json_decode($json, $assoc, 512, JSON_BIGINT_AS_STRING | JSON_THROW_ON_ERROR); } catch (JsonException $e) { throw new Exception\DecodeException(Str\format('%s.', $e->getMessage()), $e->getCode(), $e); } diff --git a/src/Psl/Json/encode.php b/src/Psl/Json/encode.php index 0ce7609b..a705d684 100644 --- a/src/Psl/Json/encode.php +++ b/src/Psl/Json/encode.php @@ -26,10 +26,7 @@ */ function encode(mixed $value, bool $pretty = false, int $flags = 0): string { - $flags |= JSON_UNESCAPED_UNICODE - | JSON_UNESCAPED_SLASHES - | JSON_PRESERVE_ZERO_FRACTION - | JSON_THROW_ON_ERROR; + $flags |= JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRESERVE_ZERO_FRACTION | JSON_THROW_ON_ERROR; if ($pretty) { $flags |= JSON_PRETTY_PRINT; diff --git a/src/Psl/Locale/Locale.php b/src/Psl/Locale/Locale.php index bd72fa38..af969be0 100644 --- a/src/Psl/Locale/Locale.php +++ b/src/Psl/Locale/Locale.php @@ -12,788 +12,788 @@ */ enum Locale: string { - case Afrikaans = "af"; - case AfrikaansNamibia = "af_NA"; - case AfrikaansSouthAfrica = "af_ZA"; - case Aghem = "agq"; - case AghemCameroon = "agq_CM"; - case Akan = "ak"; - case AkanGhana = "ak_GH"; - case Amharic = "am"; - case AmharicEthiopia = "am_ET"; - case Arabic = "ar"; - case ArabicUnitedArabEmirates = "ar_AE"; - case ArabicBahrain = "ar_BH"; - case ArabicDjibouti = "ar_DJ"; - case ArabicAlgeria = "ar_DZ"; - case ArabicEgypt = "ar_EG"; - case ArabicWesternSahara = "ar_EH"; - case ArabicEritrea = "ar_ER"; - case ArabicIsrael = "ar_IL"; - case ArabicIraq = "ar_IQ"; - case ArabicJordan = "ar_JO"; - case ArabicComoros = "ar_KM"; - case ArabicKuwait = "ar_KW"; - case ArabicLebanon = "ar_LB"; - case ArabicLibya = "ar_LY"; - case ArabicMorocco = "ar_MA"; - case ArabicMauritania = "ar_MR"; - case ArabicOman = "ar_OM"; - case ArabicPalestine = "ar_PS"; - case ArabicQatar = "ar_QA"; - case ArabicSaudiArabia = "ar_SA"; - case ArabicSudan = "ar_SD"; - case ArabicSomalia = "ar_SO"; - case ArabicSouthSudan = "ar_SS"; - case ArabicSyria = "ar_SY"; - case ArabicChad = "ar_TD"; - case ArabicTunisia = "ar_TN"; - case ArabicYemen = "ar_YE"; - case Assamese = "as"; - case AssameseIndia = "as_IN"; - case Asu = "asa"; - case AsuTanzania = "asa_TZ"; - case Asturian = "ast"; - case AsturianSpain = "ast_ES"; - case Azerbaijani = "az"; - case AzerbaijaniCyrillic = "az_Cyrl"; - case AzerbaijaniLatin = "az_Latn"; - case Basaa = "bas"; - case BasaaCameroon = "bas_CM"; - case Belarusian = "be"; - case BelarusianBelarus = "be_BY"; - case Bemba = "bem"; - case BembaZambia = "bem_ZM"; - case Bena = "bez"; - case BenaTanzania = "bez_TZ"; - case Bulgarian = "bg"; - case BulgarianBulgaria = "bg_BG"; - case Haryanvi = "bgc"; - case HaryanviIndia = "bgc_IN"; - case Bhojpuri = "bho"; - case BhojpuriIndia = "bho_IN"; - case Anii = "blo"; - case AniiBenin = "blo_BJ"; - case Bambara = "bm"; - case BambaraMali = "bm_ML"; - case Bangla = "bn"; - case BanglaBangladesh = "bn_BD"; - case BanglaIndia = "bn_IN"; - case Tibetan = "bo"; - case TibetanChina = "bo_CN"; - case TibetanIndia = "bo_IN"; - case Breton = "br"; - case BretonFrance = "br_FR"; - case Bodo = "brx"; - case BodoIndia = "brx_IN"; - case Bosnian = "bs"; - case BosnianCyrillic = "bs_Cyrl"; - case BosnianLatin = "bs_Latn"; - case Catalan = "ca"; - case CatalanAndorra = "ca_AD"; - case CatalanSpain = "ca_ES"; - case CatalanFrance = "ca_FR"; - case CatalanItaly = "ca_IT"; - case Chakma = "ccp"; - case ChakmaBangladesh = "ccp_BD"; - case ChakmaIndia = "ccp_IN"; - case Chechen = "ce"; - case ChechenRussia = "ce_RU"; - case Cebuano = "ceb"; - case CebuanoPhilippines = "ceb_PH"; - case Chiga = "cgg"; - case ChigaUganda = "cgg_UG"; - case Cherokee = "chr"; - case CherokeeUnitedStates = "chr_US"; - case CentralKurdish = "ckb"; - case CentralKurdishIraq = "ckb_IQ"; - case CentralKurdishIran = "ckb_IR"; - case Czech = "cs"; - case CzechCzechia = "cs_CZ"; - case SwampyCree = "csw"; - case SwampyCreeCanada = "csw_CA"; - case Chuvash = "cv"; - case ChuvashRussia = "cv_RU"; - case Welsh = "cy"; - case WelshUnitedKingdom = "cy_GB"; - case Danish = "da"; - case DanishDenmark = "da_DK"; - case DanishGreenland = "da_GL"; - case Taita = "dav"; - case TaitaKenya = "dav_KE"; - case German = "de"; - case GermanAustria = "de_AT"; - case GermanBelgium = "de_BE"; - case GermanSwitzerland = "de_CH"; - case GermanGermany = "de_DE"; - case GermanItaly = "de_IT"; - case GermanLiechtenstein = "de_LI"; - case GermanLuxembourg = "de_LU"; - case Zarma = "dje"; - case ZarmaNiger = "dje_NE"; - case Dogri = "doi"; - case DogriIndia = "doi_IN"; - case LowerSorbian = "dsb"; - case LowerSorbianGermany = "dsb_DE"; - case Duala = "dua"; - case DualaCameroon = "dua_CM"; - case JolaFonyi = "dyo"; - case JolaFonyiSenegal = "dyo_SN"; - case Dzongkha = "dz"; - case DzongkhaBhutan = "dz_BT"; - case Embu = "ebu"; - case EmbuKenya = "ebu_KE"; - case Ewe = "ee"; - case EweGhana = "ee_GH"; - case EweTogo = "ee_TG"; - case Greek = "el"; - case GreekCyprus = "el_CY"; - case GreekGreece = "el_GR"; - case English = "en"; - case EnglishUnitedArabEmirates = "en_AE"; - case EnglishAntiguaBarbuda = "en_AG"; - case EnglishAnguilla = "en_AI"; - case EnglishAmericanSamoa = "en_AS"; - case EnglishAustria = "en_AT"; - case EnglishAustralia = "en_AU"; - case EnglishBarbados = "en_BB"; - case EnglishBelgium = "en_BE"; - case EnglishBurundi = "en_BI"; - case EnglishBermuda = "en_BM"; - case EnglishBahamas = "en_BS"; - case EnglishBotswana = "en_BW"; - case EnglishBelize = "en_BZ"; - case EnglishCanada = "en_CA"; - case EnglishCocosKeelingIslands = "en_CC"; - case EnglishSwitzerland = "en_CH"; - case EnglishCookIslands = "en_CK"; - case EnglishCameroon = "en_CM"; - case EnglishChristmasIsland = "en_CX"; - case EnglishCyprus = "en_CY"; - case EnglishGermany = "en_DE"; - case EnglishDiegoGarcia = "en_DG"; - case EnglishDenmark = "en_DK"; - case EnglishDominica = "en_DM"; - case EnglishEritrea = "en_ER"; - case EnglishFinland = "en_FI"; - case EnglishFiji = "en_FJ"; - case EnglishFalklandIslands = "en_FK"; - case EnglishMicronesia = "en_FM"; - case EnglishUnitedKingdom = "en_GB"; - case EnglishGrenada = "en_GD"; - case EnglishGuernsey = "en_GG"; - case EnglishGhana = "en_GH"; - case EnglishGibraltar = "en_GI"; - case EnglishGambia = "en_GM"; - case EnglishGuam = "en_GU"; - case EnglishGuyana = "en_GY"; - case EnglishHongKongSARChina = "en_HK"; - case EnglishIndonesia = "en_ID"; - case EnglishIreland = "en_IE"; - case EnglishIsrael = "en_IL"; - case EnglishIsleofMan = "en_IM"; - case EnglishIndia = "en_IN"; - case EnglishBritishIndianOceanTerritory = "en_IO"; - case EnglishJersey = "en_JE"; - case EnglishJamaica = "en_JM"; - case EnglishKenya = "en_KE"; - case EnglishKiribati = "en_KI"; - case EnglishStKittsNevis = "en_KN"; - case EnglishCaymanIslands = "en_KY"; - case EnglishStLucia = "en_LC"; - case EnglishLiberia = "en_LR"; - case EnglishLesotho = "en_LS"; - case EnglishMadagascar = "en_MG"; - case EnglishMarshallIslands = "en_MH"; - case EnglishMacaoSARChina = "en_MO"; - case EnglishNorthernMarianaIslands = "en_MP"; - case EnglishMontserrat = "en_MS"; - case EnglishMalta = "en_MT"; - case EnglishMauritius = "en_MU"; - case EnglishMaldives = "en_MV"; - case EnglishMalawi = "en_MW"; - case EnglishMalaysia = "en_MY"; - case EnglishNamibia = "en_NA"; - case EnglishNorfolkIsland = "en_NF"; - case EnglishNigeria = "en_NG"; - case EnglishNetherlands = "en_NL"; - case EnglishNauru = "en_NR"; - case EnglishNiue = "en_NU"; - case EnglishNewZealand = "en_NZ"; - case EnglishPapuaNewGuinea = "en_PG"; - case EnglishPhilippines = "en_PH"; - case EnglishPakistan = "en_PK"; - case EnglishPitcairnIslands = "en_PN"; - case EnglishPuertoRico = "en_PR"; - case EnglishPalau = "en_PW"; - case EnglishRwanda = "en_RW"; - case EnglishSolomonIslands = "en_SB"; - case EnglishSeychelles = "en_SC"; - case EnglishSudan = "en_SD"; - case EnglishSweden = "en_SE"; - case EnglishSingapore = "en_SG"; - case EnglishStHelena = "en_SH"; - case EnglishSlovenia = "en_SI"; - case EnglishSierraLeone = "en_SL"; - case EnglishSouthSudan = "en_SS"; - case EnglishSintMaarten = "en_SX"; - case EnglishEswatini = "en_SZ"; - case EnglishTurksCaicosIslands = "en_TC"; - case EnglishTokelau = "en_TK"; - case EnglishTonga = "en_TO"; - case EnglishTrinidadTobago = "en_TT"; - case EnglishTuvalu = "en_TV"; - case EnglishTanzania = "en_TZ"; - case EnglishUganda = "en_UG"; - case EnglishUSOutlyingIslands = "en_UM"; - case EnglishUnitedStates = "en_US"; - case EnglishStVincentGrenadines = "en_VC"; - case EnglishBritishVirginIslands = "en_VG"; - case EnglishUSVirginIslands = "en_VI"; - case EnglishVanuatu = "en_VU"; - case EnglishSamoa = "en_WS"; - case EnglishSouthAfrica = "en_ZA"; - case EnglishZambia = "en_ZM"; - case EnglishZimbabwe = "en_ZW"; - case Esperanto = "eo"; - case Spanish = "es"; - case SpanishArgentina = "es_AR"; - case SpanishBolivia = "es_BO"; - case SpanishBrazil = "es_BR"; - case SpanishBelize = "es_BZ"; - case SpanishChile = "es_CL"; - case SpanishColombia = "es_CO"; - case SpanishCostaRica = "es_CR"; - case SpanishCuba = "es_CU"; - case SpanishDominicanRepublic = "es_DO"; - case SpanishCeutaMelilla = "es_EA"; - case SpanishEcuador = "es_EC"; - case SpanishSpain = "es_ES"; - case SpanishEquatorialGuinea = "es_GQ"; - case SpanishGuatemala = "es_GT"; - case SpanishHonduras = "es_HN"; - case SpanishCanaryIslands = "es_IC"; - case SpanishMexico = "es_MX"; - case SpanishNicaragua = "es_NI"; - case SpanishPanama = "es_PA"; - case SpanishPeru = "es_PE"; - case SpanishPhilippines = "es_PH"; - case SpanishPuertoRico = "es_PR"; - case SpanishParaguay = "es_PY"; - case SpanishElSalvador = "es_SV"; - case SpanishUnitedStates = "es_US"; - case SpanishUruguay = "es_UY"; - case SpanishVenezuela = "es_VE"; - case Estonian = "et"; - case EstonianEstonia = "et_EE"; - case Basque = "eu"; - case BasqueSpain = "eu_ES"; - case Ewondo = "ewo"; - case EwondoCameroon = "ewo_CM"; - case Persian = "fa"; - case PersianAfghanistan = "fa_AF"; - case PersianIran = "fa_IR"; - case Fula = "ff"; - case FulaAdlam = "ff_Adlm"; - case FulaLatin = "ff_Latn"; - case FulaLatinNigeria = "ff_Latn_NG"; - case FulaLatinSenegal = "ff_Latn_SG"; - case Finnish = "fi"; - case FinnishFinland = "fi_FI"; - case Filipino = "fil"; - case FilipinoPhilippines = "fil_PH"; - case Faroese = "fo"; - case FaroeseDenmark = "fo_DK"; - case FaroeseFaroeIslands = "fo_FO"; - case French = "fr"; - case FrenchBelgium = "fr_BE"; - case FrenchBurkinaFaso = "fr_BF"; - case FrenchBurundi = "fr_BI"; - case FrenchBenin = "fr_BJ"; - case FrenchStBarthelemy = "fr_BL"; - case FrenchCanada = "fr_CA"; - case FrenchCongoKinshasa = "fr_CD"; - case FrenchCentralAfricanRepublic = "fr_CF"; - case FrenchCongoBrazzaville = "fr_CG"; - case FrenchSwitzerland = "fr_CH"; - case FrenchCotedIvoire = "fr_CI"; - case FrenchCameroon = "fr_CM"; - case FrenchDjibouti = "fr_DJ"; - case FrenchAlgeria = "fr_DZ"; - case FrenchFrance = "fr_FR"; - case FrenchGabon = "fr_GA"; - case FrenchFrenchGuiana = "fr_GF"; - case FrenchGuinea = "fr_GN"; - case FrenchGuadeloupe = "fr_GP"; - case FrenchEquatorialGuinea = "fr_GQ"; - case FrenchHaiti = "fr_HT"; - case FrenchComoros = "fr_KM"; - case FrenchLuxembourg = "fr_LU"; - case FrenchMorocco = "fr_MA"; - case FrenchMonaco = "fr_MC"; - case FrenchStMartin = "fr_MF"; - case FrenchMadagascar = "fr_MG"; - case FrenchMali = "fr_ML"; - case FrenchMartinique = "fr_MQ"; - case FrenchMauritania = "fr_MR"; - case FrenchMauritius = "fr_MU"; - case FrenchNewCaledonia = "fr_NC"; - case FrenchNiger = "fr_NE"; - case FrenchFrenchPolynesia = "fr_PF"; - case FrenchStPierreMiquelon = "fr_PM"; - case FrenchReunion = "fr_RE"; - case FrenchRwanda = "fr_RW"; - case FrenchSeychelles = "fr_SC"; - case FrenchSenegal = "fr_SN"; - case FrenchSyria = "fr_SY"; - case FrenchChad = "fr_TD"; - case FrenchTogo = "fr_TG"; - case FrenchTunisia = "fr_TN"; - case FrenchVanuatu = "fr_VU"; - case FrenchWallisFutuna = "fr_WF"; - case FrenchMayotte = "fr_YT"; - case Friulian = "fur"; - case FriulianItaly = "fur_IT"; - case WesternFrisian = "fy"; - case WesternFrisianNetherlands = "fy_NL"; - case Irish = "ga"; - case IrishUnitedKingdom = "ga_GB"; - case IrishIreland = "ga_IE"; - case ScottishGaelic = "gd"; - case ScottishGaelicUnitedKingdom = "gd_GB"; - case Galician = "gl"; - case GalicianSpain = "gl_ES"; - case SwissGerman = "gsw"; - case SwissGermanSwitzerland = "gsw_CH"; - case SwissGermanFrance = "gsw_FR"; - case SwissGermanLiechtenstein = "gsw_LI"; - case Gujarati = "gu"; - case GujaratiIndia = "gu_IN"; - case Gusii = "guz"; - case GusiiKenya = "guz_KE"; - case Manx = "gv"; - case ManxIsleofMan = "gv_IM"; - case Hausa = "ha"; - case HausaGhana = "ha_GH"; - case HausaNiger = "ha_NE"; - case HausaNigeria = "ha_NG"; - case Hawaiian = "haw"; - case HawaiianUnitedStates = "haw_US"; - case Hebrew = "he"; - case HebrewIsrael = "he_IL"; - case Hindi = "hi"; - case HindiIndia = "hi_IN"; - case HindiLatin = "hi_Latn"; - case Croatian = "hr"; - case CroatianBosniaHerzegovina = "hr_BA"; - case CroatianCroatia = "hr_HR"; - case UpperSorbian = "hsb"; - case UpperSorbianGermany = "hsb_DE"; - case Hungarian = "hu"; - case HungarianHungary = "hu_HU"; - case Armenian = "hy"; - case ArmenianArmenia = "hy_AM"; - case Interlingua = "ia"; - case Indonesian = "id"; - case IndonesianIndonesia = "id_ID"; - case Interlingue = "ie"; - case InterlingueEstonia = "ie_EE"; - case Igbo = "ig"; - case IgboNigeria = "ig_NG"; - case SichuanYi = "ii"; - case SichuanYiChina = "ii_CN"; - case Icelandic = "is"; - case IcelandicIceland = "is_IS"; - case Italian = "it"; - case ItalianSwitzerland = "it_CH"; - case ItalianItaly = "it_IT"; - case ItalianSanMarino = "it_SM"; - case ItalianVaticanCity = "it_VA"; - case Japanese = "ja"; - case JapaneseJapan = "ja_JP"; - case Ngomba = "jgo"; - case NgombaCameroon = "jgo_CM"; - case Machame = "jmc"; - case MachameTanzania = "jmc_TZ"; - case Javanese = "jv"; - case JavaneseIndonesia = "jv_ID"; - case Georgian = "ka"; - case GeorgianGeorgia = "ka_GE"; - case Kabyle = "kab"; - case KabyleAlgeria = "kab_DZ"; - case Kamba = "kam"; - case KambaKenya = "kam_KE"; - case Makonde = "kde"; - case MakondeTanzania = "kde_TZ"; - case Kabuverdianu = "kea"; - case KabuverdianuCapeVerde = "kea_CV"; - case Kaingang = "kgp"; - case KaingangBrazil = "kgp_BR"; - case KoyraChiini = "khq"; - case KoyraChiiniMali = "khq_ML"; - case Kikuyu = "ki"; - case KikuyuKenya = "ki_KE"; - case Kazakh = "kk"; - case KazakhKazakhstan = "kk_KZ"; - case Kako = "kkj"; - case KakoCameroon = "kkj_CM"; - case Kalaallisut = "kl"; - case KalaallisutGreenland = "kl_GL"; - case Kalenjin = "kln"; - case KalenjinKenya = "kln_KE"; - case Khmer = "km"; - case KhmerCambodia = "km_KH"; - case Kannada = "kn"; - case KannadaIndia = "kn_IN"; - case Korean = "ko"; - case KoreanChina = "ko_CN"; - case KoreanNorthKorea = "ko_KP"; - case KoreanSouthKorea = "ko_KR"; - case Konkani = "kok"; - case KonkaniIndia = "kok_IN"; - case Kashmiri = "ks"; - case KashmiriArabic = "ks_Arab"; - case KashmiriDevanagari = "ks_Deva"; - case Shambala = "ksb"; - case ShambalaTanzania = "ksb_TZ"; - case Bafia = "ksf"; - case BafiaCameroon = "ksf_CM"; - case Colognian = "ksh"; - case ColognianGermany = "ksh_DE"; - case Kurdish = "ku"; - case KurdishTurkiye = "ku_TR"; - case Cornish = "kw"; - case CornishUnitedKingdom = "kw_GB"; - case Kuvi = "kxv"; - case KuviDevanagari = "kxv_Deva"; - case KuviLatin = "kxv_Latn"; - case KuviOdia = "kxv_Orya"; - case KuviTelugu = "kxv_Telu"; - case Kyrgyz = "ky"; - case KyrgyzKyrgyzstan = "ky_KG"; - case Langi = "lag"; - case LangiTanzania = "lag_TZ"; - case Luxembourgish = "lb"; - case LuxembourgishLuxembourg = "lb_LU"; - case Ganda = "lg"; - case GandaUganda = "lg_UG"; - case Ligurian = "lij"; - case LigurianItaly = "lij_IT"; - case Lakota = "lkt"; - case LakotaUnitedStates = "lkt_US"; - case Lombard = "lmo"; - case LombardItaly = "lmo_IT"; - case Lingala = "ln"; - case LingalaAngola = "ln_AO"; - case LingalaCongoKinshasa = "ln_CD"; - case LingalaCentralAfricanRepublic = "ln_CF"; - case LingalaCongoBrazzaville = "ln_CG"; - case Lao = "lo"; - case LaoLaos = "lo_LA"; - case NorthernLuri = "lrc"; - case NorthernLuriIraq = "lrc_IQ"; - case NorthernLuriIran = "lrc_IR"; - case Lithuanian = "lt"; - case LithuanianLithuania = "lt_LT"; - case LubaKatanga = "lu"; - case LubaKatangaCongoKinshasa = "lu_CD"; - case Luo = "luo"; - case LuoKenya = "luo_KE"; - case Luyia = "luy"; - case LuyiaKenya = "luy_KE"; - case Latvian = "lv"; - case LatvianLatvia = "lv_LV"; - case Maithili = "mai"; - case MaithiliIndia = "mai_IN"; - case Masai = "mas"; - case MasaiKenya = "mas_KE"; - case MasaiTanzania = "mas_TZ"; - case Meru = "mer"; - case MeruKenya = "mer_KE"; - case Morisyen = "mfe"; - case MorisyenMauritius = "mfe_MU"; - case Malagasy = "mg"; - case MalagasyMadagascar = "mg_MG"; - case MakhuwaMeetto = "mgh"; - case MakhuwaMeettoMozambique = "mgh_MZ"; - case Meta = "mgo"; - case MetaCameroon = "mgo_CM"; - case Mori = "mi"; - case MoriNewZealand = "mi_NZ"; - case Macedonian = "mk"; - case MacedonianNorthMacedonia = "mk_MK"; - case Malayalam = "ml"; - case MalayalamIndia = "ml_IN"; - case Mongolian = "mn"; - case MongolianMongolia = "mn_MN"; - case Manipuri = "mni"; - case ManipuriBangla = "mni_Beng"; - case Marathi = "mr"; - case MarathiIndia = "mr_IN"; - case Malay = "ms"; - case MalayBrunei = "ms_BN"; - case MalayIndonesia = "ms_ID"; - case MalayMalaysia = "ms_MY"; - case MalaySingapore = "ms_SG"; - case Maltese = "mt"; - case MalteseMalta = "mt_MT"; - case Mundang = "mua"; - case MundangCameroon = "mua_CM"; - case Burmese = "my"; - case BurmeseMyanmarBurma = "my_MM"; - case Mazanderani = "mzn"; - case MazanderaniIran = "mzn_IR"; - case Nama = "naq"; - case NamaNamibia = "naq_NA"; - case NorwegianBokml = "nb"; - case NorwegianBokmlNorway = "nb_NO"; - case NorwegianBokmlSvalbardJanMayen = "nb_SJ"; - case NorthNdebele = "nd"; - case NorthNdebeleZimbabwe = "nd_ZW"; - case LowGerman = "nds"; - case LowGermanGermany = "nds_DE"; - case LowGermanNetherlands = "nds_NL"; - case Nepali = "ne"; - case NepaliIndia = "ne_IN"; - case NepaliNepal = "ne_NP"; - case Dutch = "nl"; - case DutchAruba = "nl_AW"; - case DutchBelgium = "nl_BE"; - case DutchCaribbeanNetherlands = "nl_BQ"; - case DutchCuracao = "nl_CW"; - case DutchNetherlands = "nl_NL"; - case DutchSuriname = "nl_SR"; - case DutchSintMaarten = "nl_SX"; - case Kwasio = "nmg"; - case KwasioCameroon = "nmg_CM"; - case NorwegianNynorsk = "nn"; - case NorwegianNynorskNorway = "nn_NO"; - case Ngiemboon = "nnh"; - case NgiemboonCameroon = "nnh_CM"; - case Norwegian = "no"; - case NKo = "nqo"; - case NKoGuinea = "nqo_GN"; - case Nuer = "nus"; - case NuerSouthSudan = "nus_SS"; - case Nyankole = "nyn"; - case NyankoleUganda = "nyn_UG"; - case Occitan = "oc"; - case OccitanSpain = "oc_ES"; - case OccitanFrance = "oc_FR"; - case Oromo = "om"; - case OromoEthiopia = "om_ET"; - case OromoKenya = "om_KE"; - case Odia = "or"; - case OdiaIndia = "or_IN"; - case Ossetic = "os"; - case OsseticGeorgia = "os_GE"; - case OsseticRussia = "os_RU"; - case Punjabi = "pa"; - case PunjabiArabic = "pa_Arab"; - case PunjabiGurmukhi = "pa_Guru"; - case NigerianPidgin = "pcm"; - case NigerianPidginNigeria = "pcm_NG"; - case Polish = "pl"; - case PolishPoland = "pl_PL"; - case Prussian = "prg"; - case PrussianPoland = "prg_PL"; - case Pashto = "ps"; - case PashtoAfghanistan = "ps_AF"; - case PashtoPakistan = "ps_PK"; - case Portuguese = "pt"; - case PortugueseAngola = "pt_AO"; - case PortugueseBrazil = "pt_BR"; - case PortugueseSwitzerland = "pt_CH"; - case PortugueseCapeVerde = "pt_CV"; - case PortugueseEquatorialGuinea = "pt_GQ"; - case PortugueseGuineaBissau = "pt_GW"; - case PortugueseLuxembourg = "pt_LU"; - case PortugueseMacaoSARChina = "pt_MO"; - case PortugueseMozambique = "pt_MZ"; - case PortuguesePortugal = "pt_PT"; - case PortugueseSaoTomePrincipe = "pt_ST"; - case PortugueseTimorLeste = "pt_TL"; - case Quechua = "qu"; - case QuechuaBolivia = "qu_BO"; - case QuechuaEcuador = "qu_EC"; - case QuechuaPeru = "qu_PE"; - case Rajasthani = "raj"; - case RajasthaniIndia = "raj_IN"; - case Romansh = "rm"; - case RomanshSwitzerland = "rm_CH"; - case Rundi = "rn"; - case RundiBurundi = "rn_BI"; - case Romanian = "ro"; - case RomanianMoldova = "ro_MD"; - case RomanianRomania = "ro_RO"; - case Rombo = "rof"; - case RomboTanzania = "rof_TZ"; - case Russian = "ru"; - case RussianBelarus = "ru_BY"; - case RussianKyrgyzstan = "ru_KG"; - case RussianKazakhstan = "ru_KZ"; - case RussianMoldova = "ru_MD"; - case RussianRussia = "ru_RU"; - case RussianUkraine = "ru_UA"; - case Kinyarwanda = "rw"; - case KinyarwandaRwanda = "rw_RW"; - case Rwa = "rwk"; - case RwaTanzania = "rwk_TZ"; - case Sanskrit = "sa"; - case SanskritIndia = "sa_IN"; - case Yakut = "sah"; - case YakutRussia = "sah_RU"; - case Samburu = "saq"; - case SamburuKenya = "saq_KE"; - case Santali = "sat"; - case SantaliOlChiki = "sat_Olck"; - case Sangu = "sbp"; - case SanguTanzania = "sbp_TZ"; - case Sardinian = "sc"; - case SardinianItaly = "sc_IT"; - case Sindhi = "sd"; - case SindhiArabic = "sd_Arab"; - case SindhiDevanagari = "sd_Deva"; - case NorthernSami = "se"; - case NorthernSamiFinland = "se_FI"; - case NorthernSamiNorway = "se_NO"; - case NorthernSamiSweden = "se_SE"; - case Sena = "seh"; - case SenaMozambique = "seh_MZ"; - case KoyraboroSenni = "ses"; - case KoyraboroSenniMali = "ses_ML"; - case Sango = "sg"; - case SangoCentralAfricanRepublic = "sg_CF"; - case Tachelhit = "shi"; - case TachelhitLatin = "shi_Latn"; - case TachelhitTifinagh = "shi_Tfng"; - case Sinhala = "si"; - case SinhalaSriLanka = "si_LK"; - case Slovak = "sk"; - case SlovakSlovakia = "sk_SK"; - case Slovenian = "sl"; - case SlovenianSlovenia = "sl_SI"; - case InariSami = "smn"; - case InariSamiFinland = "smn_FI"; - case Shona = "sn"; - case ShonaZimbabwe = "sn_ZW"; - case Somali = "so"; - case SomaliDjibouti = "so_DJ"; - case SomaliEthiopia = "so_ET"; - case SomaliKenya = "so_KE"; - case SomaliSomalia = "so_SO"; - case Albanian = "sq"; - case AlbanianAlbania = "sq_AL"; - case AlbanianNorthMacedonia = "sq_MK"; - case AlbanianKosovo = "sq_XK"; - case Serbian = "sr"; - case SerbianSerbia = "sr_RS"; - case SerbianCyrillic = "sr_Cyrl"; - case SerbianCyrillicSerbia = "sr_Cyrl_RS"; - case SerbianLatin = "sr_Latn"; - case SerbianLatinSerbia = "sr_Latn_RS"; - case Sundanese = "su"; - case SundaneseLatin = "su_Latn"; - case Swedish = "sv"; - case SwedishAlandIslands = "sv_AX"; - case SwedishFinland = "sv_FI"; - case SwedishSweden = "sv_SE"; - case Swahili = "sw"; - case SwahiliCongoKinshasa = "sw_CD"; - case SwahiliKenya = "sw_KE"; - case SwahiliTanzania = "sw_TZ"; - case SwahiliUganda = "sw_UG"; - case Syriac = "syr"; - case SyriacIraq = "syr_IQ"; - case SyriacSyria = "syr_SY"; - case Silesian = "szl"; - case SilesianPoland = "szl_PL"; - case Tamil = "ta"; - case TamilIndia = "ta_IN"; - case TamilSriLanka = "ta_LK"; - case TamilMalaysia = "ta_MY"; - case TamilSingapore = "ta_SG"; - case Telugu = "te"; - case TeluguIndia = "te_IN"; - case Teso = "teo"; - case TesoKenya = "teo_KE"; - case TesoUganda = "teo_UG"; - case Tajik = "tg"; - case TajikTajikistan = "tg_TJ"; - case Thai = "th"; - case ThaiThailand = "th_TH"; - case Tigrinya = "ti"; - case TigrinyaEritrea = "ti_ER"; - case TigrinyaEthiopia = "ti_ET"; - case Turkmen = "tk"; - case TurkmenTurkmenistan = "tk_TM"; - case Tongan = "to"; - case TonganTonga = "to_TO"; - case TokiPona = "tok"; - case Turkish = "tr"; - case TurkishCyprus = "tr_CY"; - case TurkishTurkiye = "tr_TR"; - case Tatar = "tt"; - case TatarRussia = "tt_RU"; - case Tasawaq = "twq"; - case TasawaqNiger = "twq_NE"; - case CentralAtlasTamazight = "tzm"; - case CentralAtlasTamazightMorocco = "tzm_MA"; - case Uyghur = "ug"; - case UyghurChina = "ug_CN"; - case Ukrainian = "uk"; - case UkrainianUkraine = "uk_UA"; - case Urdu = "ur"; - case UrduIndia = "ur_IN"; - case UrduPakistan = "ur_PK"; - case Uzbek = "uz"; - case UzbekArabic = "uz_Arab"; - case UzbekCyrillic = "uz_Cyrl"; - case UzbekLatin = "uz_Latn"; - case Vai = "vai"; - case VaiLatin = "vai_Latn"; - case VaiVai = "vai_Vaii"; - case Venetian = "vec"; - case VenetianItaly = "vec_IT"; - case Vietnamese = "vi"; - case VietnameseVietnam = "vi_VN"; - case Makhuwa = "vmw"; - case MakhuwaMozambique = "vmw_MZ"; - case Vunjo = "vun"; - case VunjoTanzania = "vun_TZ"; - case Walser = "wae"; - case WalserSwitzerland = "wae_CH"; - case Wolof = "wo"; - case WolofSenegal = "wo_SN"; - case Xhosa = "xh"; - case XhosaSouthAfrica = "xh_ZA"; - case Kangri = "xnr"; - case KangriIndia = "xnr_IN"; - case Soga = "xog"; - case SogaUganda = "xog_UG"; - case Yangben = "yav"; - case YangbenCameroon = "yav_CM"; - case Yiddish = "yi"; - case YiddishUkraine = "yi_UA"; - case Yoruba = "yo"; - case YorubaBenin = "yo_BJ"; - case YorubaNigeria = "yo_NG"; - case Nheengatu = "yrl"; - case NheengatuBrazil = "yrl_BR"; - case NheengatuColombia = "yrl_CO"; - case NheengatuVenezuela = "yrl_VE"; - case Cantonese = "yue"; - case CantoneseSimplified = "yue_Hans"; - case CantoneseTraditional = "yue_Hant"; - case Zhuang = "za"; - case ZhuangChina = "za_CN"; - case StandardMoroccanTamazight = "zgh"; - case StandardMoroccanTamazightMorocco = "zgh_MA"; - case Chinese = "zh"; - case ChineseSimplified = "zh_Hans"; - case ChineseTraditional = "zh_Hant"; - case Zulu = "zu"; - case ZuluSouthAfrica = "zu_ZA"; + case Afrikaans = 'af'; + case AfrikaansNamibia = 'af_NA'; + case AfrikaansSouthAfrica = 'af_ZA'; + case Aghem = 'agq'; + case AghemCameroon = 'agq_CM'; + case Akan = 'ak'; + case AkanGhana = 'ak_GH'; + case Amharic = 'am'; + case AmharicEthiopia = 'am_ET'; + case Arabic = 'ar'; + case ArabicUnitedArabEmirates = 'ar_AE'; + case ArabicBahrain = 'ar_BH'; + case ArabicDjibouti = 'ar_DJ'; + case ArabicAlgeria = 'ar_DZ'; + case ArabicEgypt = 'ar_EG'; + case ArabicWesternSahara = 'ar_EH'; + case ArabicEritrea = 'ar_ER'; + case ArabicIsrael = 'ar_IL'; + case ArabicIraq = 'ar_IQ'; + case ArabicJordan = 'ar_JO'; + case ArabicComoros = 'ar_KM'; + case ArabicKuwait = 'ar_KW'; + case ArabicLebanon = 'ar_LB'; + case ArabicLibya = 'ar_LY'; + case ArabicMorocco = 'ar_MA'; + case ArabicMauritania = 'ar_MR'; + case ArabicOman = 'ar_OM'; + case ArabicPalestine = 'ar_PS'; + case ArabicQatar = 'ar_QA'; + case ArabicSaudiArabia = 'ar_SA'; + case ArabicSudan = 'ar_SD'; + case ArabicSomalia = 'ar_SO'; + case ArabicSouthSudan = 'ar_SS'; + case ArabicSyria = 'ar_SY'; + case ArabicChad = 'ar_TD'; + case ArabicTunisia = 'ar_TN'; + case ArabicYemen = 'ar_YE'; + case Assamese = 'as'; + case AssameseIndia = 'as_IN'; + case Asu = 'asa'; + case AsuTanzania = 'asa_TZ'; + case Asturian = 'ast'; + case AsturianSpain = 'ast_ES'; + case Azerbaijani = 'az'; + case AzerbaijaniCyrillic = 'az_Cyrl'; + case AzerbaijaniLatin = 'az_Latn'; + case Basaa = 'bas'; + case BasaaCameroon = 'bas_CM'; + case Belarusian = 'be'; + case BelarusianBelarus = 'be_BY'; + case Bemba = 'bem'; + case BembaZambia = 'bem_ZM'; + case Bena = 'bez'; + case BenaTanzania = 'bez_TZ'; + case Bulgarian = 'bg'; + case BulgarianBulgaria = 'bg_BG'; + case Haryanvi = 'bgc'; + case HaryanviIndia = 'bgc_IN'; + case Bhojpuri = 'bho'; + case BhojpuriIndia = 'bho_IN'; + case Anii = 'blo'; + case AniiBenin = 'blo_BJ'; + case Bambara = 'bm'; + case BambaraMali = 'bm_ML'; + case Bangla = 'bn'; + case BanglaBangladesh = 'bn_BD'; + case BanglaIndia = 'bn_IN'; + case Tibetan = 'bo'; + case TibetanChina = 'bo_CN'; + case TibetanIndia = 'bo_IN'; + case Breton = 'br'; + case BretonFrance = 'br_FR'; + case Bodo = 'brx'; + case BodoIndia = 'brx_IN'; + case Bosnian = 'bs'; + case BosnianCyrillic = 'bs_Cyrl'; + case BosnianLatin = 'bs_Latn'; + case Catalan = 'ca'; + case CatalanAndorra = 'ca_AD'; + case CatalanSpain = 'ca_ES'; + case CatalanFrance = 'ca_FR'; + case CatalanItaly = 'ca_IT'; + case Chakma = 'ccp'; + case ChakmaBangladesh = 'ccp_BD'; + case ChakmaIndia = 'ccp_IN'; + case Chechen = 'ce'; + case ChechenRussia = 'ce_RU'; + case Cebuano = 'ceb'; + case CebuanoPhilippines = 'ceb_PH'; + case Chiga = 'cgg'; + case ChigaUganda = 'cgg_UG'; + case Cherokee = 'chr'; + case CherokeeUnitedStates = 'chr_US'; + case CentralKurdish = 'ckb'; + case CentralKurdishIraq = 'ckb_IQ'; + case CentralKurdishIran = 'ckb_IR'; + case Czech = 'cs'; + case CzechCzechia = 'cs_CZ'; + case SwampyCree = 'csw'; + case SwampyCreeCanada = 'csw_CA'; + case Chuvash = 'cv'; + case ChuvashRussia = 'cv_RU'; + case Welsh = 'cy'; + case WelshUnitedKingdom = 'cy_GB'; + case Danish = 'da'; + case DanishDenmark = 'da_DK'; + case DanishGreenland = 'da_GL'; + case Taita = 'dav'; + case TaitaKenya = 'dav_KE'; + case German = 'de'; + case GermanAustria = 'de_AT'; + case GermanBelgium = 'de_BE'; + case GermanSwitzerland = 'de_CH'; + case GermanGermany = 'de_DE'; + case GermanItaly = 'de_IT'; + case GermanLiechtenstein = 'de_LI'; + case GermanLuxembourg = 'de_LU'; + case Zarma = 'dje'; + case ZarmaNiger = 'dje_NE'; + case Dogri = 'doi'; + case DogriIndia = 'doi_IN'; + case LowerSorbian = 'dsb'; + case LowerSorbianGermany = 'dsb_DE'; + case Duala = 'dua'; + case DualaCameroon = 'dua_CM'; + case JolaFonyi = 'dyo'; + case JolaFonyiSenegal = 'dyo_SN'; + case Dzongkha = 'dz'; + case DzongkhaBhutan = 'dz_BT'; + case Embu = 'ebu'; + case EmbuKenya = 'ebu_KE'; + case Ewe = 'ee'; + case EweGhana = 'ee_GH'; + case EweTogo = 'ee_TG'; + case Greek = 'el'; + case GreekCyprus = 'el_CY'; + case GreekGreece = 'el_GR'; + case English = 'en'; + case EnglishUnitedArabEmirates = 'en_AE'; + case EnglishAntiguaBarbuda = 'en_AG'; + case EnglishAnguilla = 'en_AI'; + case EnglishAmericanSamoa = 'en_AS'; + case EnglishAustria = 'en_AT'; + case EnglishAustralia = 'en_AU'; + case EnglishBarbados = 'en_BB'; + case EnglishBelgium = 'en_BE'; + case EnglishBurundi = 'en_BI'; + case EnglishBermuda = 'en_BM'; + case EnglishBahamas = 'en_BS'; + case EnglishBotswana = 'en_BW'; + case EnglishBelize = 'en_BZ'; + case EnglishCanada = 'en_CA'; + case EnglishCocosKeelingIslands = 'en_CC'; + case EnglishSwitzerland = 'en_CH'; + case EnglishCookIslands = 'en_CK'; + case EnglishCameroon = 'en_CM'; + case EnglishChristmasIsland = 'en_CX'; + case EnglishCyprus = 'en_CY'; + case EnglishGermany = 'en_DE'; + case EnglishDiegoGarcia = 'en_DG'; + case EnglishDenmark = 'en_DK'; + case EnglishDominica = 'en_DM'; + case EnglishEritrea = 'en_ER'; + case EnglishFinland = 'en_FI'; + case EnglishFiji = 'en_FJ'; + case EnglishFalklandIslands = 'en_FK'; + case EnglishMicronesia = 'en_FM'; + case EnglishUnitedKingdom = 'en_GB'; + case EnglishGrenada = 'en_GD'; + case EnglishGuernsey = 'en_GG'; + case EnglishGhana = 'en_GH'; + case EnglishGibraltar = 'en_GI'; + case EnglishGambia = 'en_GM'; + case EnglishGuam = 'en_GU'; + case EnglishGuyana = 'en_GY'; + case EnglishHongKongSARChina = 'en_HK'; + case EnglishIndonesia = 'en_ID'; + case EnglishIreland = 'en_IE'; + case EnglishIsrael = 'en_IL'; + case EnglishIsleofMan = 'en_IM'; + case EnglishIndia = 'en_IN'; + case EnglishBritishIndianOceanTerritory = 'en_IO'; + case EnglishJersey = 'en_JE'; + case EnglishJamaica = 'en_JM'; + case EnglishKenya = 'en_KE'; + case EnglishKiribati = 'en_KI'; + case EnglishStKittsNevis = 'en_KN'; + case EnglishCaymanIslands = 'en_KY'; + case EnglishStLucia = 'en_LC'; + case EnglishLiberia = 'en_LR'; + case EnglishLesotho = 'en_LS'; + case EnglishMadagascar = 'en_MG'; + case EnglishMarshallIslands = 'en_MH'; + case EnglishMacaoSARChina = 'en_MO'; + case EnglishNorthernMarianaIslands = 'en_MP'; + case EnglishMontserrat = 'en_MS'; + case EnglishMalta = 'en_MT'; + case EnglishMauritius = 'en_MU'; + case EnglishMaldives = 'en_MV'; + case EnglishMalawi = 'en_MW'; + case EnglishMalaysia = 'en_MY'; + case EnglishNamibia = 'en_NA'; + case EnglishNorfolkIsland = 'en_NF'; + case EnglishNigeria = 'en_NG'; + case EnglishNetherlands = 'en_NL'; + case EnglishNauru = 'en_NR'; + case EnglishNiue = 'en_NU'; + case EnglishNewZealand = 'en_NZ'; + case EnglishPapuaNewGuinea = 'en_PG'; + case EnglishPhilippines = 'en_PH'; + case EnglishPakistan = 'en_PK'; + case EnglishPitcairnIslands = 'en_PN'; + case EnglishPuertoRico = 'en_PR'; + case EnglishPalau = 'en_PW'; + case EnglishRwanda = 'en_RW'; + case EnglishSolomonIslands = 'en_SB'; + case EnglishSeychelles = 'en_SC'; + case EnglishSudan = 'en_SD'; + case EnglishSweden = 'en_SE'; + case EnglishSingapore = 'en_SG'; + case EnglishStHelena = 'en_SH'; + case EnglishSlovenia = 'en_SI'; + case EnglishSierraLeone = 'en_SL'; + case EnglishSouthSudan = 'en_SS'; + case EnglishSintMaarten = 'en_SX'; + case EnglishEswatini = 'en_SZ'; + case EnglishTurksCaicosIslands = 'en_TC'; + case EnglishTokelau = 'en_TK'; + case EnglishTonga = 'en_TO'; + case EnglishTrinidadTobago = 'en_TT'; + case EnglishTuvalu = 'en_TV'; + case EnglishTanzania = 'en_TZ'; + case EnglishUganda = 'en_UG'; + case EnglishUSOutlyingIslands = 'en_UM'; + case EnglishUnitedStates = 'en_US'; + case EnglishStVincentGrenadines = 'en_VC'; + case EnglishBritishVirginIslands = 'en_VG'; + case EnglishUSVirginIslands = 'en_VI'; + case EnglishVanuatu = 'en_VU'; + case EnglishSamoa = 'en_WS'; + case EnglishSouthAfrica = 'en_ZA'; + case EnglishZambia = 'en_ZM'; + case EnglishZimbabwe = 'en_ZW'; + case Esperanto = 'eo'; + case Spanish = 'es'; + case SpanishArgentina = 'es_AR'; + case SpanishBolivia = 'es_BO'; + case SpanishBrazil = 'es_BR'; + case SpanishBelize = 'es_BZ'; + case SpanishChile = 'es_CL'; + case SpanishColombia = 'es_CO'; + case SpanishCostaRica = 'es_CR'; + case SpanishCuba = 'es_CU'; + case SpanishDominicanRepublic = 'es_DO'; + case SpanishCeutaMelilla = 'es_EA'; + case SpanishEcuador = 'es_EC'; + case SpanishSpain = 'es_ES'; + case SpanishEquatorialGuinea = 'es_GQ'; + case SpanishGuatemala = 'es_GT'; + case SpanishHonduras = 'es_HN'; + case SpanishCanaryIslands = 'es_IC'; + case SpanishMexico = 'es_MX'; + case SpanishNicaragua = 'es_NI'; + case SpanishPanama = 'es_PA'; + case SpanishPeru = 'es_PE'; + case SpanishPhilippines = 'es_PH'; + case SpanishPuertoRico = 'es_PR'; + case SpanishParaguay = 'es_PY'; + case SpanishElSalvador = 'es_SV'; + case SpanishUnitedStates = 'es_US'; + case SpanishUruguay = 'es_UY'; + case SpanishVenezuela = 'es_VE'; + case Estonian = 'et'; + case EstonianEstonia = 'et_EE'; + case Basque = 'eu'; + case BasqueSpain = 'eu_ES'; + case Ewondo = 'ewo'; + case EwondoCameroon = 'ewo_CM'; + case Persian = 'fa'; + case PersianAfghanistan = 'fa_AF'; + case PersianIran = 'fa_IR'; + case Fula = 'ff'; + case FulaAdlam = 'ff_Adlm'; + case FulaLatin = 'ff_Latn'; + case FulaLatinNigeria = 'ff_Latn_NG'; + case FulaLatinSenegal = 'ff_Latn_SG'; + case Finnish = 'fi'; + case FinnishFinland = 'fi_FI'; + case Filipino = 'fil'; + case FilipinoPhilippines = 'fil_PH'; + case Faroese = 'fo'; + case FaroeseDenmark = 'fo_DK'; + case FaroeseFaroeIslands = 'fo_FO'; + case French = 'fr'; + case FrenchBelgium = 'fr_BE'; + case FrenchBurkinaFaso = 'fr_BF'; + case FrenchBurundi = 'fr_BI'; + case FrenchBenin = 'fr_BJ'; + case FrenchStBarthelemy = 'fr_BL'; + case FrenchCanada = 'fr_CA'; + case FrenchCongoKinshasa = 'fr_CD'; + case FrenchCentralAfricanRepublic = 'fr_CF'; + case FrenchCongoBrazzaville = 'fr_CG'; + case FrenchSwitzerland = 'fr_CH'; + case FrenchCotedIvoire = 'fr_CI'; + case FrenchCameroon = 'fr_CM'; + case FrenchDjibouti = 'fr_DJ'; + case FrenchAlgeria = 'fr_DZ'; + case FrenchFrance = 'fr_FR'; + case FrenchGabon = 'fr_GA'; + case FrenchFrenchGuiana = 'fr_GF'; + case FrenchGuinea = 'fr_GN'; + case FrenchGuadeloupe = 'fr_GP'; + case FrenchEquatorialGuinea = 'fr_GQ'; + case FrenchHaiti = 'fr_HT'; + case FrenchComoros = 'fr_KM'; + case FrenchLuxembourg = 'fr_LU'; + case FrenchMorocco = 'fr_MA'; + case FrenchMonaco = 'fr_MC'; + case FrenchStMartin = 'fr_MF'; + case FrenchMadagascar = 'fr_MG'; + case FrenchMali = 'fr_ML'; + case FrenchMartinique = 'fr_MQ'; + case FrenchMauritania = 'fr_MR'; + case FrenchMauritius = 'fr_MU'; + case FrenchNewCaledonia = 'fr_NC'; + case FrenchNiger = 'fr_NE'; + case FrenchFrenchPolynesia = 'fr_PF'; + case FrenchStPierreMiquelon = 'fr_PM'; + case FrenchReunion = 'fr_RE'; + case FrenchRwanda = 'fr_RW'; + case FrenchSeychelles = 'fr_SC'; + case FrenchSenegal = 'fr_SN'; + case FrenchSyria = 'fr_SY'; + case FrenchChad = 'fr_TD'; + case FrenchTogo = 'fr_TG'; + case FrenchTunisia = 'fr_TN'; + case FrenchVanuatu = 'fr_VU'; + case FrenchWallisFutuna = 'fr_WF'; + case FrenchMayotte = 'fr_YT'; + case Friulian = 'fur'; + case FriulianItaly = 'fur_IT'; + case WesternFrisian = 'fy'; + case WesternFrisianNetherlands = 'fy_NL'; + case Irish = 'ga'; + case IrishUnitedKingdom = 'ga_GB'; + case IrishIreland = 'ga_IE'; + case ScottishGaelic = 'gd'; + case ScottishGaelicUnitedKingdom = 'gd_GB'; + case Galician = 'gl'; + case GalicianSpain = 'gl_ES'; + case SwissGerman = 'gsw'; + case SwissGermanSwitzerland = 'gsw_CH'; + case SwissGermanFrance = 'gsw_FR'; + case SwissGermanLiechtenstein = 'gsw_LI'; + case Gujarati = 'gu'; + case GujaratiIndia = 'gu_IN'; + case Gusii = 'guz'; + case GusiiKenya = 'guz_KE'; + case Manx = 'gv'; + case ManxIsleofMan = 'gv_IM'; + case Hausa = 'ha'; + case HausaGhana = 'ha_GH'; + case HausaNiger = 'ha_NE'; + case HausaNigeria = 'ha_NG'; + case Hawaiian = 'haw'; + case HawaiianUnitedStates = 'haw_US'; + case Hebrew = 'he'; + case HebrewIsrael = 'he_IL'; + case Hindi = 'hi'; + case HindiIndia = 'hi_IN'; + case HindiLatin = 'hi_Latn'; + case Croatian = 'hr'; + case CroatianBosniaHerzegovina = 'hr_BA'; + case CroatianCroatia = 'hr_HR'; + case UpperSorbian = 'hsb'; + case UpperSorbianGermany = 'hsb_DE'; + case Hungarian = 'hu'; + case HungarianHungary = 'hu_HU'; + case Armenian = 'hy'; + case ArmenianArmenia = 'hy_AM'; + case Interlingua = 'ia'; + case Indonesian = 'id'; + case IndonesianIndonesia = 'id_ID'; + case Interlingue = 'ie'; + case InterlingueEstonia = 'ie_EE'; + case Igbo = 'ig'; + case IgboNigeria = 'ig_NG'; + case SichuanYi = 'ii'; + case SichuanYiChina = 'ii_CN'; + case Icelandic = 'is'; + case IcelandicIceland = 'is_IS'; + case Italian = 'it'; + case ItalianSwitzerland = 'it_CH'; + case ItalianItaly = 'it_IT'; + case ItalianSanMarino = 'it_SM'; + case ItalianVaticanCity = 'it_VA'; + case Japanese = 'ja'; + case JapaneseJapan = 'ja_JP'; + case Ngomba = 'jgo'; + case NgombaCameroon = 'jgo_CM'; + case Machame = 'jmc'; + case MachameTanzania = 'jmc_TZ'; + case Javanese = 'jv'; + case JavaneseIndonesia = 'jv_ID'; + case Georgian = 'ka'; + case GeorgianGeorgia = 'ka_GE'; + case Kabyle = 'kab'; + case KabyleAlgeria = 'kab_DZ'; + case Kamba = 'kam'; + case KambaKenya = 'kam_KE'; + case Makonde = 'kde'; + case MakondeTanzania = 'kde_TZ'; + case Kabuverdianu = 'kea'; + case KabuverdianuCapeVerde = 'kea_CV'; + case Kaingang = 'kgp'; + case KaingangBrazil = 'kgp_BR'; + case KoyraChiini = 'khq'; + case KoyraChiiniMali = 'khq_ML'; + case Kikuyu = 'ki'; + case KikuyuKenya = 'ki_KE'; + case Kazakh = 'kk'; + case KazakhKazakhstan = 'kk_KZ'; + case Kako = 'kkj'; + case KakoCameroon = 'kkj_CM'; + case Kalaallisut = 'kl'; + case KalaallisutGreenland = 'kl_GL'; + case Kalenjin = 'kln'; + case KalenjinKenya = 'kln_KE'; + case Khmer = 'km'; + case KhmerCambodia = 'km_KH'; + case Kannada = 'kn'; + case KannadaIndia = 'kn_IN'; + case Korean = 'ko'; + case KoreanChina = 'ko_CN'; + case KoreanNorthKorea = 'ko_KP'; + case KoreanSouthKorea = 'ko_KR'; + case Konkani = 'kok'; + case KonkaniIndia = 'kok_IN'; + case Kashmiri = 'ks'; + case KashmiriArabic = 'ks_Arab'; + case KashmiriDevanagari = 'ks_Deva'; + case Shambala = 'ksb'; + case ShambalaTanzania = 'ksb_TZ'; + case Bafia = 'ksf'; + case BafiaCameroon = 'ksf_CM'; + case Colognian = 'ksh'; + case ColognianGermany = 'ksh_DE'; + case Kurdish = 'ku'; + case KurdishTurkiye = 'ku_TR'; + case Cornish = 'kw'; + case CornishUnitedKingdom = 'kw_GB'; + case Kuvi = 'kxv'; + case KuviDevanagari = 'kxv_Deva'; + case KuviLatin = 'kxv_Latn'; + case KuviOdia = 'kxv_Orya'; + case KuviTelugu = 'kxv_Telu'; + case Kyrgyz = 'ky'; + case KyrgyzKyrgyzstan = 'ky_KG'; + case Langi = 'lag'; + case LangiTanzania = 'lag_TZ'; + case Luxembourgish = 'lb'; + case LuxembourgishLuxembourg = 'lb_LU'; + case Ganda = 'lg'; + case GandaUganda = 'lg_UG'; + case Ligurian = 'lij'; + case LigurianItaly = 'lij_IT'; + case Lakota = 'lkt'; + case LakotaUnitedStates = 'lkt_US'; + case Lombard = 'lmo'; + case LombardItaly = 'lmo_IT'; + case Lingala = 'ln'; + case LingalaAngola = 'ln_AO'; + case LingalaCongoKinshasa = 'ln_CD'; + case LingalaCentralAfricanRepublic = 'ln_CF'; + case LingalaCongoBrazzaville = 'ln_CG'; + case Lao = 'lo'; + case LaoLaos = 'lo_LA'; + case NorthernLuri = 'lrc'; + case NorthernLuriIraq = 'lrc_IQ'; + case NorthernLuriIran = 'lrc_IR'; + case Lithuanian = 'lt'; + case LithuanianLithuania = 'lt_LT'; + case LubaKatanga = 'lu'; + case LubaKatangaCongoKinshasa = 'lu_CD'; + case Luo = 'luo'; + case LuoKenya = 'luo_KE'; + case Luyia = 'luy'; + case LuyiaKenya = 'luy_KE'; + case Latvian = 'lv'; + case LatvianLatvia = 'lv_LV'; + case Maithili = 'mai'; + case MaithiliIndia = 'mai_IN'; + case Masai = 'mas'; + case MasaiKenya = 'mas_KE'; + case MasaiTanzania = 'mas_TZ'; + case Meru = 'mer'; + case MeruKenya = 'mer_KE'; + case Morisyen = 'mfe'; + case MorisyenMauritius = 'mfe_MU'; + case Malagasy = 'mg'; + case MalagasyMadagascar = 'mg_MG'; + case MakhuwaMeetto = 'mgh'; + case MakhuwaMeettoMozambique = 'mgh_MZ'; + case Meta = 'mgo'; + case MetaCameroon = 'mgo_CM'; + case Mori = 'mi'; + case MoriNewZealand = 'mi_NZ'; + case Macedonian = 'mk'; + case MacedonianNorthMacedonia = 'mk_MK'; + case Malayalam = 'ml'; + case MalayalamIndia = 'ml_IN'; + case Mongolian = 'mn'; + case MongolianMongolia = 'mn_MN'; + case Manipuri = 'mni'; + case ManipuriBangla = 'mni_Beng'; + case Marathi = 'mr'; + case MarathiIndia = 'mr_IN'; + case Malay = 'ms'; + case MalayBrunei = 'ms_BN'; + case MalayIndonesia = 'ms_ID'; + case MalayMalaysia = 'ms_MY'; + case MalaySingapore = 'ms_SG'; + case Maltese = 'mt'; + case MalteseMalta = 'mt_MT'; + case Mundang = 'mua'; + case MundangCameroon = 'mua_CM'; + case Burmese = 'my'; + case BurmeseMyanmarBurma = 'my_MM'; + case Mazanderani = 'mzn'; + case MazanderaniIran = 'mzn_IR'; + case Nama = 'naq'; + case NamaNamibia = 'naq_NA'; + case NorwegianBokml = 'nb'; + case NorwegianBokmlNorway = 'nb_NO'; + case NorwegianBokmlSvalbardJanMayen = 'nb_SJ'; + case NorthNdebele = 'nd'; + case NorthNdebeleZimbabwe = 'nd_ZW'; + case LowGerman = 'nds'; + case LowGermanGermany = 'nds_DE'; + case LowGermanNetherlands = 'nds_NL'; + case Nepali = 'ne'; + case NepaliIndia = 'ne_IN'; + case NepaliNepal = 'ne_NP'; + case Dutch = 'nl'; + case DutchAruba = 'nl_AW'; + case DutchBelgium = 'nl_BE'; + case DutchCaribbeanNetherlands = 'nl_BQ'; + case DutchCuracao = 'nl_CW'; + case DutchNetherlands = 'nl_NL'; + case DutchSuriname = 'nl_SR'; + case DutchSintMaarten = 'nl_SX'; + case Kwasio = 'nmg'; + case KwasioCameroon = 'nmg_CM'; + case NorwegianNynorsk = 'nn'; + case NorwegianNynorskNorway = 'nn_NO'; + case Ngiemboon = 'nnh'; + case NgiemboonCameroon = 'nnh_CM'; + case Norwegian = 'no'; + case NKo = 'nqo'; + case NKoGuinea = 'nqo_GN'; + case Nuer = 'nus'; + case NuerSouthSudan = 'nus_SS'; + case Nyankole = 'nyn'; + case NyankoleUganda = 'nyn_UG'; + case Occitan = 'oc'; + case OccitanSpain = 'oc_ES'; + case OccitanFrance = 'oc_FR'; + case Oromo = 'om'; + case OromoEthiopia = 'om_ET'; + case OromoKenya = 'om_KE'; + case Odia = 'or'; + case OdiaIndia = 'or_IN'; + case Ossetic = 'os'; + case OsseticGeorgia = 'os_GE'; + case OsseticRussia = 'os_RU'; + case Punjabi = 'pa'; + case PunjabiArabic = 'pa_Arab'; + case PunjabiGurmukhi = 'pa_Guru'; + case NigerianPidgin = 'pcm'; + case NigerianPidginNigeria = 'pcm_NG'; + case Polish = 'pl'; + case PolishPoland = 'pl_PL'; + case Prussian = 'prg'; + case PrussianPoland = 'prg_PL'; + case Pashto = 'ps'; + case PashtoAfghanistan = 'ps_AF'; + case PashtoPakistan = 'ps_PK'; + case Portuguese = 'pt'; + case PortugueseAngola = 'pt_AO'; + case PortugueseBrazil = 'pt_BR'; + case PortugueseSwitzerland = 'pt_CH'; + case PortugueseCapeVerde = 'pt_CV'; + case PortugueseEquatorialGuinea = 'pt_GQ'; + case PortugueseGuineaBissau = 'pt_GW'; + case PortugueseLuxembourg = 'pt_LU'; + case PortugueseMacaoSARChina = 'pt_MO'; + case PortugueseMozambique = 'pt_MZ'; + case PortuguesePortugal = 'pt_PT'; + case PortugueseSaoTomePrincipe = 'pt_ST'; + case PortugueseTimorLeste = 'pt_TL'; + case Quechua = 'qu'; + case QuechuaBolivia = 'qu_BO'; + case QuechuaEcuador = 'qu_EC'; + case QuechuaPeru = 'qu_PE'; + case Rajasthani = 'raj'; + case RajasthaniIndia = 'raj_IN'; + case Romansh = 'rm'; + case RomanshSwitzerland = 'rm_CH'; + case Rundi = 'rn'; + case RundiBurundi = 'rn_BI'; + case Romanian = 'ro'; + case RomanianMoldova = 'ro_MD'; + case RomanianRomania = 'ro_RO'; + case Rombo = 'rof'; + case RomboTanzania = 'rof_TZ'; + case Russian = 'ru'; + case RussianBelarus = 'ru_BY'; + case RussianKyrgyzstan = 'ru_KG'; + case RussianKazakhstan = 'ru_KZ'; + case RussianMoldova = 'ru_MD'; + case RussianRussia = 'ru_RU'; + case RussianUkraine = 'ru_UA'; + case Kinyarwanda = 'rw'; + case KinyarwandaRwanda = 'rw_RW'; + case Rwa = 'rwk'; + case RwaTanzania = 'rwk_TZ'; + case Sanskrit = 'sa'; + case SanskritIndia = 'sa_IN'; + case Yakut = 'sah'; + case YakutRussia = 'sah_RU'; + case Samburu = 'saq'; + case SamburuKenya = 'saq_KE'; + case Santali = 'sat'; + case SantaliOlChiki = 'sat_Olck'; + case Sangu = 'sbp'; + case SanguTanzania = 'sbp_TZ'; + case Sardinian = 'sc'; + case SardinianItaly = 'sc_IT'; + case Sindhi = 'sd'; + case SindhiArabic = 'sd_Arab'; + case SindhiDevanagari = 'sd_Deva'; + case NorthernSami = 'se'; + case NorthernSamiFinland = 'se_FI'; + case NorthernSamiNorway = 'se_NO'; + case NorthernSamiSweden = 'se_SE'; + case Sena = 'seh'; + case SenaMozambique = 'seh_MZ'; + case KoyraboroSenni = 'ses'; + case KoyraboroSenniMali = 'ses_ML'; + case Sango = 'sg'; + case SangoCentralAfricanRepublic = 'sg_CF'; + case Tachelhit = 'shi'; + case TachelhitLatin = 'shi_Latn'; + case TachelhitTifinagh = 'shi_Tfng'; + case Sinhala = 'si'; + case SinhalaSriLanka = 'si_LK'; + case Slovak = 'sk'; + case SlovakSlovakia = 'sk_SK'; + case Slovenian = 'sl'; + case SlovenianSlovenia = 'sl_SI'; + case InariSami = 'smn'; + case InariSamiFinland = 'smn_FI'; + case Shona = 'sn'; + case ShonaZimbabwe = 'sn_ZW'; + case Somali = 'so'; + case SomaliDjibouti = 'so_DJ'; + case SomaliEthiopia = 'so_ET'; + case SomaliKenya = 'so_KE'; + case SomaliSomalia = 'so_SO'; + case Albanian = 'sq'; + case AlbanianAlbania = 'sq_AL'; + case AlbanianNorthMacedonia = 'sq_MK'; + case AlbanianKosovo = 'sq_XK'; + case Serbian = 'sr'; + case SerbianSerbia = 'sr_RS'; + case SerbianCyrillic = 'sr_Cyrl'; + case SerbianCyrillicSerbia = 'sr_Cyrl_RS'; + case SerbianLatin = 'sr_Latn'; + case SerbianLatinSerbia = 'sr_Latn_RS'; + case Sundanese = 'su'; + case SundaneseLatin = 'su_Latn'; + case Swedish = 'sv'; + case SwedishAlandIslands = 'sv_AX'; + case SwedishFinland = 'sv_FI'; + case SwedishSweden = 'sv_SE'; + case Swahili = 'sw'; + case SwahiliCongoKinshasa = 'sw_CD'; + case SwahiliKenya = 'sw_KE'; + case SwahiliTanzania = 'sw_TZ'; + case SwahiliUganda = 'sw_UG'; + case Syriac = 'syr'; + case SyriacIraq = 'syr_IQ'; + case SyriacSyria = 'syr_SY'; + case Silesian = 'szl'; + case SilesianPoland = 'szl_PL'; + case Tamil = 'ta'; + case TamilIndia = 'ta_IN'; + case TamilSriLanka = 'ta_LK'; + case TamilMalaysia = 'ta_MY'; + case TamilSingapore = 'ta_SG'; + case Telugu = 'te'; + case TeluguIndia = 'te_IN'; + case Teso = 'teo'; + case TesoKenya = 'teo_KE'; + case TesoUganda = 'teo_UG'; + case Tajik = 'tg'; + case TajikTajikistan = 'tg_TJ'; + case Thai = 'th'; + case ThaiThailand = 'th_TH'; + case Tigrinya = 'ti'; + case TigrinyaEritrea = 'ti_ER'; + case TigrinyaEthiopia = 'ti_ET'; + case Turkmen = 'tk'; + case TurkmenTurkmenistan = 'tk_TM'; + case Tongan = 'to'; + case TonganTonga = 'to_TO'; + case TokiPona = 'tok'; + case Turkish = 'tr'; + case TurkishCyprus = 'tr_CY'; + case TurkishTurkiye = 'tr_TR'; + case Tatar = 'tt'; + case TatarRussia = 'tt_RU'; + case Tasawaq = 'twq'; + case TasawaqNiger = 'twq_NE'; + case CentralAtlasTamazight = 'tzm'; + case CentralAtlasTamazightMorocco = 'tzm_MA'; + case Uyghur = 'ug'; + case UyghurChina = 'ug_CN'; + case Ukrainian = 'uk'; + case UkrainianUkraine = 'uk_UA'; + case Urdu = 'ur'; + case UrduIndia = 'ur_IN'; + case UrduPakistan = 'ur_PK'; + case Uzbek = 'uz'; + case UzbekArabic = 'uz_Arab'; + case UzbekCyrillic = 'uz_Cyrl'; + case UzbekLatin = 'uz_Latn'; + case Vai = 'vai'; + case VaiLatin = 'vai_Latn'; + case VaiVai = 'vai_Vaii'; + case Venetian = 'vec'; + case VenetianItaly = 'vec_IT'; + case Vietnamese = 'vi'; + case VietnameseVietnam = 'vi_VN'; + case Makhuwa = 'vmw'; + case MakhuwaMozambique = 'vmw_MZ'; + case Vunjo = 'vun'; + case VunjoTanzania = 'vun_TZ'; + case Walser = 'wae'; + case WalserSwitzerland = 'wae_CH'; + case Wolof = 'wo'; + case WolofSenegal = 'wo_SN'; + case Xhosa = 'xh'; + case XhosaSouthAfrica = 'xh_ZA'; + case Kangri = 'xnr'; + case KangriIndia = 'xnr_IN'; + case Soga = 'xog'; + case SogaUganda = 'xog_UG'; + case Yangben = 'yav'; + case YangbenCameroon = 'yav_CM'; + case Yiddish = 'yi'; + case YiddishUkraine = 'yi_UA'; + case Yoruba = 'yo'; + case YorubaBenin = 'yo_BJ'; + case YorubaNigeria = 'yo_NG'; + case Nheengatu = 'yrl'; + case NheengatuBrazil = 'yrl_BR'; + case NheengatuColombia = 'yrl_CO'; + case NheengatuVenezuela = 'yrl_VE'; + case Cantonese = 'yue'; + case CantoneseSimplified = 'yue_Hans'; + case CantoneseTraditional = 'yue_Hant'; + case Zhuang = 'za'; + case ZhuangChina = 'za_CN'; + case StandardMoroccanTamazight = 'zgh'; + case StandardMoroccanTamazightMorocco = 'zgh_MA'; + case Chinese = 'zh'; + case ChineseSimplified = 'zh_Hans'; + case ChineseTraditional = 'zh_Hant'; + case Zulu = 'zu'; + case ZuluSouthAfrica = 'zu_ZA'; /** * Retrieves the system's default locale from the PHP environment settings. @@ -848,7 +848,7 @@ public static function default(): self * * @psalm-mutation-free */ - public function getDisplayName(?Locale $locale = null): string + public function getDisplayName(null|Locale $locale = null): string { /** @var non-empty-string */ return NativeLocale::getDisplayName($this->value, $locale?->value ?? $this->value); @@ -876,7 +876,7 @@ public function getLanguage(): string * * @psalm-mutation-free */ - public function getDisplayLanguage(?Locale $locale = null): string + public function getDisplayLanguage(null|Locale $locale = null): string { /** @var non-empty-string */ return NativeLocale::getDisplayLanguage($this->value, $locale?->value ?? $this->value); @@ -901,7 +901,7 @@ public function hasScript(): bool * * @psalm-mutation-free */ - public function getScript(): ?string + public function getScript(): null|string { return NativeLocale::getScript($this->value) ?: null; } @@ -927,7 +927,7 @@ public function hasRegion(): bool * * @psalm-mutation-free */ - public function getDisplayRegion(?Locale $locale = null): ?string + public function getDisplayRegion(null|Locale $locale = null): null|string { return NativeLocale::getDisplayRegion($this->value, $locale?->value ?? $this->value) ?: null; } @@ -939,7 +939,7 @@ public function getDisplayRegion(?Locale $locale = null): ?string * * @psalm-mutation-free */ - public function getRegion(): ?string + public function getRegion(): null|string { return NativeLocale::getRegion($this->value) ?: null; } diff --git a/src/Psl/Math/base_convert.php b/src/Psl/Math/base_convert.php index ab03e899..67f04e07 100644 --- a/src/Psl/Math/base_convert.php +++ b/src/Psl/Math/base_convert.php @@ -31,14 +31,14 @@ function base_convert(string $value, int $from_base, int $to_base): string { $from_alphabet = Byte\slice(Str\ALPHABET_ALPHANUMERIC, 0, $from_base); $result_decimal = '0'; - $place_value = bcpow((string)$from_base, (string)(Byte\length($value) - 1)); + $place_value = bcpow((string) $from_base, (string) (Byte\length($value) - 1)); foreach (Byte\chunk($value) as $digit) { $digit_numeric = Byte\search_ci($from_alphabet, $digit); if (null === $digit_numeric) { throw new Exception\InvalidArgumentException(Str\format('Invalid digit %s in base %d', $digit, $from_base)); } - $result_decimal = bcadd($result_decimal, bcmul((string)$digit_numeric, $place_value)); - $place_value = bcdiv($place_value, (string)$from_base); + $result_decimal = bcadd($result_decimal, bcmul((string) $digit_numeric, $place_value)); + $place_value = bcdiv($place_value, (string) $from_base); } if (10 === $to_base) { @@ -46,10 +46,10 @@ function base_convert(string $value, int $from_base, int $to_base): string } $to_alphabet = Byte\slice(Str\ALPHABET_ALPHANUMERIC, 0, $to_base); - $result = ''; + $result = ''; do { - $result = $to_alphabet[(int)bcmod($result_decimal, (string)$to_base)] . $result; - $result_decimal = bcdiv($result_decimal, (string)$to_base); + $result = $to_alphabet[(int) bcmod($result_decimal, (string) $to_base)] . $result; + $result_decimal = bcdiv($result_decimal, (string) $to_base); } while (bccomp($result_decimal, '0') > 0); return $result; diff --git a/src/Psl/Math/div.php b/src/Psl/Math/div.php index 3fb674e7..d043b8b9 100644 --- a/src/Psl/Math/div.php +++ b/src/Psl/Math/div.php @@ -23,16 +23,12 @@ function div(int $numerator, int $denominator): int try { return intdiv($numerator, $denominator); } catch (DivisionByZeroError $error) { - throw new Exception\DivisionByZeroException( - Str\format('%s.', $error->getMessage()), - $error->getCode(), - $error - ); + throw new Exception\DivisionByZeroException(Str\format('%s.', $error->getMessage()), $error->getCode(), $error); } catch (ArithmeticError $error) { throw new Exception\ArithmeticException( 'Division of Math\INT64_MIN by -1 is not an integer.', $error->getCode(), - $error + $error, ); } } diff --git a/src/Psl/Math/from_base.php b/src/Psl/Math/from_base.php index 0be7d439..aef7bde3 100644 --- a/src/Psl/Math/from_base.php +++ b/src/Psl/Math/from_base.php @@ -22,7 +22,7 @@ function from_base(string $number, int $from_base): int { /** @psalm-suppress MissingThrowsDocblock */ - $limit = div(INT64_MAX, $from_base); + $limit = div(INT64_MAX, $from_base); $result = 0; foreach (Byte\chunk($number) as $digit) { $oval = Byte\ord($digit); @@ -42,11 +42,13 @@ function from_base(string $number, int $from_base): int } $oldval = $result; - $result = $from_base * $result + $dval; + $result = ($from_base * $result) + $dval; if ($oldval > $limit || $oldval > $result) { - throw new Exception\OverflowException( - Str\format('Unexpected integer overflow parsing %s from base %d', $number, $from_base) - ); + throw new Exception\OverflowException(Str\format( + 'Unexpected integer overflow parsing %s from base %d', + $number, + $from_base, + )); } } diff --git a/src/Psl/Math/log.php b/src/Psl/Math/log.php index 4af537a9..c0bed04b 100644 --- a/src/Psl/Math/log.php +++ b/src/Psl/Math/log.php @@ -13,7 +13,7 @@ * * @throws Exception\InvalidArgumentException If $number or $base are negative, or $base is equal to 1.0. */ -function log(float $number, ?float $base = null): float +function log(float $number, null|float $base = null): float { if ($number <= 0) { throw new Exception\InvalidArgumentException('$number must be positive.'); diff --git a/src/Psl/Math/max_by.php b/src/Psl/Math/max_by.php index 5c37ce6f..b1cc1ea8 100644 --- a/src/Psl/Math/max_by.php +++ b/src/Psl/Math/max_by.php @@ -23,12 +23,12 @@ */ function max_by(iterable $numbers, Closure $numeric_function): mixed { - $max = null; + $max = null; $max_num = null; foreach ($numbers as $value) { $value_num = $numeric_function($value); if (null === $max_num || $value_num >= $max_num) { - $max = $value; + $max = $value; $max_num = $value_num; } } diff --git a/src/Psl/Math/mean.php b/src/Psl/Math/mean.php index 51907e30..2ff75cf7 100644 --- a/src/Psl/Math/mean.php +++ b/src/Psl/Math/mean.php @@ -26,7 +26,7 @@ function mean(array $numbers): float|null $mean = 0.0; foreach ($numbers as $number) { - $mean += (float)$number / $count; + $mean += ((float) $number) / $count; } return $mean; diff --git a/src/Psl/Math/median.php b/src/Psl/Math/median.php index faf12bbe..e6ab9c71 100644 --- a/src/Psl/Math/median.php +++ b/src/Psl/Math/median.php @@ -21,17 +21,15 @@ function median(array $numbers): float|null { sort($numbers); - $count = count($numbers); + $count = count($numbers); if (0 === $count) { return null; } /** @psalm-suppress MissingThrowsDocblock */ $middle_index = div($count, 2); - if (0 === $count % 2) { - return mean( - [$numbers[$middle_index], $numbers[$middle_index - 1]] - ); + if (0 === ($count % 2)) { + return mean([$numbers[$middle_index], $numbers[$middle_index - 1]]); } return (float) $numbers[$middle_index]; diff --git a/src/Psl/Math/min_by.php b/src/Psl/Math/min_by.php index c8d2edd6..dfdc6034 100644 --- a/src/Psl/Math/min_by.php +++ b/src/Psl/Math/min_by.php @@ -23,12 +23,12 @@ */ function min_by(iterable $numbers, Closure $numeric_function): mixed { - $min = null; + $min = null; $min_num = null; foreach ($numbers as $value) { $value_num = $numeric_function($value); if (null === $min_num || $value_num <= $min_num) { - $min = $value; + $min = $value; $min_num = $value_num; } } diff --git a/src/Psl/Math/sum_floats.php b/src/Psl/Math/sum_floats.php index e3af47ac..db3934d9 100644 --- a/src/Psl/Math/sum_floats.php +++ b/src/Psl/Math/sum_floats.php @@ -15,7 +15,7 @@ function sum_floats(array $numbers): float { $result = 0.0; foreach ($numbers as $number) { - $result += (float)$number; + $result += (float) $number; } return $result; diff --git a/src/Psl/Math/to_base.php b/src/Psl/Math/to_base.php index cdd03b2b..7ededf0f 100644 --- a/src/Psl/Math/to_base.php +++ b/src/Psl/Math/to_base.php @@ -23,8 +23,8 @@ function to_base(int $number, int $base): string do { /** @psalm-suppress MissingThrowsDocblock */ $quotient = div($number, $base); - $result = Str\ALPHABET_ALPHANUMERIC[$number - $quotient * $base] . $result; - $number = $quotient; + $result = Str\ALPHABET_ALPHANUMERIC[$number - ($quotient * $base)] . $result; + $number = $quotient; } while (0 !== $number); /** @var non-empty-string */ diff --git a/src/Psl/Network/Address.php b/src/Psl/Network/Address.php index 8a2a59f3..c1cf3ccc 100644 --- a/src/Psl/Network/Address.php +++ b/src/Psl/Network/Address.php @@ -22,7 +22,7 @@ /** * @var int<0, 65535>|null */ - public ?int $port; + public null|int $port; /** * @param SocketScheme $scheme @@ -31,7 +31,7 @@ * * @psalm-mutation-free */ - private function __construct(SocketScheme $scheme, string $host, ?int $port) + private function __construct(SocketScheme $scheme, string $host, null|int $port) { $this->scheme = $scheme; $this->host = $host; @@ -45,7 +45,7 @@ private function __construct(SocketScheme $scheme, string $host, ?int $port) * * @pure */ - public static function create(SocketScheme $scheme, string $host, ?int $port = null): self + public static function create(SocketScheme $scheme, string $host, null|int $port = null): self { return new self($scheme, $host, $port); } diff --git a/src/Psl/Network/Internal/AbstractStreamServer.php b/src/Psl/Network/Internal/AbstractStreamServer.php index a8d4e809..6dab018c 100644 --- a/src/Psl/Network/Internal/AbstractStreamServer.php +++ b/src/Psl/Network/Internal/AbstractStreamServer.php @@ -60,7 +60,13 @@ protected function __construct(mixed $impl, int $idleConnections = self::DEFAULT // @codeCoverageIgnoreStart /** @var array{file: string, line: int, message: string, type: int} $err */ $err = error_get_last(); - $sender->send([false, new Network\Exception\RuntimeException('Failed to accept incoming connection: ' . $err['message'], $err['type'])]); + $sender->send([ + false, + new Network\Exception\RuntimeException( + 'Failed to accept incoming connection: ' . $err['message'], + $err['type'], + ), + ]); // @codeCoverageIgnoreEnd } catch (Channel\Exception\ClosedChannelException) { EventLoop::cancel($watcher); diff --git a/src/Psl/Network/Internal/Socket.php b/src/Psl/Network/Internal/Socket.php index 43f5327f..e7f574d4 100644 --- a/src/Psl/Network/Internal/Socket.php +++ b/src/Psl/Network/Internal/Socket.php @@ -44,7 +44,7 @@ public function reachedEndOfDataSource(): bool /** * {@inheritDoc} */ - public function tryRead(?int $max_bytes = null): string + public function tryRead(null|int $max_bytes = null): string { return $this->handle->tryRead($max_bytes); } @@ -52,7 +52,7 @@ public function tryRead(?int $max_bytes = null): string /** * {@inheritDoc} */ - public function read(?int $max_bytes = null, ?Duration $timeout = null): string + public function read(null|int $max_bytes = null, null|Duration $timeout = null): string { return $this->handle->read($max_bytes, $timeout); } @@ -68,7 +68,7 @@ public function tryWrite(string $bytes): int /** * {@inheritDoc} */ - public function write(string $bytes, ?Duration $timeout = null): int + public function write(string $bytes, null|Duration $timeout = null): int { return $this->handle->write($bytes, $timeout); } diff --git a/src/Psl/Network/Internal/server_listen.php b/src/Psl/Network/Internal/server_listen.php index 5e120f52..57803d31 100644 --- a/src/Psl/Network/Internal/server_listen.php +++ b/src/Psl/Network/Internal/server_listen.php @@ -34,9 +34,18 @@ function server_listen(string $uri, array $context = []): mixed static function () use ($uri, $context): mixed { $context = stream_context_create($context); // Error reporting suppressed since stream_socket_server() emits an E_WARNING on failure (checked below). - $server = @stream_socket_server($uri, $errno, $_, flags: STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, context: $context); + $server = @stream_socket_server( + $uri, + $errno, + $_, + flags: STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, + context: $context, + ); if (!$server || $errno) { - throw new Psl\Network\Exception\RuntimeException('Failed to listen to on given address (' . $uri . ').', $errno); + throw new Psl\Network\Exception\RuntimeException( + 'Failed to listen to on given address (' . $uri . ').', + $errno, + ); } return $server; diff --git a/src/Psl/Network/Internal/socket_connect.php b/src/Psl/Network/Internal/socket_connect.php index 088e92bd..4547650e 100644 --- a/src/Psl/Network/Internal/socket_connect.php +++ b/src/Psl/Network/Internal/socket_connect.php @@ -30,11 +30,18 @@ * * @codeCoverageIgnore */ -function socket_connect(string $uri, array $context = [], ?Duration $timeout = null): mixed +function socket_connect(string $uri, array $context = [], null|Duration $timeout = null): mixed { return Internal\suppress(static function () use ($uri, $context, $timeout): mixed { $context = stream_context_create($context); - $socket = @stream_socket_client($uri, $errno, $_, null, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT, $context); + $socket = @stream_socket_client( + $uri, + $errno, + $_, + null, + STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT, + $context, + ); if (!$socket || $errno) { throw new Exception\RuntimeException('Failed to connect to client "' . $uri . '".', $errno); } @@ -45,7 +52,11 @@ function socket_connect(string $uri, array $context = [], ?Duration $timeout = n $timeout_watcher = ''; if (null !== $timeout) { $timeout = max($timeout->getTotalSeconds(), 0.0); - $timeout_watcher = EventLoop::delay($timeout, static function () use ($suspension, &$write_watcher, $socket) { + $timeout_watcher = EventLoop::delay($timeout, static function () use ( + $suspension, + &$write_watcher, + $socket, + ) { EventLoop::cancel($write_watcher); /** @psalm-suppress RedundantCondition - it can be resource|closed-resource */ @@ -57,7 +68,11 @@ function socket_connect(string $uri, array $context = [], ?Duration $timeout = n }); } - $write_watcher = EventLoop::onWritable($socket, static function () use ($suspension, $socket, $timeout_watcher) { + $write_watcher = EventLoop::onWritable($socket, static function () use ( + $suspension, + $socket, + $timeout_watcher, + ) { EventLoop::cancel($timeout_watcher); $suspension->resume($socket); diff --git a/src/Psl/Network/SocketOptions.php b/src/Psl/Network/SocketOptions.php index 1a59a6ca..19050174 100644 --- a/src/Psl/Network/SocketOptions.php +++ b/src/Psl/Network/SocketOptions.php @@ -45,8 +45,11 @@ public function __construct(bool $address_reuse, bool $port_reuse, bool $broadca * * @pure */ - public static function create(bool $address_reuse = false, bool $port_reuse = false, bool $broadcast = false): SocketOptions - { + public static function create( + bool $address_reuse = false, + bool $port_reuse = false, + bool $broadcast = false, + ): SocketOptions { return new self($address_reuse, $port_reuse, $broadcast); } diff --git a/src/Psl/Option/Option.php b/src/Psl/Option/Option.php index a1350f99..10579947 100644 --- a/src/Psl/Option/Option.php +++ b/src/Psl/Option/Option.php @@ -26,7 +26,7 @@ * * @psalm-mutation-free */ - private function __construct(?array $option) + private function __construct(null|array $option) { $this->option = $option; } @@ -400,7 +400,7 @@ public function compare(mixed $other): Comparison\Order return match (true) { $aIsNone || $bIsNone => Comparison\compare($bIsNone, $aIsNone), - default => Comparison\compare($this->unwrap(), $other->unwrap()) + default => Comparison\compare($this->unwrap(), $other->unwrap()), }; } @@ -451,9 +451,9 @@ public function zipWith(Option $other, Closure $closure): Option static function ($a) use ($other, $closure) { return $other->map( /** @param Tu $b */ - static fn ($b) => $closure($a, $b) + static fn($b) => $closure($a, $b), ); - } + }, ); } diff --git a/src/Psl/Password/get_information.php b/src/Psl/Password/get_information.php index 066e6205..74593935 100644 --- a/src/Psl/Password/get_information.php +++ b/src/Psl/Password/get_information.php @@ -29,12 +29,12 @@ function get_information(string $hash): array { /** @var array{algo: string, options: array} $information */ $information = password_get_info($hash); - $algorithm = $information['algo']; + $algorithm = $information['algo']; if (PASSWORD_BCRYPT === $algorithm) { return [ 'algorithm' => Algorithm::Bcrypt, 'options' => [ - 'cost' => (int)($information['options']['cost'] ?? PASSWORD_BCRYPT_DEFAULT_COST), + 'cost' => (int) ($information['options']['cost'] ?? PASSWORD_BCRYPT_DEFAULT_COST), ], ]; } @@ -42,9 +42,9 @@ function get_information(string $hash): array return [ 'algorithm' => PASSWORD_ARGON2ID === $algorithm ? Algorithm::Argon2id : Algorithm::Argon2i, 'options' => [ - 'memory_cost' => (int)($information['options']['memory_cost'] ?? PASSWORD_ARGON2_DEFAULT_MEMORY_COST), - 'time_cost' => (int)($information['options']['time_cost'] ?? PASSWORD_ARGON2_DEFAULT_TIME_COST), - 'threads' => (int)($information['options']['threads'] ?? PASSWORD_ARGON2_DEFAULT_THREADS), + 'memory_cost' => (int) ($information['options']['memory_cost'] ?? PASSWORD_ARGON2_DEFAULT_MEMORY_COST), + 'time_cost' => (int) ($information['options']['time_cost'] ?? PASSWORD_ARGON2_DEFAULT_TIME_COST), + 'threads' => (int) ($information['options']['threads'] ?? PASSWORD_ARGON2_DEFAULT_THREADS), ], ]; } diff --git a/src/Psl/PseudoRandom/int.php b/src/Psl/PseudoRandom/int.php index 159cf5f5..1d210fb4 100644 --- a/src/Psl/PseudoRandom/int.php +++ b/src/Psl/PseudoRandom/int.php @@ -19,7 +19,11 @@ function int(int $min = Math\INT64_MIN, int $max = Math\INT64_MAX): int { if ($min > $max) { - throw new Exception\InvalidArgumentException(Str\format('Expected $min (%d) to be less than or equal to $max (%d).', $min, $max)); + throw new Exception\InvalidArgumentException(Str\format( + 'Expected $min (%d) to be less than or equal to $max (%d).', + $min, + $max, + )); } return mt_rand($min, $max); diff --git a/src/Psl/RandomSequence/Internal/MersenneTwisterTrait.php b/src/Psl/RandomSequence/Internal/MersenneTwisterTrait.php index f0c5d41a..979655fb 100644 --- a/src/Psl/RandomSequence/Internal/MersenneTwisterTrait.php +++ b/src/Psl/RandomSequence/Internal/MersenneTwisterTrait.php @@ -16,9 +16,8 @@ trait MersenneTwisterTrait private int $index; - final public function __construct( - int $seed - ) { + final public function __construct(int $seed) + { $state = [$seed & 0xffffffff]; /** @var array{0: int, 1: int} $i */ $i = [$seed & 0xffff, ($seed >> 16) & 0xffff]; @@ -61,7 +60,7 @@ final public function next(): int $y = $this->state[$this->index++]; $y ^= ($y >> 11) & 0x001fffff; - $y ^= ($y << 7) & 0x9d2c5680; + $y ^= ($y << 7) & 0x9d2c5680; $y ^= ($y << 15) & 0xefc60000; $y ^= ($y >> 18) & 0x00003fff; diff --git a/src/Psl/Range/BetweenRange.php b/src/Psl/Range/BetweenRange.php index 3c5d592e..dfb4a8aa 100644 --- a/src/Psl/Range/BetweenRange.php +++ b/src/Psl/Range/BetweenRange.php @@ -42,8 +42,8 @@ */ final readonly class BetweenRange implements LowerBoundRangeInterface, UpperBoundRangeInterface { - private int $lowerBound; - private int $upperBound; + private int $lowerBound; + private int $upperBound; private bool $upperInclusive; /** @@ -51,13 +51,10 @@ * * @psalm-mutation-free */ - public function __construct(int $lower_bound, int $upper_bound, bool $upper_inclusive = false) + public function __construct(int $lower_bound, int $upper_bound, bool $upper_inclusive = false) { if ($lower_bound > $upper_bound) { - throw Exception\InvalidRangeException::lowerBoundIsGreaterThanUpperBound( - $lower_bound, - $upper_bound - ); + throw Exception\InvalidRangeException::lowerBoundIsGreaterThanUpperBound($lower_bound, $upper_bound); } $this->lowerBound = $lower_bound; @@ -92,11 +89,7 @@ public function contains(int $value): bool */ public function withUpperBound(int $upper_bound, bool $upper_inclusive): BetweenRange { - return new BetweenRange( - $this->lowerBound, - $upper_bound, - $upper_inclusive, - ); + return new BetweenRange($this->lowerBound, $upper_bound, $upper_inclusive); } /** @@ -108,11 +101,7 @@ public function withUpperBound(int $upper_bound, bool $upper_inclusive): Between */ public function withUpperBoundInclusive(int $upper_bound): BetweenRange { - return new BetweenRange( - $this->lowerBound, - $upper_bound, - true, - ); + return new BetweenRange($this->lowerBound, $upper_bound, true); } /** @@ -124,11 +113,7 @@ public function withUpperBoundInclusive(int $upper_bound): BetweenRange */ public function withUpperBoundExclusive(int $upper_bound): BetweenRange { - return new BetweenRange( - $this->lowerBound, - $upper_bound, - false, - ); + return new BetweenRange($this->lowerBound, $upper_bound, false); } /** @@ -150,11 +135,7 @@ public function withoutLowerBound(): ToRange */ public function withLowerBound(int $lower_bound): BetweenRange { - return new static( - $lower_bound, - $this->upperBound, - $this->upperInclusive, - ); + return new static($lower_bound, $this->upperBound, $this->upperInclusive); } /** @@ -195,11 +176,7 @@ public function isUpperInclusive(): bool public function withUpperInclusive(bool $upper_inclusive): static { /** @psalm-suppress MissingThrowsDocblock */ - return new static( - $this->lowerBound, - $this->upperBound, - $upper_inclusive, - ); + return new static($this->lowerBound, $this->upperBound, $upper_inclusive); } /** @@ -228,7 +205,7 @@ public function getIterator(): Iter\Iterator $inclusive = $this->upperInclusive; return Iter\Iterator::from(static function () use ($lower, $upper, $inclusive): Generator { - $to = $inclusive ? $upper : $upper - 1; + $to = $inclusive ? $upper : ($upper - 1); for ($i = $lower; $i <= $to; $i++) { yield $i; diff --git a/src/Psl/Range/Exception/InvalidRangeException.php b/src/Psl/Range/Exception/InvalidRangeException.php index cbc136af..10f5ef3d 100644 --- a/src/Psl/Range/Exception/InvalidRangeException.php +++ b/src/Psl/Range/Exception/InvalidRangeException.php @@ -17,10 +17,8 @@ public function __construct( parent::__construct($message); } - public static function lowerBoundIsGreaterThanUpperBound( - int $lower_bound, - int $upper_bound, - ): self { + public static function lowerBoundIsGreaterThanUpperBound(int $lower_bound, int $upper_bound): self + { return new self( Str\format( '`$lower_bound` (%d) must be less than or equal to `$upper_bound` (%d).', diff --git a/src/Psl/Range/FromRange.php b/src/Psl/Range/FromRange.php index 88eecdc7..ab287756 100644 --- a/src/Psl/Range/FromRange.php +++ b/src/Psl/Range/FromRange.php @@ -59,9 +59,7 @@ public function contains(int $value): bool */ public function withLowerBound(int $lower_bound): FromRange { - return new FromRange( - $lower_bound, - ); + return new FromRange($lower_bound); } /** @@ -73,11 +71,7 @@ public function withLowerBound(int $lower_bound): FromRange */ public function withUpperBound(int $upper_bound, bool $upper_inclusive): BetweenRange { - return new BetweenRange( - $this->lowerBound, - $upper_bound, - $upper_inclusive, - ); + return new BetweenRange($this->lowerBound, $upper_bound, $upper_inclusive); } /** @@ -89,11 +83,7 @@ public function withUpperBound(int $upper_bound, bool $upper_inclusive): Between */ public function withUpperBoundInclusive(int $upper_bound): BetweenRange { - return new BetweenRange( - $this->lowerBound, - $upper_bound, - true, - ); + return new BetweenRange($this->lowerBound, $upper_bound, true); } /** @@ -105,11 +95,7 @@ public function withUpperBoundInclusive(int $upper_bound): BetweenRange */ public function withUpperBoundExclusive(int $upper_bound): BetweenRange { - return new BetweenRange( - $this->lowerBound, - $upper_bound, - false, - ); + return new BetweenRange($this->lowerBound, $upper_bound, false); } /** diff --git a/src/Psl/Range/FullRange.php b/src/Psl/Range/FullRange.php index 93a91d86..a8359b6e 100644 --- a/src/Psl/Range/FullRange.php +++ b/src/Psl/Range/FullRange.php @@ -34,9 +34,7 @@ public function contains(int $value): bool */ public function withLowerBound(int $lower_bound): FromRange { - return new FromRange( - $lower_bound, - ); + return new FromRange($lower_bound); } /** diff --git a/src/Psl/Range/LowerBoundRangeInterface.php b/src/Psl/Range/LowerBoundRangeInterface.php index b4191002..0b918c91 100644 --- a/src/Psl/Range/LowerBoundRangeInterface.php +++ b/src/Psl/Range/LowerBoundRangeInterface.php @@ -22,7 +22,10 @@ interface LowerBoundRangeInterface extends IteratorAggregate, RangeInterface * * @psalm-mutation-free */ - public function withUpperBound(int $upper_bound, bool $upper_inclusive): UpperBoundRangeInterface&LowerBoundRangeInterface; + public function withUpperBound( + int $upper_bound, + bool $upper_inclusive, + ): UpperBoundRangeInterface&LowerBoundRangeInterface; /** * {@inheritDoc} diff --git a/src/Psl/Range/ToRange.php b/src/Psl/Range/ToRange.php index 3ee3c5f3..83de42f6 100644 --- a/src/Psl/Range/ToRange.php +++ b/src/Psl/Range/ToRange.php @@ -17,7 +17,7 @@ */ final readonly class ToRange implements UpperBoundRangeInterface { - private int $upperBound; + private int $upperBound; private bool $upperInclusive; /** @@ -52,11 +52,7 @@ public function contains(int $value): bool */ public function withLowerBound(int $lower_bound): BetweenRange { - return new BetweenRange( - $lower_bound, - $this->upperBound, - $this->upperInclusive, - ); + return new BetweenRange($lower_bound, $this->upperBound, $this->upperInclusive); } /** @@ -126,9 +122,6 @@ public function isUpperInclusive(): bool */ public function withUpperInclusive(bool $upper_inclusive): static { - return new static( - $this->upperBound, - $upper_inclusive, - ); + return new static($this->upperBound, $upper_inclusive); } } diff --git a/src/Psl/Regex/Internal/get_preg_error.php b/src/Psl/Regex/Internal/get_preg_error.php index 9eef2dfd..e4d223fd 100644 --- a/src/Psl/Regex/Internal/get_preg_error.php +++ b/src/Psl/Regex/Internal/get_preg_error.php @@ -21,7 +21,7 @@ * * @internal */ -function get_preg_error(string $function): ?array +function get_preg_error(string $function): null|array { /** @psalm-suppress ImpureFunctionCall */ $code = preg_last_error(); diff --git a/src/Psl/Regex/capture_groups.php b/src/Psl/Regex/capture_groups.php index d606c732..14354555 100644 --- a/src/Psl/Regex/capture_groups.php +++ b/src/Psl/Regex/capture_groups.php @@ -16,13 +16,11 @@ */ function capture_groups(array $groups): Type\TypeInterface { - return Type\shape( - Dict\from_keys( - Dict\unique([0, ...$groups]), - /** - * @return Type\TypeInterface - */ - static fn(): Type\TypeInterface => Type\string() - ) - ); + return Type\shape(Dict\from_keys( + Dict\unique([0, ...$groups]), + /** + * @return Type\TypeInterface + */ + static fn(): Type\TypeInterface => Type\string(), + )); } diff --git a/src/Psl/Regex/every_match.php b/src/Psl/Regex/every_match.php index 1a02b061..bce4ec77 100644 --- a/src/Psl/Regex/every_match.php +++ b/src/Psl/Regex/every_match.php @@ -21,17 +21,18 @@ * * @return (T is null ? list> : list)|null */ -function every_match(string $subject, string $pattern, ?Type\TypeInterface $capture_groups = null, int $offset = 0): ?array -{ - $matching = Internal\call_preg( - 'preg_match_all', - static function () use ($subject, $pattern, $offset): ?array { - $matching = []; - $matches = preg_match_all($pattern, $subject, $matching, PREG_SET_ORDER, $offset); - - return $matches === 0 ? null : $matching; - } - ); +function every_match( + string $subject, + string $pattern, + null|Type\TypeInterface $capture_groups = null, + int $offset = 0, +): null|array { + $matching = Internal\call_preg('preg_match_all', static function () use ($subject, $pattern, $offset): null|array { + $matching = []; + $matches = preg_match_all($pattern, $subject, $matching, PREG_SET_ORDER, $offset); + + return $matches === 0 ? null : $matching; + }); if ($matching === null) { return null; diff --git a/src/Psl/Regex/first_match.php b/src/Psl/Regex/first_match.php index b6bf6622..35dd42e5 100644 --- a/src/Psl/Regex/first_match.php +++ b/src/Psl/Regex/first_match.php @@ -21,17 +21,18 @@ * * @return (T is null ? array : T)|null */ -function first_match(string $subject, string $pattern, ?Type\TypeInterface $capture_groups = null, int $offset = 0): ?array -{ - $matching = Internal\call_preg( - 'preg_match', - static function () use ($subject, $pattern, $offset): ?array { - $matching = []; - $matches = preg_match($pattern, $subject, $matching, 0, $offset); - - return $matches === 0 ? null : $matching; - } - ); +function first_match( + string $subject, + string $pattern, + null|Type\TypeInterface $capture_groups = null, + int $offset = 0, +): null|array { + $matching = Internal\call_preg('preg_match', static function () use ($subject, $pattern, $offset): null|array { + $matching = []; + $matches = preg_match($pattern, $subject, $matching, 0, $offset); + + return $matches === 0 ? null : $matching; + }); if ($matching === null) { return null; diff --git a/src/Psl/Regex/matches.php b/src/Psl/Regex/matches.php index a7c9524e..ff1404ac 100644 --- a/src/Psl/Regex/matches.php +++ b/src/Psl/Regex/matches.php @@ -19,8 +19,5 @@ function matches(string $subject, string $pattern, int $offset = 0): bool { $_ = []; - return Internal\call_preg( - 'preg_match', - static fn() => preg_match($pattern, $subject, $_, 0, $offset), - ) === 1; + return Internal\call_preg('preg_match', static fn() => preg_match($pattern, $subject, $_, 0, $offset)) === 1; } diff --git a/src/Psl/Regex/replace.php b/src/Psl/Regex/replace.php index 3ce54557..21a07358 100644 --- a/src/Psl/Regex/replace.php +++ b/src/Psl/Regex/replace.php @@ -19,10 +19,12 @@ * * @pure */ -function replace(string $haystack, string $pattern, string $replacement, ?int $limit = null): string +function replace(string $haystack, string $pattern, string $replacement, null|int $limit = null): string { - return (string) Internal\call_preg( - 'preg_replace', - static fn() => preg_replace($pattern, $replacement, $haystack, $limit ?? -1), - ); + return (string) Internal\call_preg('preg_replace', static fn() => preg_replace( + $pattern, + $replacement, + $haystack, + $limit ?? -1, + )); } diff --git a/src/Psl/Regex/replace_every.php b/src/Psl/Regex/replace_every.php index 509cba20..b847d166 100644 --- a/src/Psl/Regex/replace_every.php +++ b/src/Psl/Regex/replace_every.php @@ -21,10 +21,12 @@ * * @pure */ -function replace_every(string $haystack, array $replacements, ?int $limit = null): string +function replace_every(string $haystack, array $replacements, null|int $limit = null): string { - return (string) Internal\call_preg( - 'preg_replace', - static fn() => preg_replace(array_keys($replacements), array_values($replacements), $haystack, $limit ?? -1), - ); + return (string) Internal\call_preg('preg_replace', static fn() => preg_replace( + array_keys($replacements), + array_values($replacements), + $haystack, + $limit ?? -1, + )); } diff --git a/src/Psl/Regex/replace_with.php b/src/Psl/Regex/replace_with.php index 0afc01c2..8938938e 100644 --- a/src/Psl/Regex/replace_with.php +++ b/src/Psl/Regex/replace_with.php @@ -21,10 +21,12 @@ * @throws Exception\InvalidPatternException If $pattern is invalid. * @throws Exception\RuntimeException In case of an unexpected error. */ -function replace_with(string $haystack, string $pattern, Closure $callback, ?int $limit = null): string +function replace_with(string $haystack, string $pattern, Closure $callback, null|int $limit = null): string { - return (string) Internal\call_preg( - 'preg_replace_callback', - static fn() => preg_replace_callback($pattern, $callback, $haystack, $limit ?? -1), - ); + return (string) Internal\call_preg('preg_replace_callback', static fn() => preg_replace_callback( + $pattern, + $callback, + $haystack, + $limit ?? -1, + )); } diff --git a/src/Psl/Regex/split.php b/src/Psl/Regex/split.php index 0c1b2500..a81843e4 100644 --- a/src/Psl/Regex/split.php +++ b/src/Psl/Regex/split.php @@ -22,11 +22,13 @@ * * @pure */ -function split(string $subject, string $pattern, ?int $limit = null): array +function split(string $subject, string $pattern, null|int $limit = null): array { /** @var list */ - return Internal\call_preg( - 'preg_split', - static fn() => preg_split($pattern, $subject, $limit ?? -1, PREG_SPLIT_NO_EMPTY), - ); + return Internal\call_preg('preg_split', static fn() => preg_split( + $pattern, + $subject, + $limit ?? -1, + PREG_SPLIT_NO_EMPTY, + )); } diff --git a/src/Psl/Result/Failure.php b/src/Psl/Result/Failure.php index 4e57b9a1..ecdcd17f 100644 --- a/src/Psl/Result/Failure.php +++ b/src/Psl/Result/Failure.php @@ -117,7 +117,7 @@ public function proceed(Closure $success, Closure $failure): mixed */ public function then(Closure $success, Closure $failure): ResultInterface { - return wrap(fn () => $failure($this->throwable)); + return wrap(fn() => $failure($this->throwable)); } /** diff --git a/src/Psl/Result/Stats.php b/src/Psl/Result/Stats.php index 9e75f014..d1bf3d71 100644 --- a/src/Psl/Result/Stats.php +++ b/src/Psl/Result/Stats.php @@ -30,8 +30,8 @@ public function apply(ResultInterface $result): self { return new self( $this->total + 1, - $result->isSucceeded() ? $this->succeeded + 1 : $this->succeeded, - $result->isFailed() ? $this->failed + 1 : $this->failed, + $result->isSucceeded() ? ($this->succeeded + 1) : $this->succeeded, + $result->isFailed() ? ($this->failed + 1) : $this->failed, ); } diff --git a/src/Psl/Result/Success.php b/src/Psl/Result/Success.php index a2846b77..12cb03c6 100644 --- a/src/Psl/Result/Success.php +++ b/src/Psl/Result/Success.php @@ -124,7 +124,7 @@ public function proceed(Closure $success, Closure $failure): mixed */ public function then(Closure $success, Closure $failure): ResultInterface { - return wrap(fn () => $success($this->value)); + return wrap(fn() => $success($this->value)); } /** @@ -138,7 +138,7 @@ public function then(Closure $success, Closure $failure): ResultInterface */ public function map(Closure $success): ResultInterface { - return wrap(fn () => $success($this->value)); + return wrap(fn() => $success($this->value)); } /** diff --git a/src/Psl/Result/collect_stats.php b/src/Psl/Result/collect_stats.php index 7c6e9d81..54e1b245 100644 --- a/src/Psl/Result/collect_stats.php +++ b/src/Psl/Result/collect_stats.php @@ -15,7 +15,7 @@ function collect_stats(iterable $results): Stats { return reduce( $results, - static fn (Stats $stats, ResultInterface $result): Stats => $stats->apply($result), - new Stats() + static fn(Stats $stats, ResultInterface $result): Stats => $stats->apply($result), + new Stats(), ); } diff --git a/src/Psl/Result/wrap.php b/src/Psl/Result/wrap.php index 275a6dc8..1e2dab4d 100644 --- a/src/Psl/Result/wrap.php +++ b/src/Psl/Result/wrap.php @@ -21,7 +21,7 @@ function wrap(Closure $closure): ResultInterface { try { $result = $closure(); - return $result instanceof ResultInterface ? $result : new Success($result); + return ($result instanceof ResultInterface) ? $result : new Success($result); } catch (Throwable $e) { return new Failure($e); } diff --git a/src/Psl/SecureRandom/int.php b/src/Psl/SecureRandom/int.php index 8c3cd029..cef23a10 100644 --- a/src/Psl/SecureRandom/int.php +++ b/src/Psl/SecureRandom/int.php @@ -22,7 +22,11 @@ function int(int $min = Math\INT64_MIN, int $max = Math\INT64_MAX): int { if ($max < $min) { - throw new Exception\InvalidArgumentException(Str\format('Expected $min (%d) to be less than or equal to $max (%d).', $min, $max)); + throw new Exception\InvalidArgumentException(Str\format( + 'Expected $min (%d) to be less than or equal to $max (%d).', + $min, + $max, + )); } if ($min === $max) { diff --git a/src/Psl/SecureRandom/string.php b/src/Psl/SecureRandom/string.php index e77dad12..7e393c64 100644 --- a/src/Psl/SecureRandom/string.php +++ b/src/Psl/SecureRandom/string.php @@ -24,16 +24,16 @@ * * @psalm-external-mutation-free */ -function string(int $length, ?string $alphabet = null): string +function string(int $length, null|string $alphabet = null): string { if (0 === $length) { return ''; } - $alphabet = $alphabet ?? Str\ALPHABET_ALPHANUMERIC; + $alphabet = $alphabet ?? Str\ALPHABET_ALPHANUMERIC; $alphabet_size = Byte\length($alphabet); /** @psalm-suppress MissingThrowsDocblock */ - $bits = (int) Math\ceil(Math\log($alphabet_size, 2.0)); + $bits = (int) Math\ceil(Math\log($alphabet_size, 2.0)); if ($bits < 1 || $bits > 56) { throw new Exception\InvalidArgumentException('$alphabet\'s length must be in [2^1, 2^56]'); } @@ -41,8 +41,8 @@ function string(int $length, ?string $alphabet = null): string $ret = ''; while ($length > 0) { /** @var int<0, max> $urandom_length */ - $urandom_length = (int) Math\ceil((float) (2 * $length * $bits) / 8.0); - $data = namespace\bytes($urandom_length); + $urandom_length = (int) Math\ceil(((float) (2 * $length * $bits)) / 8.0); + $data = namespace\bytes($urandom_length); $unpacked_data = 0; $unpacked_bits = 0; @@ -50,13 +50,13 @@ function string(int $length, ?string $alphabet = null): string // Unpack 8 bits /** @var array $v */ $v = unpack('C', $data[$i]); - $unpacked_data = ($unpacked_data << 8) | $v[1]; + $unpacked_data = ($unpacked_data << 8) | $v[1]; $unpacked_bits += 8; // While we have enough bits to select a character from the alphabet, keep // consuming the random data for (; $unpacked_bits >= $bits && $length > 0; $unpacked_bits -= $bits) { - $index = ($unpacked_data & ((1 << $bits) - 1)); + $index = $unpacked_data & ((1 << $bits) - 1); $unpacked_data >>= $bits; // Unfortunately, the alphabet size is not necessarily a power of two. // Worst case, it is 2^k + 1, which means we need (k+1) bits and we diff --git a/src/Psl/Shell/Exception/FailedExecutionException.php b/src/Psl/Shell/Exception/FailedExecutionException.php index c8f851ab..4bea6ef8 100644 --- a/src/Psl/Shell/Exception/FailedExecutionException.php +++ b/src/Psl/Shell/Exception/FailedExecutionException.php @@ -20,21 +20,15 @@ final class FailedExecutionException extends RuntimeException */ public function __construct(string $command, string $stdout_content, string $stderr_content, int $code) { - $message = Str\format( - << '"^^"', '%' => '"^%"', '!' => '"^!"', - "\n" => '!LF!' + "\n" => '!LF!', ]); return '"' . $argument . '"'; diff --git a/src/Psl/Shell/execute.php b/src/Psl/Shell/execute.php index 090651c3..42d134ae 100644 --- a/src/Psl/Shell/execute.php +++ b/src/Psl/Shell/execute.php @@ -40,12 +40,12 @@ * @throws Exception\TimeoutException If $timeout is reached before being able to read the process stream. */ function execute( - string $command, - array $arguments = [], - ?string $working_directory = null, - array $environment = [], + string $command, + array $arguments = [], + null|string $working_directory = null, + array $environment = [], ErrorOutputBehavior $error_output_behavior = ErrorOutputBehavior::Discard, - ?Duration $timeout = null + null|Duration $timeout = null, ): string { $arguments = Vec\map($arguments, Internal\escape_argument(...)); $commandline = Str\join([$command, ...$arguments], ' '); @@ -77,12 +77,7 @@ function execute( * * @return string */ - static function (array $m) use ( - &$environment, - &$variable_cache, - &$variable_count, - $identifier - ): string { + static function (array $m) use (&$environment, &$variable_cache, &$variable_count, $identifier): string { if (!isset($m[1])) { return $m[0]; } @@ -103,14 +98,20 @@ static function (array $m) use ( $var = $identifier . ((string) ++$variable_count); - $environment[$var] = '"' . Regex\replace( - Str\Byte\replace_every( - $value, - ['!LF!' => "\n", '"^!"' => '!', '"^%"' => '%', '"^^"' => '^', '""' => '"'] - ), - '/(\\\\*)"/', - '$1$1\\"', - ) . '"'; + $environment[$var] = + '"' . + Regex\replace( + Str\Byte\replace_every($value, [ + '!LF!' => "\n", + '"^!"' => '!', + '"^%"' => '%', + '"^^"' => '^', + '""' => '"', + ]), + '/(\\\\*)"/', + '$1$1\\"', + ) . + '"'; /** @var string */ return $variable_cache[$m[0]] = '!' . $var . '!'; @@ -150,7 +151,11 @@ static function (array $m) use ( } } } catch (IO\Exception\TimeoutException $previous) { - throw new Exception\TimeoutException('reached timeout while the process output is still not readable.', 0, $previous); + throw new Exception\TimeoutException( + 'reached timeout while the process output is still not readable.', + 0, + $previous, + ); } finally { /** @psalm-suppress MissingThrowsDocblock */ $stdout->close(); diff --git a/src/Psl/Str/Byte/after.php b/src/Psl/Str/Byte/after.php index 80aacfca..7d0a7d07 100644 --- a/src/Psl/Str/Byte/after.php +++ b/src/Psl/Str/Byte/after.php @@ -11,7 +11,7 @@ * * @pure */ -function after(string $haystack, string $needle, int $offset = 0): ?string +function after(string $haystack, string $needle, int $offset = 0): null|string { $position = search($haystack, $needle, $offset); if (null === $position) { diff --git a/src/Psl/Str/Byte/after_ci.php b/src/Psl/Str/Byte/after_ci.php index 295d7ea0..dba2668a 100644 --- a/src/Psl/Str/Byte/after_ci.php +++ b/src/Psl/Str/Byte/after_ci.php @@ -11,11 +11,8 @@ * * @pure */ -function after_ci( - string $haystack, - string $needle, - int $offset = 0 -): ?string { +function after_ci(string $haystack, string $needle, int $offset = 0): null|string +{ $position = search_ci($haystack, $needle, $offset); if (null === $position) { return null; diff --git a/src/Psl/Str/Byte/after_last.php b/src/Psl/Str/Byte/after_last.php index c4148c01..d5b33ba9 100644 --- a/src/Psl/Str/Byte/after_last.php +++ b/src/Psl/Str/Byte/after_last.php @@ -11,11 +11,8 @@ * * @pure */ -function after_last( - string $haystack, - string $needle, - int $offset = 0 -): ?string { +function after_last(string $haystack, string $needle, int $offset = 0): null|string +{ $position = search_last($haystack, $needle, $offset); if (null === $position) { return null; diff --git a/src/Psl/Str/Byte/after_last_ci.php b/src/Psl/Str/Byte/after_last_ci.php index 03215c41..9b9c2d97 100644 --- a/src/Psl/Str/Byte/after_last_ci.php +++ b/src/Psl/Str/Byte/after_last_ci.php @@ -11,11 +11,8 @@ * * @pure */ -function after_last_ci( - string $haystack, - string $needle, - int $offset = 0 -): ?string { +function after_last_ci(string $haystack, string $needle, int $offset = 0): null|string +{ $position = search_last_ci($haystack, $needle, $offset); if (null === $position) { return null; diff --git a/src/Psl/Str/Byte/before.php b/src/Psl/Str/Byte/before.php index 736e532a..8cec86e3 100644 --- a/src/Psl/Str/Byte/before.php +++ b/src/Psl/Str/Byte/before.php @@ -11,11 +11,8 @@ * * @pure */ -function before( - string $haystack, - string $needle, - int $offset = 0 -): ?string { +function before(string $haystack, string $needle, int $offset = 0): null|string +{ $length = search($haystack, $needle, $offset); if (null === $length) { return null; diff --git a/src/Psl/Str/Byte/before_ci.php b/src/Psl/Str/Byte/before_ci.php index 1e1c7911..8d5b2efd 100644 --- a/src/Psl/Str/Byte/before_ci.php +++ b/src/Psl/Str/Byte/before_ci.php @@ -11,11 +11,8 @@ * * @pure */ -function before_ci( - string $haystack, - string $needle, - int $offset = 0 -): ?string { +function before_ci(string $haystack, string $needle, int $offset = 0): null|string +{ $length = search_ci($haystack, $needle, $offset); if (null === $length) { return null; diff --git a/src/Psl/Str/Byte/before_last.php b/src/Psl/Str/Byte/before_last.php index 00af3149..6af949ec 100644 --- a/src/Psl/Str/Byte/before_last.php +++ b/src/Psl/Str/Byte/before_last.php @@ -11,11 +11,8 @@ * * @pure */ -function before_last( - string $haystack, - string $needle, - int $offset = 0 -): ?string { +function before_last(string $haystack, string $needle, int $offset = 0): null|string +{ $length = search_last($haystack, $needle, $offset); if (null === $length) { return null; diff --git a/src/Psl/Str/Byte/before_last_ci.php b/src/Psl/Str/Byte/before_last_ci.php index de0aad20..52bc9d75 100644 --- a/src/Psl/Str/Byte/before_last_ci.php +++ b/src/Psl/Str/Byte/before_last_ci.php @@ -11,11 +11,8 @@ * * @pure */ -function before_last_ci( - string $haystack, - string $needle, - int $offset = 0 -): ?string { +function before_last_ci(string $haystack, string $needle, int $offset = 0): null|string +{ $length = search_last_ci($haystack, $needle, $offset); if (null === $length) { return null; diff --git a/src/Psl/Str/Byte/compare.php b/src/Psl/Str/Byte/compare.php index 777c87ce..42d201c5 100644 --- a/src/Psl/Str/Byte/compare.php +++ b/src/Psl/Str/Byte/compare.php @@ -16,9 +16,7 @@ * * @pure */ -function compare(string $string, string $other, ?int $length = null): int +function compare(string $string, string $other, null|int $length = null): int { - return null === $length ? - strcmp($string, $other) : - strncmp($string, $other, $length); + return null === $length ? strcmp($string, $other) : strncmp($string, $other, $length); } diff --git a/src/Psl/Str/Byte/compare_ci.php b/src/Psl/Str/Byte/compare_ci.php index 6eeeb529..ac1d94ea 100644 --- a/src/Psl/Str/Byte/compare_ci.php +++ b/src/Psl/Str/Byte/compare_ci.php @@ -16,9 +16,7 @@ * @param int<0, max>|null $length number of characters to use in the comparison, * or null to compare the whole string */ -function compare_ci(string $string, string $other, ?int $length = null): int +function compare_ci(string $string, string $other, null|int $length = null): int { - return null === $length ? - strcasecmp($string, $other) : - strncasecmp($string, $other, $length); + return null === $length ? strcasecmp($string, $other) : strncasecmp($string, $other, $length); } diff --git a/src/Psl/Str/Byte/ends_with_ci.php b/src/Psl/Str/Byte/ends_with_ci.php index 1d70e07e..012f664e 100644 --- a/src/Psl/Str/Byte/ends_with_ci.php +++ b/src/Psl/Str/Byte/ends_with_ci.php @@ -20,6 +20,8 @@ function ends_with_ci(string $string, string $suffix): bool $suffix_length = length($suffix); - return length($string) >= $suffix_length && - 0 === substr_compare($string, $suffix, -$suffix_length, $suffix_length, true); + return ( + length($string) >= $suffix_length && + 0 === substr_compare($string, $suffix, -$suffix_length, $suffix_length, true) + ); } diff --git a/src/Psl/Str/Byte/replace_every.php b/src/Psl/Str/Byte/replace_every.php index 2bf5ebb7..d0642a73 100644 --- a/src/Psl/Str/Byte/replace_every.php +++ b/src/Psl/Str/Byte/replace_every.php @@ -16,10 +16,10 @@ */ function replace_every(string $haystack, array $replacements): string { - $search = []; + $search = []; $replace = []; foreach ($replacements as $k => $v) { - $search[] = $k; + $search[] = $k; $replace[] = $v; } diff --git a/src/Psl/Str/Byte/replace_every_ci.php b/src/Psl/Str/Byte/replace_every_ci.php index 5d4233b4..9ab93103 100644 --- a/src/Psl/Str/Byte/replace_every_ci.php +++ b/src/Psl/Str/Byte/replace_every_ci.php @@ -21,7 +21,7 @@ function replace_every_ci(string $haystack, array $replacements): string /** @var list $replace */ $replace = []; foreach ($replacements as $k => $v) { - $search[] = $k; + $search[] = $k; $replace[] = $v; } diff --git a/src/Psl/Str/Byte/search.php b/src/Psl/Str/Byte/search.php index b9f23c05..2bcce0e5 100644 --- a/src/Psl/Str/Byte/search.php +++ b/src/Psl/Str/Byte/search.php @@ -22,7 +22,7 @@ * * @return null|int<0, max> */ -function search(string $haystack, string $needle, int $offset = 0): ?int +function search(string $haystack, string $needle, int $offset = 0): null|int { $offset = Str\Internal\validate_offset($offset, length($haystack)); diff --git a/src/Psl/Str/Byte/search_ci.php b/src/Psl/Str/Byte/search_ci.php index 3efca602..87db3ab7 100644 --- a/src/Psl/Str/Byte/search_ci.php +++ b/src/Psl/Str/Byte/search_ci.php @@ -22,7 +22,7 @@ * * @return null|int<0, max> */ -function search_ci(string $haystack, string $needle, int $offset = 0): ?int +function search_ci(string $haystack, string $needle, int $offset = 0): null|int { $offset = Str\Internal\validate_offset($offset, length($haystack)); diff --git a/src/Psl/Str/Byte/search_last.php b/src/Psl/Str/Byte/search_last.php index 073c076d..9249bd9f 100644 --- a/src/Psl/Str/Byte/search_last.php +++ b/src/Psl/Str/Byte/search_last.php @@ -24,7 +24,7 @@ * * @return null|int<0, max> */ -function search_last(string $haystack, string $needle, int $offset = 0): ?int +function search_last(string $haystack, string $needle, int $offset = 0): null|int { if ('' === $needle) { return null; diff --git a/src/Psl/Str/Byte/search_last_ci.php b/src/Psl/Str/Byte/search_last_ci.php index a77e0cb1..cadc9a51 100644 --- a/src/Psl/Str/Byte/search_last_ci.php +++ b/src/Psl/Str/Byte/search_last_ci.php @@ -22,7 +22,7 @@ * * @return null|int<0, max> */ -function search_last_ci(string $haystack, string $needle, int $offset = 0): ?int +function search_last_ci(string $haystack, string $needle, int $offset = 0): null|int { if ('' === $needle) { return null; diff --git a/src/Psl/Str/Byte/slice.php b/src/Psl/Str/Byte/slice.php index aaf6d375..d9919154 100644 --- a/src/Psl/Str/Byte/slice.php +++ b/src/Psl/Str/Byte/slice.php @@ -21,7 +21,7 @@ * * @throws Str\Exception\OutOfBoundsException If $offset is out-of-bounds. */ -function slice(string $string, int $offset, ?int $length = null): string +function slice(string $string, int $offset, null|int $length = null): string { $offset = Str\Internal\validate_offset($offset, length($string)); diff --git a/src/Psl/Str/Byte/splice.php b/src/Psl/Str/Byte/splice.php index 464348f1..ccab4286 100644 --- a/src/Psl/Str/Byte/splice.php +++ b/src/Psl/Str/Byte/splice.php @@ -22,7 +22,7 @@ * * @throws Str\Exception\OutOfBoundsException If $offset is out-of-bounds. */ -function splice(string $string, string $replacement, int $offset, ?int $length = null): string +function splice(string $string, string $replacement, int $offset, null|int $length = null): string { $offset = Str\Internal\validate_offset($offset, length($string)); diff --git a/src/Psl/Str/Byte/split.php b/src/Psl/Str/Byte/split.php index 44fdb5c9..430aa807 100644 --- a/src/Psl/Str/Byte/split.php +++ b/src/Psl/Str/Byte/split.php @@ -19,7 +19,7 @@ * * @pure */ -function split(string $string, string $delimiter, ?int $limit = null): array +function split(string $string, string $delimiter, null|int $limit = null): array { if ('' === $delimiter) { if (null === $limit || $limit >= length($string)) { @@ -32,7 +32,7 @@ function split(string $string, string $delimiter, ?int $limit = null): array $length = $limit - 1; - $result = chunk(slice($string, 0, $length)); + $result = chunk(slice($string, 0, $length)); $result[] = slice($string, $length); return $result; diff --git a/src/Psl/Str/Byte/trim.php b/src/Psl/Str/Byte/trim.php index 85b95b38..9de7a59c 100644 --- a/src/Psl/Str/Byte/trim.php +++ b/src/Psl/Str/Byte/trim.php @@ -14,9 +14,7 @@ * * @pure */ -function trim(string $string, ?string $char_mask = null): string +function trim(string $string, null|string $char_mask = null): string { - return null === $char_mask - ? php_trim($string) - : php_trim($string, $char_mask); + return null === $char_mask ? php_trim($string) : php_trim($string, $char_mask); } diff --git a/src/Psl/Str/Byte/trim_left.php b/src/Psl/Str/Byte/trim_left.php index 6b47c7df..402f3e03 100644 --- a/src/Psl/Str/Byte/trim_left.php +++ b/src/Psl/Str/Byte/trim_left.php @@ -14,9 +14,7 @@ * * @pure */ -function trim_left(string $string, ?string $char_mask = null): string +function trim_left(string $string, null|string $char_mask = null): string { - return null === $char_mask - ? ltrim($string) - : ltrim($string, $char_mask); + return null === $char_mask ? ltrim($string) : ltrim($string, $char_mask); } diff --git a/src/Psl/Str/Byte/trim_right.php b/src/Psl/Str/Byte/trim_right.php index 373fd33c..6bb999f6 100644 --- a/src/Psl/Str/Byte/trim_right.php +++ b/src/Psl/Str/Byte/trim_right.php @@ -14,9 +14,7 @@ * * @pure */ -function trim_right(string $string, ?string $char_mask = null): string +function trim_right(string $string, null|string $char_mask = null): string { - return null === $char_mask - ? rtrim($string) - : rtrim($string, $char_mask); + return null === $char_mask ? rtrim($string) : rtrim($string, $char_mask); } diff --git a/src/Psl/Str/Byte/words.php b/src/Psl/Str/Byte/words.php index 27335075..ed61d8b1 100644 --- a/src/Psl/Str/Byte/words.php +++ b/src/Psl/Str/Byte/words.php @@ -16,7 +16,7 @@ * * @pure */ -function words(string $string, ?string $characters_list = null): array +function words(string $string, null|string $characters_list = null): array { if (null === $characters_list) { $words = str_word_count($string, 2); diff --git a/src/Psl/Str/Grapheme/after.php b/src/Psl/Str/Grapheme/after.php index 6c86ec68..38ef660f 100644 --- a/src/Psl/Str/Grapheme/after.php +++ b/src/Psl/Str/Grapheme/after.php @@ -12,7 +12,7 @@ * * @pure */ -function after(string $haystack, string $needle, int $offset = 0): ?string +function after(string $haystack, string $needle, int $offset = 0): null|string { $position = search($haystack, $needle, $offset); if (null === $position) { diff --git a/src/Psl/Str/Grapheme/after_ci.php b/src/Psl/Str/Grapheme/after_ci.php index 29f5952d..fbb43839 100644 --- a/src/Psl/Str/Grapheme/after_ci.php +++ b/src/Psl/Str/Grapheme/after_ci.php @@ -12,7 +12,7 @@ * * @pure */ -function after_ci(string $haystack, string $needle, int $offset = 0): ?string +function after_ci(string $haystack, string $needle, int $offset = 0): null|string { $position = search_ci($haystack, $needle, $offset); if (null === $position) { diff --git a/src/Psl/Str/Grapheme/after_last.php b/src/Psl/Str/Grapheme/after_last.php index 24db7a63..f71511a8 100644 --- a/src/Psl/Str/Grapheme/after_last.php +++ b/src/Psl/Str/Grapheme/after_last.php @@ -12,7 +12,7 @@ * * @pure */ -function after_last(string $haystack, string $needle, int $offset = 0): ?string +function after_last(string $haystack, string $needle, int $offset = 0): null|string { $position = search_last($haystack, $needle, $offset); if (null === $position) { diff --git a/src/Psl/Str/Grapheme/after_last_ci.php b/src/Psl/Str/Grapheme/after_last_ci.php index 7393e9b1..754449ad 100644 --- a/src/Psl/Str/Grapheme/after_last_ci.php +++ b/src/Psl/Str/Grapheme/after_last_ci.php @@ -12,7 +12,7 @@ * * @pure */ -function after_last_ci(string $haystack, string $needle, int $offset = 0): ?string +function after_last_ci(string $haystack, string $needle, int $offset = 0): null|string { $position = search_last_ci($haystack, $needle, $offset); if (null === $position) { diff --git a/src/Psl/Str/Grapheme/before.php b/src/Psl/Str/Grapheme/before.php index dba6414e..7824ed06 100644 --- a/src/Psl/Str/Grapheme/before.php +++ b/src/Psl/Str/Grapheme/before.php @@ -12,7 +12,7 @@ * * @pure */ -function before(string $haystack, string $needle, int $offset = 0): ?string +function before(string $haystack, string $needle, int $offset = 0): null|string { $length = search($haystack, $needle, $offset); if (null === $length) { diff --git a/src/Psl/Str/Grapheme/before_ci.php b/src/Psl/Str/Grapheme/before_ci.php index 4f0f243f..d80b91f0 100644 --- a/src/Psl/Str/Grapheme/before_ci.php +++ b/src/Psl/Str/Grapheme/before_ci.php @@ -12,7 +12,7 @@ * * @pure */ -function before_ci(string $haystack, string $needle, int $offset = 0): ?string +function before_ci(string $haystack, string $needle, int $offset = 0): null|string { $length = search_ci($haystack, $needle, $offset); if (null === $length) { diff --git a/src/Psl/Str/Grapheme/before_last.php b/src/Psl/Str/Grapheme/before_last.php index d9e5059c..152167a9 100644 --- a/src/Psl/Str/Grapheme/before_last.php +++ b/src/Psl/Str/Grapheme/before_last.php @@ -12,7 +12,7 @@ * * @pure */ -function before_last(string $haystack, string $needle, int $offset = 0): ?string +function before_last(string $haystack, string $needle, int $offset = 0): null|string { $length = search_last($haystack, $needle, $offset); if (null === $length) { diff --git a/src/Psl/Str/Grapheme/before_last_ci.php b/src/Psl/Str/Grapheme/before_last_ci.php index 93d691d5..c0d012a7 100644 --- a/src/Psl/Str/Grapheme/before_last_ci.php +++ b/src/Psl/Str/Grapheme/before_last_ci.php @@ -12,7 +12,7 @@ * * @pure */ -function before_last_ci(string $haystack, string $needle, int $offset = 0): ?string +function before_last_ci(string $haystack, string $needle, int $offset = 0): null|string { $length = search_last_ci($haystack, $needle, $offset); if (null === $length) { diff --git a/src/Psl/Str/Grapheme/ends_with.php b/src/Psl/Str/Grapheme/ends_with.php index 519ebba2..b900f327 100644 --- a/src/Psl/Str/Grapheme/ends_with.php +++ b/src/Psl/Str/Grapheme/ends_with.php @@ -20,7 +20,7 @@ function ends_with(string $string, string $suffix): bool } $suffix_length = length($suffix); - $total_length = length($string); + $total_length = length($string); if ($suffix_length > $total_length) { return false; } @@ -31,5 +31,5 @@ function ends_with(string $string, string $suffix): bool return false; } - return $position + $suffix_length === $total_length; + return ($position + $suffix_length) === $total_length; } diff --git a/src/Psl/Str/Grapheme/ends_with_ci.php b/src/Psl/Str/Grapheme/ends_with_ci.php index cb11bfd4..3d6bed7e 100644 --- a/src/Psl/Str/Grapheme/ends_with_ci.php +++ b/src/Psl/Str/Grapheme/ends_with_ci.php @@ -20,7 +20,7 @@ function ends_with_ci(string $string, string $suffix): bool } $suffix_length = length($suffix); - $total_length = length($string); + $total_length = length($string); if ($suffix_length > $total_length) { return false; } @@ -31,5 +31,5 @@ function ends_with_ci(string $string, string $suffix): bool return false; } - return $position + $suffix_length === $total_length; + return ($position + $suffix_length) === $total_length; } diff --git a/src/Psl/Str/Grapheme/range.php b/src/Psl/Str/Grapheme/range.php index 629ae11c..aa1c7c18 100644 --- a/src/Psl/Str/Grapheme/range.php +++ b/src/Psl/Str/Grapheme/range.php @@ -48,7 +48,7 @@ function range(string $string, RangeInterface $range): string /** @var int<0, max> $offset */ $offset = $range->getLowerBound(); } - + if ($range instanceof UpperBoundRangeInterface) { /** @var int<0, max> $length */ $length = $range->getUpperBound() - $offset; diff --git a/src/Psl/Str/Grapheme/reverse.php b/src/Psl/Str/Grapheme/reverse.php index 6a8872d6..b1bf51fc 100644 --- a/src/Psl/Str/Grapheme/reverse.php +++ b/src/Psl/Str/Grapheme/reverse.php @@ -16,7 +16,7 @@ function reverse(string $string): string { $reversed = ''; - $offset = length($string); + $offset = length($string); while ($offset-- > 0) { $reversed .= slice($string, $offset, 1); diff --git a/src/Psl/Str/Grapheme/search.php b/src/Psl/Str/Grapheme/search.php index c091654d..f1cb1bf7 100644 --- a/src/Psl/Str/Grapheme/search.php +++ b/src/Psl/Str/Grapheme/search.php @@ -24,7 +24,7 @@ * * @return null|int<0, max> */ -function search(string $haystack, string $needle, int $offset = 0): ?int +function search(string $haystack, string $needle, int $offset = 0): null|int { if ('' === $needle) { return null; @@ -33,7 +33,5 @@ function search(string $haystack, string $needle, int $offset = 0): ?int $offset = Str\Internal\validate_offset($offset, length($haystack)); /** @var null|int<0, max> */ - return false === ($pos = grapheme_strpos($haystack, $needle, $offset)) ? - null : - $pos; + return false === ($pos = grapheme_strpos($haystack, $needle, $offset)) ? null : $pos; } diff --git a/src/Psl/Str/Grapheme/search_ci.php b/src/Psl/Str/Grapheme/search_ci.php index 309be4de..ec6a4c2e 100644 --- a/src/Psl/Str/Grapheme/search_ci.php +++ b/src/Psl/Str/Grapheme/search_ci.php @@ -24,7 +24,7 @@ * * @return null|int<0, max> */ -function search_ci(string $haystack, string $needle, int $offset = 0): ?int +function search_ci(string $haystack, string $needle, int $offset = 0): null|int { if ('' === $needle) { return null; @@ -33,7 +33,5 @@ function search_ci(string $haystack, string $needle, int $offset = 0): ?int $offset = Str\Internal\validate_offset($offset, length($haystack)); /** @var null|int<0, max> */ - return false === ($pos = grapheme_stripos($haystack, $needle, $offset)) ? - null : - $pos; + return false === ($pos = grapheme_stripos($haystack, $needle, $offset)) ? null : $pos; } diff --git a/src/Psl/Str/Grapheme/search_last.php b/src/Psl/Str/Grapheme/search_last.php index 43811792..d077cf66 100644 --- a/src/Psl/Str/Grapheme/search_last.php +++ b/src/Psl/Str/Grapheme/search_last.php @@ -25,7 +25,7 @@ * * @return null|int<0, max> */ -function search_last(string $haystack, string $needle, int $offset = 0): ?int +function search_last(string $haystack, string $needle, int $offset = 0): null|int { if ('' === $needle) { return null; @@ -34,7 +34,5 @@ function search_last(string $haystack, string $needle, int $offset = 0): ?int $offset = Str\Internal\validate_offset($offset, length($haystack)); /** @var null|int<0, max> */ - return false === ($pos = grapheme_strrpos($haystack, $needle, $offset)) ? - null : - $pos; + return false === ($pos = grapheme_strrpos($haystack, $needle, $offset)) ? null : $pos; } diff --git a/src/Psl/Str/Grapheme/search_last_ci.php b/src/Psl/Str/Grapheme/search_last_ci.php index bfe72ea8..aea74fcd 100644 --- a/src/Psl/Str/Grapheme/search_last_ci.php +++ b/src/Psl/Str/Grapheme/search_last_ci.php @@ -25,7 +25,7 @@ * * @return null|int<0, max> */ -function search_last_ci(string $haystack, string $needle, int $offset = 0): ?int +function search_last_ci(string $haystack, string $needle, int $offset = 0): null|int { if ('' === $needle) { return null; @@ -34,7 +34,5 @@ function search_last_ci(string $haystack, string $needle, int $offset = 0): ?int $offset = Str\Internal\validate_offset($offset, length($haystack)); /** @var null|int<0, max> */ - return false === ($pos = grapheme_strripos($haystack, $needle, $offset)) ? - null : - $pos; + return false === ($pos = grapheme_strripos($haystack, $needle, $offset)) ? null : $pos; } diff --git a/src/Psl/Str/Grapheme/slice.php b/src/Psl/Str/Grapheme/slice.php index dac48252..6744f339 100644 --- a/src/Psl/Str/Grapheme/slice.php +++ b/src/Psl/Str/Grapheme/slice.php @@ -21,10 +21,10 @@ * @throws Str\Exception\OutOfBoundsException If $offset is out-of-bounds. * @throws Str\Exception\InvalidArgumentException If $string is not made of grapheme clusters. */ -function slice(string $string, int $offset, ?int $length = null): string +function slice(string $string, int $offset, null|int $length = null): string { $string_length = length($string); - $offset = Str\Internal\validate_offset($offset, $string_length); + $offset = Str\Internal\validate_offset($offset, $string_length); if (0 === $offset && (null === $length || $string_length <= $length)) { return $string; diff --git a/src/Psl/Str/after.php b/src/Psl/Str/after.php index a019796a..797d5849 100644 --- a/src/Psl/Str/after.php +++ b/src/Psl/Str/after.php @@ -9,7 +9,7 @@ * * @pure */ -function after(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?string +function after(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): null|string { $position = search($haystack, $needle, $offset, $encoding); if (null === $position) { diff --git a/src/Psl/Str/after_ci.php b/src/Psl/Str/after_ci.php index bec05b66..200b4903 100644 --- a/src/Psl/Str/after_ci.php +++ b/src/Psl/Str/after_ci.php @@ -9,7 +9,7 @@ * * @pure */ -function after_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?string +function after_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): null|string { $position = search_ci($haystack, $needle, $offset, $encoding); if (null === $position) { diff --git a/src/Psl/Str/after_last.php b/src/Psl/Str/after_last.php index d0f43749..bbb66ff9 100644 --- a/src/Psl/Str/after_last.php +++ b/src/Psl/Str/after_last.php @@ -9,7 +9,7 @@ * * @pure */ -function after_last(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?string +function after_last(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): null|string { $position = search_last($haystack, $needle, $offset, $encoding); if (null === $position) { diff --git a/src/Psl/Str/after_last_ci.php b/src/Psl/Str/after_last_ci.php index f1a6d795..9b61b076 100644 --- a/src/Psl/Str/after_last_ci.php +++ b/src/Psl/Str/after_last_ci.php @@ -9,8 +9,12 @@ * * @pure */ -function after_last_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?string -{ +function after_last_ci( + string $haystack, + string $needle, + int $offset = 0, + Encoding $encoding = Encoding::Utf8, +): null|string { $position = search_last_ci($haystack, $needle, $offset, $encoding); if (null === $position) { return null; diff --git a/src/Psl/Str/before.php b/src/Psl/Str/before.php index 447a2194..997b4868 100644 --- a/src/Psl/Str/before.php +++ b/src/Psl/Str/before.php @@ -9,7 +9,7 @@ * * @pure */ -function before(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?string +function before(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): null|string { $length = search($haystack, $needle, $offset, $encoding); if (null === $length) { diff --git a/src/Psl/Str/before_ci.php b/src/Psl/Str/before_ci.php index 304faea4..0309d229 100644 --- a/src/Psl/Str/before_ci.php +++ b/src/Psl/Str/before_ci.php @@ -9,7 +9,7 @@ * * @pure */ -function before_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?string +function before_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): null|string { $length = search_ci($haystack, $needle, $offset, $encoding); if (null === $length) { diff --git a/src/Psl/Str/before_last.php b/src/Psl/Str/before_last.php index 4133a049..e67794ff 100644 --- a/src/Psl/Str/before_last.php +++ b/src/Psl/Str/before_last.php @@ -9,8 +9,12 @@ * * @pure */ -function before_last(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?string -{ +function before_last( + string $haystack, + string $needle, + int $offset = 0, + Encoding $encoding = Encoding::Utf8, +): null|string { $length = search_last($haystack, $needle, $offset, $encoding); if (null === $length) { return null; diff --git a/src/Psl/Str/before_last_ci.php b/src/Psl/Str/before_last_ci.php index cc1cd9c3..320bb041 100644 --- a/src/Psl/Str/before_last_ci.php +++ b/src/Psl/Str/before_last_ci.php @@ -9,8 +9,12 @@ * * @pure */ -function before_last_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?string -{ +function before_last_ci( + string $haystack, + string $needle, + int $offset = 0, + Encoding $encoding = Encoding::Utf8, +): null|string { $length = search_last_ci($haystack, $needle, $offset, $encoding); if (null === $length) { return null; diff --git a/src/Psl/Str/capitalize.php b/src/Psl/Str/capitalize.php index 5c4b7440..affe65d6 100644 --- a/src/Psl/Str/capitalize.php +++ b/src/Psl/Str/capitalize.php @@ -34,6 +34,6 @@ function capitalize(string $string, Encoding $encoding = Encoding::Utf8): string return concat( uppercase(slice($string, 0, 1, $encoding), $encoding), - slice($string, 1, length($string, $encoding), $encoding) + slice($string, 1, length($string, $encoding), $encoding), ); } diff --git a/src/Psl/Str/detect_encoding.php b/src/Psl/Str/detect_encoding.php index 074885df..36e35b59 100644 --- a/src/Psl/Str/detect_encoding.php +++ b/src/Psl/Str/detect_encoding.php @@ -16,13 +16,10 @@ * * @pure */ -function detect_encoding(string $string, ?array $encoding_list = null): ?Encoding +function detect_encoding(string $string, null|array $encoding_list = null): null|Encoding { if (null !== $encoding_list) { - $encoding_list = array_map( - static fn(Encoding $encoding): string => $encoding->value, - $encoding_list - ); + $encoding_list = array_map(static fn(Encoding $encoding): string => $encoding->value, $encoding_list); } $encoding = mb_detect_encoding($string, $encoding_list, true); diff --git a/src/Psl/Str/ends_with.php b/src/Psl/Str/ends_with.php index 1597dc8e..539e3173 100644 --- a/src/Psl/Str/ends_with.php +++ b/src/Psl/Str/ends_with.php @@ -39,7 +39,7 @@ function ends_with(string $string, string $suffix, Encoding $encoding = Encoding } $suffix_length = length($suffix, $encoding); - $total_length = length($string, $encoding); + $total_length = length($string, $encoding); if ($suffix_length > $total_length) { return false; } @@ -50,5 +50,5 @@ function ends_with(string $string, string $suffix, Encoding $encoding = Encoding return false; } - return $position + $suffix_length === $total_length; + return ($position + $suffix_length) === $total_length; } diff --git a/src/Psl/Str/ends_with_ci.php b/src/Psl/Str/ends_with_ci.php index 66303aee..f7daa5c5 100644 --- a/src/Psl/Str/ends_with_ci.php +++ b/src/Psl/Str/ends_with_ci.php @@ -39,7 +39,7 @@ function ends_with_ci(string $string, string $suffix, Encoding $encoding = Encod } $suffix_length = length($suffix, $encoding); - $total_length = length($string, $encoding); + $total_length = length($string, $encoding); if ($suffix_length > $total_length) { return false; } @@ -50,5 +50,5 @@ function ends_with_ci(string $string, string $suffix, Encoding $encoding = Encod return false; } - return $position + $suffix_length === $total_length; + return ($position + $suffix_length) === $total_length; } diff --git a/src/Psl/Str/format_number.php b/src/Psl/Str/format_number.php index 0b769fad..efd1665e 100644 --- a/src/Psl/Str/format_number.php +++ b/src/Psl/Str/format_number.php @@ -20,7 +20,7 @@ function format_number( float $number, int $decimals = 0, string $decimal_point = '.', - string $thousands_separator = ',' + string $thousands_separator = ',', ): string { return number_format($number, $decimals, $decimal_point, $thousands_separator); } diff --git a/src/Psl/Str/from_code_points.php b/src/Psl/Str/from_code_points.php index 6327cc86..0c3c4494 100644 --- a/src/Psl/Str/from_code_points.php +++ b/src/Psl/Str/from_code_points.php @@ -21,16 +21,16 @@ function from_code_points(int ...$code_points): string { $string = ''; foreach ($code_points as $code) { - if (0x80 > $code %= 0x200000) { + if (0x80 > ($code %= 0x200000)) { $string .= Byte\chr($code); } elseif (0x800 > $code) { - $string .= Byte\chr(0xC0 | $code >> 6) . Byte\chr(0x80 | $code & 0x3F); + $string .= Byte\chr(0xC0 | ($code >> 6)) . Byte\chr(0x80 | ($code & 0x3F)); } elseif (0x10000 > $code) { - $string .= Byte\chr(0xE0 | $code >> 12) . Byte\chr(0x80 | $code >> 6 & 0x3F); - $string .= Byte\chr(0x80 | $code & 0x3F); + $string .= Byte\chr(0xE0 | ($code >> 12)) . Byte\chr(0x80 | (($code >> 6) & 0x3F)); + $string .= Byte\chr(0x80 | ($code & 0x3F)); } else { - $string .= Byte\chr(0xF0 | $code >> 18) . Byte\chr(0x80 | $code >> 12 & 0x3F); - $string .= Byte\chr(0x80 | $code >> 6 & 0x3F) . Byte\chr(0x80 | $code & 0x3F); + $string .= Byte\chr(0xF0 | ($code >> 18)) . Byte\chr(0x80 | (($code >> 12) & 0x3F)); + $string .= Byte\chr(0x80 | (($code >> 6) & 0x3F)) . Byte\chr(0x80 | ($code & 0x3F)); } } diff --git a/src/Psl/Str/is_empty.php b/src/Psl/Str/is_empty.php index 14a84c0c..144c852c 100644 --- a/src/Psl/Str/is_empty.php +++ b/src/Psl/Str/is_empty.php @@ -26,7 +26,7 @@ * * @pure */ -function is_empty(?string $string): bool +function is_empty(null|string $string): bool { return null === $string || '' === $string; } diff --git a/src/Psl/Str/levenshtein.php b/src/Psl/Str/levenshtein.php index 9cde9455..a6b60abb 100644 --- a/src/Psl/Str/levenshtein.php +++ b/src/Psl/Str/levenshtein.php @@ -29,9 +29,9 @@ function levenshtein( string $source, string $target, - ?int $cost_of_insertion = null, - ?int $cost_of_replacement = null, - ?int $cost_of_deletion = null + null|int $cost_of_insertion = null, + null|int $cost_of_replacement = null, + null|int $cost_of_deletion = null, ): int { if (null === $cost_of_deletion && null === $cost_of_insertion && null === $cost_of_replacement) { return php_levenshtien($source, $target); @@ -40,7 +40,7 @@ function levenshtein( // https://github.com/php/php-src/blob/623911f993f39ebbe75abe2771fc89faf6b15b9b/ext/standard/levenshtein.c#L101 Psl\invariant( null !== $cost_of_deletion && null !== $cost_of_insertion && null !== $cost_of_replacement, - 'Expected either all costs to be supplied, or non.' + 'Expected either all costs to be supplied, or non.', ); return php_levenshtien($source, $target, $cost_of_insertion, $cost_of_replacement, $cost_of_deletion); diff --git a/src/Psl/Str/pad_left.php b/src/Psl/Str/pad_left.php index 670c41af..6ab4b352 100644 --- a/src/Psl/Str/pad_left.php +++ b/src/Psl/Str/pad_left.php @@ -31,8 +31,12 @@ * * @pure */ -function pad_left(string $string, int $total_length, string $pad_string = ' ', Encoding $encoding = Encoding::Utf8): string -{ +function pad_left( + string $string, + int $total_length, + string $pad_string = ' ', + Encoding $encoding = Encoding::Utf8, +): string { while (($length = length($string, $encoding)) < $total_length) { /** @var int<0, max> $remaining */ $remaining = $total_length - $length; diff --git a/src/Psl/Str/pad_right.php b/src/Psl/Str/pad_right.php index 9afcf2c2..f52accea 100644 --- a/src/Psl/Str/pad_right.php +++ b/src/Psl/Str/pad_right.php @@ -31,8 +31,12 @@ * * @pure */ -function pad_right(string $string, int $total_length, string $pad_string = ' ', Encoding $encoding = Encoding::Utf8): string -{ +function pad_right( + string $string, + int $total_length, + string $pad_string = ' ', + Encoding $encoding = Encoding::Utf8, +): string { while (($length = length($string, $encoding)) < $total_length) { /** @var int<0, max> $remaining */ $remaining = $total_length - $length; diff --git a/src/Psl/Str/replace_ci.php b/src/Psl/Str/replace_ci.php index 473c8467..d1aac22b 100644 --- a/src/Psl/Str/replace_ci.php +++ b/src/Psl/Str/replace_ci.php @@ -25,11 +25,12 @@ function replace_ci(string $haystack, string $needle, string $replacement, Encod try { /** @var list */ - $pieces = Regex\Internal\call_preg( - 'preg_split', - static fn() => preg_split('{' . preg_quote($needle, '/') . '}iu', $haystack, -1), - ); - } catch (Regex\Exception\RuntimeException | Regex\Exception\InvalidPatternException $error) { + $pieces = Regex\Internal\call_preg('preg_split', static fn() => preg_split( + '{' . preg_quote($needle, '/') . '}iu', + $haystack, + -1, + )); + } catch (Regex\Exception\RuntimeException|Regex\Exception\InvalidPatternException $error) { throw new Exception\InvalidArgumentException($error->getMessage(), previous: $error); } diff --git a/src/Psl/Str/reverse.php b/src/Psl/Str/reverse.php index 9200a9ef..3a47d6d8 100644 --- a/src/Psl/Str/reverse.php +++ b/src/Psl/Str/reverse.php @@ -13,8 +13,8 @@ */ function reverse(string $string, Encoding $encoding = Encoding::Utf8): string { - $chunks = chunk($string, encoding: $encoding); + $chunks = chunk($string, encoding: $encoding); - /** @psalm-suppress ImpureFunctionCall */ - return join(Vec\reverse($chunks), ''); + /** @psalm-suppress ImpureFunctionCall */ + return join(Vec\reverse($chunks), ''); } diff --git a/src/Psl/Str/search.php b/src/Psl/Str/search.php index 2f6892fa..f43a54e7 100644 --- a/src/Psl/Str/search.php +++ b/src/Psl/Str/search.php @@ -20,7 +20,7 @@ * * @return null|int<0, max> */ -function search(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?int +function search(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): null|int { if ('' === $needle) { return null; @@ -29,7 +29,5 @@ function search(string $haystack, string $needle, int $offset = 0, Encoding $enc $offset = Internal\validate_offset($offset, length($haystack, $encoding)); /** @var null|int<0, max> */ - return false === ($pos = mb_strpos($haystack, $needle, $offset, $encoding->value)) ? - null : - $pos; + return false === ($pos = mb_strpos($haystack, $needle, $offset, $encoding->value)) ? null : $pos; } diff --git a/src/Psl/Str/search_ci.php b/src/Psl/Str/search_ci.php index 3889043c..6bbca1c3 100644 --- a/src/Psl/Str/search_ci.php +++ b/src/Psl/Str/search_ci.php @@ -20,7 +20,7 @@ * * @return null|int<0, max> */ -function search_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?int +function search_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): null|int { if ('' === $needle) { return null; @@ -29,7 +29,5 @@ function search_ci(string $haystack, string $needle, int $offset = 0, Encoding $ $offset = Internal\validate_offset($offset, length($haystack, $encoding)); /** @var null|int<0, max> */ - return false === ($pos = mb_stripos($haystack, $needle, $offset, $encoding->value)) ? - null : - $pos; + return false === ($pos = mb_stripos($haystack, $needle, $offset, $encoding->value)) ? null : $pos; } diff --git a/src/Psl/Str/search_last.php b/src/Psl/Str/search_last.php index 01e7f26f..dd7ff0b3 100644 --- a/src/Psl/Str/search_last.php +++ b/src/Psl/Str/search_last.php @@ -20,7 +20,7 @@ * * @return null|int<0, max> */ -function search_last(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?int +function search_last(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): null|int { if ('' === $needle) { return null; @@ -29,7 +29,5 @@ function search_last(string $haystack, string $needle, int $offset = 0, Encoding $offset = Internal\validate_offset($offset, length($haystack, $encoding)); /** @var null|int<0, max> */ - return false === ($pos = mb_strrpos($haystack, $needle, $offset, $encoding->value)) ? - null : - $pos; + return false === ($pos = mb_strrpos($haystack, $needle, $offset, $encoding->value)) ? null : $pos; } diff --git a/src/Psl/Str/search_last_ci.php b/src/Psl/Str/search_last_ci.php index 21048a47..a1a35910 100644 --- a/src/Psl/Str/search_last_ci.php +++ b/src/Psl/Str/search_last_ci.php @@ -20,8 +20,12 @@ * * @return null|int<0, max> */ -function search_last_ci(string $haystack, string $needle, int $offset = 0, Encoding $encoding = Encoding::Utf8): ?int -{ +function search_last_ci( + string $haystack, + string $needle, + int $offset = 0, + Encoding $encoding = Encoding::Utf8, +): null|int { if ('' === $needle) { return null; } @@ -29,7 +33,5 @@ function search_last_ci(string $haystack, string $needle, int $offset = 0, Encod $offset = Internal\validate_offset($offset, length($haystack, $encoding)); /** @var null|int<0, max> */ - return false === ($pos = mb_strripos($haystack, $needle, $offset, $encoding->value)) ? - null : - $pos; + return false === ($pos = mb_strripos($haystack, $needle, $offset, $encoding->value)) ? null : $pos; } diff --git a/src/Psl/Str/slice.php b/src/Psl/Str/slice.php index cd59f657..097ab41c 100644 --- a/src/Psl/Str/slice.php +++ b/src/Psl/Str/slice.php @@ -20,10 +20,10 @@ * * @pure */ -function slice(string $string, int $offset, ?int $length = null, Encoding $encoding = Encoding::Utf8): string +function slice(string $string, int $offset, null|int $length = null, Encoding $encoding = Encoding::Utf8): string { $string_length = length($string, $encoding); - $offset = Internal\validate_offset($offset, $string_length); + $offset = Internal\validate_offset($offset, $string_length); if (0 === $offset && (null === $length || $string_length <= $length)) { return $string; } diff --git a/src/Psl/Str/splice.php b/src/Psl/Str/splice.php index 09606313..133022e5 100644 --- a/src/Psl/Str/splice.php +++ b/src/Psl/Str/splice.php @@ -22,11 +22,11 @@ function splice( string $string, string $replacement, int $offset = 0, - ?int $length = null, - Encoding $encoding = Encoding::Utf8 + null|int $length = null, + Encoding $encoding = Encoding::Utf8, ): string { $total_length = length($string, $encoding); - $offset = Internal\validate_offset($offset, $total_length); + $offset = Internal\validate_offset($offset, $total_length); if (null === $length || ($offset + $length) >= $total_length) { return slice($string, 0, $offset, $encoding) . $replacement; diff --git a/src/Psl/Str/split.php b/src/Psl/Str/split.php index af586ec2..cbc47972 100644 --- a/src/Psl/Str/split.php +++ b/src/Psl/Str/split.php @@ -19,7 +19,7 @@ * * @pure */ -function split(string $string, string $delimiter, ?int $limit = null, Encoding $encoding = Encoding::Utf8): array +function split(string $string, string $delimiter, null|int $limit = null, Encoding $encoding = Encoding::Utf8): array { if ('' === $delimiter) { if (null === $limit || $limit >= length($string, $encoding)) { @@ -32,7 +32,7 @@ function split(string $string, string $delimiter, ?int $limit = null, Encoding $ $length = $limit - 1; - $result = chunk(slice($string, 0, $length, $encoding), 1, $encoding); + $result = chunk(slice($string, 0, $length, $encoding), 1, $encoding); $result[] = slice($string, $length, null, $encoding); return $result; @@ -40,7 +40,7 @@ function split(string $string, string $delimiter, ?int $limit = null, Encoding $ $limit ??= Math\INT64_MAX; - $tail = $string; + $tail = $string; $chunks = []; /** @@ -50,9 +50,9 @@ function split(string $string, string $delimiter, ?int $limit = null, Encoding $ */ $position = search($tail, $delimiter, 0, $encoding); while (1 < $limit && null !== $position) { - $result = slice($tail, 0, $position, $encoding); + $result = slice($tail, 0, $position, $encoding); $chunks[] = $result; - $tail = slice($tail, length($result, $encoding) + length($delimiter, $encoding), null, $encoding); + $tail = slice($tail, length($result, $encoding) + length($delimiter, $encoding), null, $encoding); $limit--; /** diff --git a/src/Psl/Str/to_int.php b/src/Psl/Str/to_int.php index ff0adce5..d4ace062 100644 --- a/src/Psl/Str/to_int.php +++ b/src/Psl/Str/to_int.php @@ -9,9 +9,9 @@ * * @pure */ -function to_int(string $string): ?int +function to_int(string $string): null|int { - if ((string) (int) $string === $string) { + if (((string) ((int) $string)) === $string) { return (int) $string; } diff --git a/src/Psl/Str/trim.php b/src/Psl/Str/trim.php index f3b41b3e..f111bf48 100644 --- a/src/Psl/Str/trim.php +++ b/src/Psl/Str/trim.php @@ -18,14 +18,14 @@ * * @throws Exception\InvalidArgumentException if $string is not a valid UTF-8 string. */ -function trim(string $string, ?string $char_mask = null): string +function trim(string $string, null|string $char_mask = null): string { $char_mask ??= " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}"; - $char_mask = preg_quote($char_mask, null); + $char_mask = preg_quote($char_mask, null); try { return Regex\replace($string, "{^[{$char_mask}]++|[{$char_mask}]++$}uD", ''); - } catch (Regex\Exception\RuntimeException | Regex\Exception\InvalidPatternException $error) { + } catch (Regex\Exception\RuntimeException|Regex\Exception\InvalidPatternException $error) { throw new Exception\InvalidArgumentException($error->getMessage(), previous: $error); } } diff --git a/src/Psl/Str/trim_left.php b/src/Psl/Str/trim_left.php index c7f62a92..776b3024 100644 --- a/src/Psl/Str/trim_left.php +++ b/src/Psl/Str/trim_left.php @@ -18,14 +18,14 @@ * * @throws Exception\InvalidArgumentException if $string is not a valid UTF-8 string. */ -function trim_left(string $string, ?string $char_mask = null): string +function trim_left(string $string, null|string $char_mask = null): string { $char_mask ??= " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}"; - $char_mask = preg_quote($char_mask, null); + $char_mask = preg_quote($char_mask, null); try { return Regex\replace($string, "{^[{$char_mask}]++}uD", ''); - } catch (Regex\Exception\RuntimeException | Regex\Exception\InvalidPatternException $error) { + } catch (Regex\Exception\RuntimeException|Regex\Exception\InvalidPatternException $error) { throw new Exception\InvalidArgumentException($error->getMessage(), previous: $error); } } diff --git a/src/Psl/Str/trim_right.php b/src/Psl/Str/trim_right.php index 8bdd1e36..cf86c4f5 100644 --- a/src/Psl/Str/trim_right.php +++ b/src/Psl/Str/trim_right.php @@ -18,14 +18,14 @@ * * @throws Exception\InvalidArgumentException if $string is not a valid UTF-8 string. */ -function trim_right(string $string, ?string $char_mask = null): string +function trim_right(string $string, null|string $char_mask = null): string { $char_mask ??= " \t\n\r\0\x0B\x0C\u{A0}\u{FEFF}"; - $char_mask = preg_quote($char_mask, null); + $char_mask = preg_quote($char_mask, null); try { return Regex\replace($string, "{[{$char_mask}]++$}uD", ''); - } catch (Regex\Exception\RuntimeException | Regex\Exception\InvalidPatternException $error) { + } catch (Regex\Exception\RuntimeException|Regex\Exception\InvalidPatternException $error) { throw new Exception\InvalidArgumentException($error->getMessage(), previous: $error); } } diff --git a/src/Psl/Str/truncate.php b/src/Psl/Str/truncate.php index 7f163163..68f580f8 100644 --- a/src/Psl/Str/truncate.php +++ b/src/Psl/Str/truncate.php @@ -26,8 +26,8 @@ function truncate( string $string, int $offset, int $width, - ?string $trim_marker = null, - Encoding $encoding = Encoding::Utf8 + null|string $trim_marker = null, + Encoding $encoding = Encoding::Utf8, ): string { $offset = Internal\validate_offset($offset, length($string, $encoding)); diff --git a/src/Psl/Str/wrap.php b/src/Psl/Str/wrap.php index 52105db7..43eaa6e7 100644 --- a/src/Psl/Str/wrap.php +++ b/src/Psl/Str/wrap.php @@ -17,8 +17,13 @@ * * @pure */ -function wrap(string $string, int $width = 75, string $break = "\n", bool $cut = false, Encoding $encoding = Encoding::Utf8): string -{ +function wrap( + string $string, + int $width = 75, + string $break = "\n", + bool $cut = false, + Encoding $encoding = Encoding::Utf8, +): string { if ('' === $string) { return ''; } @@ -28,11 +33,11 @@ function wrap(string $string, int $width = 75, string $break = "\n", bool $cut = } $string_length = length($string, $encoding); - $break_length = length($break, $encoding); - $result = ''; - $last_start = $last_space = 0; + $break_length = length($break, $encoding); + $result = ''; + $last_start = $last_space = 0; for ($current = 0; $current < $string_length; ++$current) { - $char = slice($string, $current, 1, $encoding); + $char = slice($string, $current, 1, $encoding); $possible_break = $char; if (1 !== $break_length) { $possible_break = slice($string, $current, $break_length, $encoding); @@ -40,8 +45,8 @@ function wrap(string $string, int $width = 75, string $break = "\n", bool $cut = if ($possible_break === $break) { /** @psalm-suppress InvalidArgument - length is positive */ - $result .= slice($string, $last_start, $current - $last_start + $break_length, $encoding); - $current += $break_length - 1; + $result .= slice($string, $last_start, ($current - $last_start) + $break_length, $encoding); + $current += $break_length - 1; $last_start = $last_space = $current + 1; continue; } @@ -49,7 +54,7 @@ function wrap(string $string, int $width = 75, string $break = "\n", bool $cut = if (' ' === $char) { if (($length = $current - $last_start) >= $width) { /** @psalm-suppress InvalidArgument - length is positive */ - $result .= slice($string, $last_start, $length, $encoding) . $break; + $result .= slice($string, $last_start, $length, $encoding) . $break; $last_start = $current + 1; } $last_space = $current; @@ -58,14 +63,14 @@ function wrap(string $string, int $width = 75, string $break = "\n", bool $cut = if (($length = $current - $last_start) >= $width && $cut && $last_start >= $last_space) { /** @psalm-suppress InvalidArgument - length is positive */ - $result .= slice($string, $last_start, $length, $encoding) . $break; + $result .= slice($string, $last_start, $length, $encoding) . $break; $last_start = $last_space = $current; continue; } - if ($current - $last_start >= $width && $last_start < $last_space) { + if (($current - $last_start) >= $width && $last_start < $last_space) { /** @psalm-suppress InvalidArgument - length is positive */ - $result .= slice($string, $last_start, $last_space - $last_start, $encoding) . $break; + $result .= slice($string, $last_start, $last_space - $last_start, $encoding) . $break; $last_start = ++$last_space; } } diff --git a/src/Psl/TCP/Server.php b/src/Psl/TCP/Server.php index cc110c39..8852091c 100644 --- a/src/Psl/TCP/Server.php +++ b/src/Psl/TCP/Server.php @@ -18,22 +18,17 @@ final class Server extends Network\Internal\AbstractStreamServer * * @throws Psl\Network\Exception\RuntimeException In case failed to listen to on given address. */ - public static function create( - string $host, - int $port = 0, - ?ServerOptions $options = null, - ): self { + public static function create(string $host, int $port = 0, null|ServerOptions $options = null): self + { $server_options = $options ?? ServerOptions::create(); $socket_options = $server_options->socketOptions; - $socket_context = [ - 'socket' => [ - 'ipv6_v6only' => true, - 'so_reuseaddr' => OS\is_windows() ? $socket_options->portReuse : $socket_options->addressReuse, - 'so_reuseport' => $socket_options->portReuse, - 'so_broadcast' => $socket_options->broadcast, - 'tcp_nodelay' => $server_options->noDelay, - ] - ]; + $socket_context = ['socket' => [ + 'ipv6_v6only' => true, + 'so_reuseaddr' => OS\is_windows() ? $socket_options->portReuse : $socket_options->addressReuse, + 'so_reuseport' => $socket_options->portReuse, + 'so_broadcast' => $socket_options->broadcast, + 'tcp_nodelay' => $server_options->noDelay, + ]]; $socket = Network\Internal\server_listen("tcp://{$host}:{$port}", $socket_context); diff --git a/src/Psl/TCP/ServerOptions.php b/src/Psl/TCP/ServerOptions.php index ac8cb41b..f33b2f82 100644 --- a/src/Psl/TCP/ServerOptions.php +++ b/src/Psl/TCP/ServerOptions.php @@ -60,7 +60,7 @@ public function __construct(bool $no_delay, int $idle_connections, Network\Socke public static function create( bool $no_delay = false, int $idle_connections = self::DEFAULT_IDLE_CONNECTIONS, - ?Network\SocketOptions $socket_options = null, + null|Network\SocketOptions $socket_options = null, ): ServerOptions { return new self($no_delay, $idle_connections, $socket_options ?? Network\SocketOptions::default()); } diff --git a/src/Psl/TCP/connect.php b/src/Psl/TCP/connect.php index ed26a37d..6cd31515 100644 --- a/src/Psl/TCP/connect.php +++ b/src/Psl/TCP/connect.php @@ -16,15 +16,17 @@ * @throws Network\Exception\RuntimeException If failed to connect to client on the given address. * @throws Network\Exception\TimeoutException If $timeout is non-null, and the operation timed-out. */ -function connect(string $host, int $port = 0, ?ConnectOptions $options = null, ?Duration $timeout = null): Network\StreamSocketInterface -{ +function connect( + string $host, + int $port = 0, + null|ConnectOptions $options = null, + null|Duration $timeout = null, +): Network\StreamSocketInterface { $options ??= ConnectOptions::create(); - $context = [ - 'socket' => [ - 'tcp_nodelay' => $options->noDelay, - ] - ]; + $context = ['socket' => [ + 'tcp_nodelay' => $options->noDelay, + ]]; $socket = Network\Internal\socket_connect("tcp://$host:$port", $context, $timeout); diff --git a/src/Psl/Type/Exception/AssertException.php b/src/Psl/Type/Exception/AssertException.php index 19335c71..59c0c70d 100644 --- a/src/Psl/Type/Exception/AssertException.php +++ b/src/Psl/Type/Exception/AssertException.php @@ -17,20 +17,20 @@ final class AssertException extends Exception /** * @param list $paths */ - private function __construct(string $actual, string $expected, array $paths = [], ?Throwable $previous = null) + private function __construct(string $actual, string $expected, array $paths = [], null|Throwable $previous = null) { - $first = $previous instanceof Exception ? $previous->getFirstFailingActualType() : $actual; + $first = ($previous instanceof Exception) ? $previous->getFirstFailingActualType() : $actual; parent::__construct( Str\format( 'Expected "%s", got "%s"%s.', $expected, $first, - $paths ? ' at path "' . Str\join($paths, '.') . '"' : '' + $paths ? (' at path "' . Str\join($paths, '.') . '"') : '', ), $actual, $paths, - $previous + $previous, ); $this->expected = $expected; @@ -44,10 +44,10 @@ public function getExpectedType(): string public static function withValue( mixed $value, string $expected_type, - ?string $path = null, - ?Throwable $previous = null + null|string $path = null, + null|Throwable $previous = null, ): self { - $paths = $previous instanceof Exception ? [$path, ...$previous->getPaths()] : [$path]; + $paths = ($previous instanceof Exception) ? [$path, ...$previous->getPaths()] : [$path]; return new self(get_debug_type($value), $expected_type, Vec\filter_nulls($paths), $previous); } diff --git a/src/Psl/Type/Exception/CoercionException.php b/src/Psl/Type/Exception/CoercionException.php index 3b8b5c3a..2577fd30 100644 --- a/src/Psl/Type/Exception/CoercionException.php +++ b/src/Psl/Type/Exception/CoercionException.php @@ -17,21 +17,21 @@ final class CoercionException extends Exception /** * @param list $paths */ - private function __construct(string $actual, string $target, array $paths = [], ?Throwable $previous = null) + private function __construct(string $actual, string $target, array $paths = [], null|Throwable $previous = null) { - $first = $previous instanceof Exception ? $previous->getFirstFailingActualType() : $actual; + $first = ($previous instanceof Exception) ? $previous->getFirstFailingActualType() : $actual; parent::__construct( Str\format( 'Could not coerce "%s" to type "%s"%s%s.', $first, $target, - $paths ? ' at path "' . Str\join($paths, '.') . '"' : '', - $previous && !$previous instanceof self ? ': ' . $previous->getMessage() : '', + $paths ? (' at path "' . Str\join($paths, '.') . '"') : '', + $previous && !($previous instanceof self) ? (': ' . $previous->getMessage()) : '', ), $actual, $paths, - $previous + $previous, ); $this->target = $target; @@ -45,10 +45,10 @@ public function getTargetType(): string public static function withValue( mixed $value, string $target, - ?string $path = null, - ?Throwable $previous = null + null|string $path = null, + null|Throwable $previous = null, ): self { - $paths = $previous instanceof Exception ? [$path, ...$previous->getPaths()] : [$path]; + $paths = ($previous instanceof Exception) ? [$path, ...$previous->getPaths()] : [$path]; return new self(get_debug_type($value), $target, Vec\filter_nulls($paths), $previous); } diff --git a/src/Psl/Type/Exception/Exception.php b/src/Psl/Type/Exception/Exception.php index a6251e6f..0439c231 100644 --- a/src/Psl/Type/Exception/Exception.php +++ b/src/Psl/Type/Exception/Exception.php @@ -21,16 +21,12 @@ abstract class Exception extends RuntimeException implements ExceptionInterface /** * @param list $paths */ - protected function __construct( - string $message, - string $actual, - array $paths, - ?Throwable $previous = null - ) { + protected function __construct(string $message, string $actual, array $paths, null|Throwable $previous = null) + { parent::__construct($message, 0, $previous); $this->paths = $paths; - $this->first = $previous instanceof self ? $previous->first : $actual; + $this->first = ($previous instanceof self) ? $previous->first : $actual; $this->actual = $actual; } diff --git a/src/Psl/Type/Internal/BackedEnumType.php b/src/Psl/Type/Internal/BackedEnumType.php index 563122f1..0e596ff2 100644 --- a/src/Psl/Type/Internal/BackedEnumType.php +++ b/src/Psl/Type/Internal/BackedEnumType.php @@ -23,7 +23,7 @@ * @param class-string $enum */ public function __construct( - private readonly string $enum + private readonly string $enum, ) { } @@ -43,7 +43,7 @@ public function coerce(mixed $value): BackedEnum return $value; } - foreach (($this->enum)::cases() as $case) { + foreach ($this->enum::cases() as $case) { if (Type\string()->matches($case->value)) { $string_value = Type\string()->coerce($value); diff --git a/src/Psl/Type/Internal/BackedEnumValueType.php b/src/Psl/Type/Internal/BackedEnumValueType.php index 9db5ec9e..027d9850 100644 --- a/src/Psl/Type/Internal/BackedEnumValueType.php +++ b/src/Psl/Type/Internal/BackedEnumValueType.php @@ -41,7 +41,7 @@ * @throws InvariantViolationException If the given value is not class-string. */ public function __construct( - private string $enum + private string $enum, ) { $this->isStringBacked = $this->hasStringBackingType($this->enum); } @@ -95,9 +95,7 @@ public function matches(mixed $value): bool public function coerce(mixed $value): string|int { try { - $case = $this->isStringBacked - ? string()->coerce($value) - : int()->coerce($value); + $case = $this->isStringBacked ? string()->coerce($value) : int()->coerce($value); if ($this->matches($case)) { return $case; diff --git a/src/Psl/Type/Internal/ClassStringType.php b/src/Psl/Type/Internal/ClassStringType.php index a441849c..c4a471df 100644 --- a/src/Psl/Type/Internal/ClassStringType.php +++ b/src/Psl/Type/Internal/ClassStringType.php @@ -27,9 +27,8 @@ * * @param class-string $classname */ - public function __construct( - string $classname - ) { + public function __construct(string $classname) + { $this->classname = $classname; } diff --git a/src/Psl/Type/Internal/ConvertedType.php b/src/Psl/Type/Internal/ConvertedType.php index 1a40340b..3b21fbb6 100644 --- a/src/Psl/Type/Internal/ConvertedType.php +++ b/src/Psl/Type/Internal/ConvertedType.php @@ -33,7 +33,7 @@ public function __construct( private TypeInterface $from, private TypeInterface $into, - private Closure $converter + private Closure $converter, ) { } @@ -70,7 +70,7 @@ public function coerce(mixed $value): mixed 1 => PathExpression::convert($coercedInput ?? null, $this->into->toString()), default => PathExpression::coerceOutput($converted ?? null, $this->into->toString()), }, - $failure + $failure, ); } } diff --git a/src/Psl/Type/Internal/DictType.php b/src/Psl/Type/Internal/DictType.php index 9847745f..babf559f 100644 --- a/src/Psl/Type/Internal/DictType.php +++ b/src/Psl/Type/Internal/DictType.php @@ -30,7 +30,7 @@ */ public function __construct( private readonly Type\TypeInterface $key_type, - private readonly Type\TypeInterface $value_type + private readonly Type\TypeInterface $value_type, ) { } @@ -41,7 +41,7 @@ public function __construct( */ public function coerce(mixed $value): array { - if (! is_iterable($value)) { + if (!is_iterable($value)) { throw CoercionException::withValue($value, $this->toString()); } @@ -70,9 +70,14 @@ public function coerce(mixed $value): array } } catch (Throwable $e) { throw match (true) { - $iterating => CoercionException::withValue(null, $this->toString(), PathExpression::iteratorError($k), $e), + $iterating => CoercionException::withValue( + null, + $this->toString(), + PathExpression::iteratorError($k), + $e, + ), $trying_key => CoercionException::withValue($k, $this->toString(), PathExpression::iteratorKey($k), $e), - !$trying_key => CoercionException::withValue($v, $this->toString(), PathExpression::path($k), $e) + !$trying_key => CoercionException::withValue($v, $this->toString(), PathExpression::path($k), $e), }; } @@ -88,7 +93,7 @@ public function coerce(mixed $value): array */ public function assert(mixed $value): array { - if (! is_array($value)) { + if (!is_array($value)) { throw AssertException::withValue($value, $this->toString()); } @@ -115,7 +120,7 @@ public function assert(mixed $value): array } catch (AssertException $e) { throw match ($trying_key) { true => AssertException::withValue($k, $this->toString(), PathExpression::iteratorKey($k), $e), - false => AssertException::withValue($v, $this->toString(), PathExpression::path($k), $e) + false => AssertException::withValue($v, $this->toString(), PathExpression::path($k), $e), }; } diff --git a/src/Psl/Type/Internal/FloatType.php b/src/Psl/Type/Internal/FloatType.php index 0621fe7d..228b790a 100644 --- a/src/Psl/Type/Internal/FloatType.php +++ b/src/Psl/Type/Internal/FloatType.php @@ -42,15 +42,15 @@ public function coerce(mixed $value): float return $value; } - if (is_string($value) || (is_object($value) && method_exists($value, '__toString'))) { + if (is_string($value) || is_object($value) && method_exists($value, '__toString')) { $str = (string) $value; if ('' !== $str) { if (ctype_digit($str)) { - return (float)$str; + return (float) $str; } if (1 === preg_match("/^[+-]?(\d+([.]\d*)?([eE][+-]?\d+)?|[.]\d+([eE][+-]?\d+)?)$/", $str)) { - return (float)$str; + return (float) $str; } } } diff --git a/src/Psl/Type/Internal/InstanceOfType.php b/src/Psl/Type/Internal/InstanceOfType.php index 15d8ae92..50d4ad92 100644 --- a/src/Psl/Type/Internal/InstanceOfType.php +++ b/src/Psl/Type/Internal/InstanceOfType.php @@ -27,9 +27,8 @@ * * @param class-string $classname */ - public function __construct( - string $classname - ) { + public function __construct(string $classname) + { $this->classname = $classname; } diff --git a/src/Psl/Type/Internal/IntType.php b/src/Psl/Type/Internal/IntType.php index ec55386d..1fbadc1f 100644 --- a/src/Psl/Type/Internal/IntType.php +++ b/src/Psl/Type/Internal/IntType.php @@ -46,15 +46,15 @@ public function coerce(mixed $value): int } if (is_string($value) || $value instanceof Stringable) { - $str = (string)$value; - $int = (int)$str; - if ($str === (string) $int) { + $str = (string) $value; + $int = (int) $str; + if ($str === ((string) $int)) { return $int; } $trimmed = ltrim($str, '0'); - $int = (int) $trimmed; - if ($trimmed === (string) $int) { + $int = (int) $trimmed; + if ($trimmed === ((string) $int)) { return $int; } diff --git a/src/Psl/Type/Internal/IntersectionType.php b/src/Psl/Type/Internal/IntersectionType.php index cf249013..7c2587e1 100644 --- a/src/Psl/Type/Internal/IntersectionType.php +++ b/src/Psl/Type/Internal/IntersectionType.php @@ -29,7 +29,7 @@ */ public function __construct( private readonly TypeInterface $left_type, - private readonly TypeInterface $right_type + private readonly TypeInterface $right_type, ) { } @@ -93,7 +93,7 @@ public function assert(mixed $value): mixed public function toString(): string { - $left = $this->left_type->toString(); + $left = $this->left_type->toString(); $right = $this->right_type->toString(); /** @psalm-suppress MissingThrowsDocblock - offset is within bound. */ if (Str\contains($left, '|')) { diff --git a/src/Psl/Type/Internal/IterableType.php b/src/Psl/Type/Internal/IterableType.php index accd8d66..6009f635 100644 --- a/src/Psl/Type/Internal/IterableType.php +++ b/src/Psl/Type/Internal/IterableType.php @@ -31,7 +31,7 @@ */ public function __construct( private readonly Type\TypeInterface $key_type, - private readonly Type\TypeInterface $value_type + private readonly Type\TypeInterface $value_type, ) { } @@ -72,18 +72,28 @@ public function coerce(mixed $value): iterable } } catch (Throwable $e) { throw match (true) { - $iterating => CoercionException::withValue(null, $this->toString(), PathExpression::iteratorError($k), $e), - $trying_key => CoercionException::withValue($k, $this->toString(), PathExpression::iteratorKey($k), $e), - !$trying_key => CoercionException::withValue($v, $this->toString(), PathExpression::path($k), $e) + $iterating => CoercionException::withValue( + null, + $this->toString(), + PathExpression::iteratorError($k), + $e, + ), + $trying_key => CoercionException::withValue( + $k, + $this->toString(), + PathExpression::iteratorKey($k), + $e, + ), + !$trying_key => CoercionException::withValue($v, $this->toString(), PathExpression::path($k), $e), }; } /** @var iterable */ - return Iter\Iterator::from((static function () use ($entries) { + return Iter\Iterator::from(static function () use ($entries) { foreach ($entries as [$key, $value]) { yield $key => $value; } - })); + }); } throw CoercionException::withValue($value, $this->toString()); @@ -126,16 +136,16 @@ public function assert(mixed $value): iterable } catch (AssertException $e) { throw match ($trying_key) { true => AssertException::withValue($k, $this->toString(), PathExpression::iteratorKey($k), $e), - false => AssertException::withValue($v, $this->toString(), PathExpression::path($k), $e) + false => AssertException::withValue($v, $this->toString(), PathExpression::path($k), $e), }; } /** @var iterable */ - return Iter\Iterator::from((static function () use ($entries) { + return Iter\Iterator::from(static function () use ($entries) { foreach ($entries as [$key, $value]) { yield $key => $value; } - })); + }); } throw AssertException::withValue($value, $this->toString()); diff --git a/src/Psl/Type/Internal/LiteralScalarType.php b/src/Psl/Type/Internal/LiteralScalarType.php index ec5c0d83..90454010 100644 --- a/src/Psl/Type/Internal/LiteralScalarType.php +++ b/src/Psl/Type/Internal/LiteralScalarType.php @@ -24,7 +24,7 @@ * @param T $value */ public function __construct( - private string|int|float|bool $value + private string|int|float|bool $value, ) { } diff --git a/src/Psl/Type/Internal/MapType.php b/src/Psl/Type/Internal/MapType.php index f2eacb16..31b156e1 100644 --- a/src/Psl/Type/Internal/MapType.php +++ b/src/Psl/Type/Internal/MapType.php @@ -33,7 +33,7 @@ */ public function __construct( private readonly Type\TypeInterface $key_type, - private readonly Type\TypeInterface $value_type + private readonly Type\TypeInterface $value_type, ) { } @@ -53,7 +53,6 @@ public function coerce(mixed $value): Collection\MapInterface /** @var list $entries */ $entries = []; - $k = $v = null; $trying_key = true; $iterating = true; @@ -75,9 +74,19 @@ public function coerce(mixed $value): Collection\MapInterface } } catch (Throwable $e) { throw match (true) { - $iterating => CoercionException::withValue(null, $this->toString(), PathExpression::iteratorError($k), $e), - $trying_key => CoercionException::withValue($k, $this->toString(), PathExpression::iteratorKey($k), $e), - !$trying_key => CoercionException::withValue($v, $this->toString(), PathExpression::path($k), $e) + $iterating => CoercionException::withValue( + null, + $this->toString(), + PathExpression::iteratorError($k), + $e, + ), + $trying_key => CoercionException::withValue( + $k, + $this->toString(), + PathExpression::iteratorKey($k), + $e, + ), + !$trying_key => CoercionException::withValue($v, $this->toString(), PathExpression::path($k), $e), }; } @@ -125,7 +134,7 @@ public function assert(mixed $value): Collection\MapInterface } catch (AssertException $e) { throw match ($trying_key) { true => AssertException::withValue($k, $this->toString(), PathExpression::iteratorKey($k), $e), - false => AssertException::withValue($v, $this->toString(), PathExpression::path($k), $e) + false => AssertException::withValue($v, $this->toString(), PathExpression::path($k), $e), }; } diff --git a/src/Psl/Type/Internal/MixedDictType.php b/src/Psl/Type/Internal/MixedDictType.php index fa25c376..fadb53b9 100644 --- a/src/Psl/Type/Internal/MixedDictType.php +++ b/src/Psl/Type/Internal/MixedDictType.php @@ -23,7 +23,7 @@ */ public function coerce(mixed $value): array { - if (! is_iterable($value)) { + if (!is_iterable($value)) { throw CoercionException::withValue($value, $this->toString()); } @@ -51,12 +51,16 @@ public function coerce(mixed $value): array } } catch (Throwable $e) { throw match (true) { - $iterating => CoercionException::withValue(null, $this->toString(), PathExpression::iteratorError($k), $e), + $iterating => CoercionException::withValue( + null, + $this->toString(), + PathExpression::iteratorError($k), + $e, + ), default => CoercionException::withValue($k, $this->toString(), PathExpression::iteratorKey($k), $e), }; } - return $result; } @@ -69,7 +73,7 @@ public function coerce(mixed $value): array */ public function assert(mixed $value): array { - if (! is_array($value)) { + if (!is_array($value)) { throw AssertException::withValue($value, $this->toString()); } diff --git a/src/Psl/Type/Internal/MixedVecType.php b/src/Psl/Type/Internal/MixedVecType.php index 8ba485d0..42e7b465 100644 --- a/src/Psl/Type/Internal/MixedVecType.php +++ b/src/Psl/Type/Internal/MixedVecType.php @@ -30,12 +30,12 @@ public function matches(mixed $value): bool */ public function coerce(mixed $value): iterable { - if (! is_iterable($value)) { + if (!is_iterable($value)) { throw CoercionException::withValue($value, $this->toString()); } if (is_array($value)) { - if (! array_is_list($value)) { + if (!array_is_list($value)) { return array_values($value); } @@ -68,7 +68,7 @@ public function coerce(mixed $value): iterable */ public function assert(mixed $value): array { - if (! is_array($value) || ! array_is_list($value)) { + if (!is_array($value) || !array_is_list($value)) { throw AssertException::withValue($value, $this->toString()); } diff --git a/src/Psl/Type/Internal/MutableMapType.php b/src/Psl/Type/Internal/MutableMapType.php index 8d947db1..96c3e1d2 100644 --- a/src/Psl/Type/Internal/MutableMapType.php +++ b/src/Psl/Type/Internal/MutableMapType.php @@ -33,7 +33,7 @@ */ public function __construct( private readonly Type\TypeInterface $key_type, - private readonly Type\TypeInterface $value_type + private readonly Type\TypeInterface $value_type, ) { } @@ -74,9 +74,19 @@ public function coerce(mixed $value): Collection\MutableMapInterface } } catch (Throwable $e) { throw match (true) { - $iterating => CoercionException::withValue(null, $this->toString(), PathExpression::iteratorError($k), $e), - $trying_key => CoercionException::withValue($k, $this->toString(), PathExpression::iteratorKey($k), $e), - !$trying_key => CoercionException::withValue($v, $this->toString(), PathExpression::path($k), $e) + $iterating => CoercionException::withValue( + null, + $this->toString(), + PathExpression::iteratorError($k), + $e, + ), + $trying_key => CoercionException::withValue( + $k, + $this->toString(), + PathExpression::iteratorKey($k), + $e, + ), + !$trying_key => CoercionException::withValue($v, $this->toString(), PathExpression::path($k), $e), }; } $dict = Dict\from_entries($entries); @@ -125,7 +135,7 @@ public function assert(mixed $value): Collection\MutableMapInterface } catch (AssertException $e) { throw match ($trying_key) { true => AssertException::withValue($k, $this->toString(), PathExpression::iteratorKey($k), $e), - false => AssertException::withValue($v, $this->toString(), PathExpression::path($k), $e) + false => AssertException::withValue($v, $this->toString(), PathExpression::path($k), $e), }; } diff --git a/src/Psl/Type/Internal/MutableSetType.php b/src/Psl/Type/Internal/MutableSetType.php index dac089f4..a021013b 100644 --- a/src/Psl/Type/Internal/MutableSetType.php +++ b/src/Psl/Type/Internal/MutableSetType.php @@ -117,10 +117,6 @@ public function assert(mixed $value): Collection\MutableSetInterface public function toString(): string { - return Str\format( - '%s<%s>', - Collection\MutableSetInterface::class, - $this->type->toString(), - ); + return Str\format('%s<%s>', Collection\MutableSetInterface::class, $this->type->toString()); } } diff --git a/src/Psl/Type/Internal/MutableVectorType.php b/src/Psl/Type/Internal/MutableVectorType.php index 785507e0..42a350d6 100644 --- a/src/Psl/Type/Internal/MutableVectorType.php +++ b/src/Psl/Type/Internal/MutableVectorType.php @@ -29,7 +29,7 @@ * @param Type\TypeInterface $value_type */ public function __construct( - private readonly Type\TypeInterface $value_type + private readonly Type\TypeInterface $value_type, ) { } @@ -63,8 +63,13 @@ public function coerce(mixed $value): Collection\MutableVectorInterface } } catch (Throwable $e) { throw match (true) { - $iterating => CoercionException::withValue(null, $this->toString(), PathExpression::iteratorError($i), $e), - default => CoercionException::withValue($v, $this->toString(), PathExpression::path($i), $e) + $iterating => CoercionException::withValue( + null, + $this->toString(), + PathExpression::iteratorError($i), + $e, + ), + default => CoercionException::withValue($v, $this->toString(), PathExpression::path($i), $e), }; } @@ -115,10 +120,6 @@ public function assert(mixed $value): Collection\MutableVectorInterface public function toString(): string { - return Str\format( - '%s<%s>', - Collection\MutableVectorInterface::class, - $this->value_type->toString(), - ); + return Str\format('%s<%s>', Collection\MutableVectorInterface::class, $this->value_type->toString()); } } diff --git a/src/Psl/Type/Internal/NonEmptyDictType.php b/src/Psl/Type/Internal/NonEmptyDictType.php index 23aad44e..96ef0b2c 100644 --- a/src/Psl/Type/Internal/NonEmptyDictType.php +++ b/src/Psl/Type/Internal/NonEmptyDictType.php @@ -31,7 +31,7 @@ */ public function __construct( private readonly Type\TypeInterface $key_type, - private readonly Type\TypeInterface $value_type + private readonly Type\TypeInterface $value_type, ) { } @@ -69,9 +69,19 @@ public function coerce(mixed $value): array } } catch (Throwable $e) { throw match (true) { - $iterating => CoercionException::withValue(null, $this->toString(), PathExpression::iteratorError($k), $e), - $trying_key => CoercionException::withValue($k, $this->toString(), PathExpression::iteratorKey($k), $e), - !$trying_key => CoercionException::withValue($v, $this->toString(), PathExpression::path($k), $e) + $iterating => CoercionException::withValue( + null, + $this->toString(), + PathExpression::iteratorError($k), + $e, + ), + $trying_key => CoercionException::withValue( + $k, + $this->toString(), + PathExpression::iteratorKey($k), + $e, + ), + !$trying_key => CoercionException::withValue($v, $this->toString(), PathExpression::path($k), $e), }; } @@ -119,7 +129,7 @@ public function assert(mixed $value): array } catch (AssertException $e) { throw match ($trying_key) { true => AssertException::withValue($k, $this->toString(), PathExpression::iteratorKey($k), $e), - false => AssertException::withValue($v, $this->toString(), PathExpression::path($k), $e) + false => AssertException::withValue($v, $this->toString(), PathExpression::path($k), $e), }; } diff --git a/src/Psl/Type/Internal/NonEmptyStringType.php b/src/Psl/Type/Internal/NonEmptyStringType.php index a3cb1c69..08ca5bf0 100644 --- a/src/Psl/Type/Internal/NonEmptyStringType.php +++ b/src/Psl/Type/Internal/NonEmptyStringType.php @@ -24,8 +24,7 @@ */ public function matches(mixed $value): bool { - return '' !== $value - && is_string($value); + return '' !== $value && is_string($value); } /** diff --git a/src/Psl/Type/Internal/NonEmptyVecType.php b/src/Psl/Type/Internal/NonEmptyVecType.php index 52b44976..8b3ae8f7 100644 --- a/src/Psl/Type/Internal/NonEmptyVecType.php +++ b/src/Psl/Type/Internal/NonEmptyVecType.php @@ -28,7 +28,7 @@ * @param Type\TypeInterface $value_type */ public function __construct( - private readonly Type\TypeInterface $value_type + private readonly Type\TypeInterface $value_type, ) { } @@ -92,8 +92,13 @@ public function coerce(mixed $value): iterable } } catch (Throwable $e) { throw match (true) { - $iterating => CoercionException::withValue(null, $this->toString(), PathExpression::iteratorError($i), $e), - default => CoercionException::withValue($v, $this->toString(), PathExpression::path($i), $e) + $iterating => CoercionException::withValue( + null, + $this->toString(), + PathExpression::iteratorError($i), + $e, + ), + default => CoercionException::withValue($v, $this->toString(), PathExpression::path($i), $e), }; } diff --git a/src/Psl/Type/Internal/NullableType.php b/src/Psl/Type/Internal/NullableType.php index 5cf0b4c2..c2d2b7c1 100644 --- a/src/Psl/Type/Internal/NullableType.php +++ b/src/Psl/Type/Internal/NullableType.php @@ -23,7 +23,7 @@ * @param Type\TypeInterface $inner */ public function __construct( - private readonly Type\TypeInterface $inner + private readonly Type\TypeInterface $inner, ) { } diff --git a/src/Psl/Type/Internal/OptionalType.php b/src/Psl/Type/Internal/OptionalType.php index db3b3111..055fbcd8 100644 --- a/src/Psl/Type/Internal/OptionalType.php +++ b/src/Psl/Type/Internal/OptionalType.php @@ -23,7 +23,7 @@ * @param Type\TypeInterface $inner */ public function __construct( - private Type\TypeInterface $inner + private Type\TypeInterface $inner, ) { } diff --git a/src/Psl/Type/Internal/PositiveIntType.php b/src/Psl/Type/Internal/PositiveIntType.php index 79acbb24..61ad038a 100644 --- a/src/Psl/Type/Internal/PositiveIntType.php +++ b/src/Psl/Type/Internal/PositiveIntType.php @@ -40,8 +40,8 @@ public function coerce(mixed $value): int return $value; } - if (is_string($value) || (is_object($value) && method_exists($value, '__toString'))) { - $str = (string)$value; + if (is_string($value) || is_object($value) && method_exists($value, '__toString')) { + $str = (string) $value; $int = Str\to_int($str); if (null !== $int && $int > 0) { return $int; diff --git a/src/Psl/Type/Internal/ResourceType.php b/src/Psl/Type/Internal/ResourceType.php index 4af47667..dbd148ae 100644 --- a/src/Psl/Type/Internal/ResourceType.php +++ b/src/Psl/Type/Internal/ResourceType.php @@ -22,7 +22,7 @@ * @psalm-mutation-free */ public function __construct( - private ?string $kind = null + private null|string $kind = null, ) { } diff --git a/src/Psl/Type/Internal/ScalarType.php b/src/Psl/Type/Internal/ScalarType.php index cec90cf4..3896b535 100644 --- a/src/Psl/Type/Internal/ScalarType.php +++ b/src/Psl/Type/Internal/ScalarType.php @@ -20,7 +20,7 @@ public function __construct() parent::__construct( /** @psalm-suppress MissingThrowsDocblock */ new UnionType(new StringType(), new BoolType()), - new NumType() + new NumType(), ); } diff --git a/src/Psl/Type/Internal/SetType.php b/src/Psl/Type/Internal/SetType.php index 41cd85b9..80d083a7 100644 --- a/src/Psl/Type/Internal/SetType.php +++ b/src/Psl/Type/Internal/SetType.php @@ -117,10 +117,6 @@ public function assert(mixed $value): Collection\SetInterface public function toString(): string { - return Str\format( - '%s<%s>', - Collection\SetInterface::class, - $this->type->toString(), - ); + return Str\format('%s<%s>', Collection\SetInterface::class, $this->type->toString()); } } diff --git a/src/Psl/Type/Internal/ShapeType.php b/src/Psl/Type/Internal/ShapeType.php index fd24039a..01983e7f 100644 --- a/src/Psl/Type/Internal/ShapeType.php +++ b/src/Psl/Type/Internal/ShapeType.php @@ -45,7 +45,7 @@ public function __construct( /** @psalm-suppress ImpureFunctionCall - This implementation is pure. */ $this->requiredElements = array_filter( $elements_types, - static fn (Type\TypeInterface $element): bool => ! $element->isOptional() + static fn(Type\TypeInterface $element): bool => !$element->isOptional(), ); } @@ -61,7 +61,7 @@ public function coerce(mixed $value): array } // To whom reads this: yes, I hate this stuff as passionately as you do :-) - if (! is_array($value)) { + if (!is_array($value)) { // Fallback to slow implementation - unhappy path return $this->coerceIterable($value); } @@ -71,7 +71,7 @@ public function coerce(mixed $value): array return $this->coerceIterable($value); } - if (! $this->allow_unknown_fields && array_keys($value) !== array_keys($this->elements_types)) { + if (!$this->allow_unknown_fields && array_keys($value) !== array_keys($this->elements_types)) { // Fallback to slow implementation - unhappy path return $this->coerceIterable($value); } @@ -104,7 +104,7 @@ public function coerce(mixed $value): array */ private function coerceIterable(mixed $value): array { - if (! is_iterable($value)) { + if (!is_iterable($value)) { throw CoercionException::withValue($value, $this->toString()); } @@ -125,7 +125,6 @@ private function coerceIterable(mixed $value): array throw CoercionException::withValue(null, $this->toString(), PathExpression::iteratorError($k), $e); } - $result = []; $element = null; $element_value_found = false; @@ -148,8 +147,13 @@ private function coerceIterable(mixed $value): array } } catch (CoercionException $e) { throw match (true) { - $element_value_found => CoercionException::withValue($array[$element] ?? null, $this->toString(), PathExpression::path($element), $e), - default => $e + $element_value_found => CoercionException::withValue( + $array[$element] ?? null, + $this->toString(), + PathExpression::path($element), + $e, + ), + default => $e, }; } @@ -174,7 +178,7 @@ private function coerceIterable(mixed $value): array */ public function assert(mixed $value): array { - if (! is_array($value)) { + if (!is_array($value)) { throw AssertException::withValue($value, $this->toString()); } @@ -200,8 +204,13 @@ public function assert(mixed $value): array } } catch (AssertException $e) { throw match (true) { - $element_value_found => AssertException::withValue($value[$element] ?? null, $this->toString(), PathExpression::path($element), $e), - default => $e + $element_value_found => AssertException::withValue( + $value[$element] ?? null, + $this->toString(), + PathExpression::path($element), + $e, + ), + default => $e, }; } @@ -214,11 +223,7 @@ public function assert(mixed $value): array if ($this->allow_unknown_fields) { $result[$k] = $v; } else { - throw AssertException::withValue( - $v, - $this->toString(), - PathExpression::path($k) - ); + throw AssertException::withValue($v, $this->toString(), PathExpression::path($k)); } } } @@ -234,10 +239,7 @@ public function toString(): string { $nodes = []; foreach ($this->elements_types as $element => $type) { - $nodes[] = $this->getElementName($element) - . ($type->isOptional() ? '?' : '') - . ': ' - . $type->toString(); + $nodes[] = $this->getElementName($element) . ($type->isOptional() ? '?' : '') . ': ' . $type->toString(); } return 'array{' . implode(', ', $nodes) . '}'; @@ -245,8 +247,6 @@ public function toString(): string private function getElementName(string|int $element): string { - return is_int($element) - ? (string) $element - : '\'' . $element . '\''; + return is_int($element) ? ((string) $element) : ('\'' . $element . '\''); } } diff --git a/src/Psl/Type/Internal/UIntType.php b/src/Psl/Type/Internal/UIntType.php index d195cbdc..863ee50c 100644 --- a/src/Psl/Type/Internal/UIntType.php +++ b/src/Psl/Type/Internal/UIntType.php @@ -50,15 +50,15 @@ public function coerce(mixed $value): int return $integer_value; } } elseif (is_string($value) || $value instanceof Stringable) { - $str = (string)$value; - $int = (int)$str; - if ($str === (string) $int && $int >= 0) { + $str = (string) $value; + $int = (int) $str; + if ($str === ((string) $int) && $int >= 0) { return $int; } $trimmed = ltrim($str, '0'); - $int = (int) $trimmed; - if ($trimmed === (string) $int && $int >= 0) { + $int = (int) $trimmed; + if ($trimmed === ((string) $int) && $int >= 0) { return $int; } diff --git a/src/Psl/Type/Internal/UnionType.php b/src/Psl/Type/Internal/UnionType.php index 79047c9a..a9a8c8a7 100644 --- a/src/Psl/Type/Internal/UnionType.php +++ b/src/Psl/Type/Internal/UnionType.php @@ -27,7 +27,7 @@ */ public function __construct( private readonly Type\TypeInterface $left_type, - private readonly Type\TypeInterface $right_type + private readonly Type\TypeInterface $right_type, ) { } @@ -93,7 +93,7 @@ public function assert(mixed $value): mixed public function toString(): string { - $left = $this->left_type->toString(); + $left = $this->left_type->toString(); $right = $this->right_type->toString(); /** @psalm-suppress MissingThrowsDocblock - offset is within bound. */ if (Str\contains($left, '&')) { diff --git a/src/Psl/Type/Internal/UnitEnumType.php b/src/Psl/Type/Internal/UnitEnumType.php index e61d60ce..1fad9bc1 100644 --- a/src/Psl/Type/Internal/UnitEnumType.php +++ b/src/Psl/Type/Internal/UnitEnumType.php @@ -23,7 +23,7 @@ * @param class-string $enum */ public function __construct( - private readonly string $enum + private readonly string $enum, ) { } diff --git a/src/Psl/Type/Internal/VecType.php b/src/Psl/Type/Internal/VecType.php index 60c0bf19..a7024074 100644 --- a/src/Psl/Type/Internal/VecType.php +++ b/src/Psl/Type/Internal/VecType.php @@ -28,7 +28,7 @@ * @param Type\TypeInterface $value_type */ public function __construct( - private readonly Type\TypeInterface $value_type + private readonly Type\TypeInterface $value_type, ) { } @@ -57,7 +57,7 @@ public function matches(mixed $value): bool */ public function coerce(mixed $value): iterable { - if (! is_iterable($value)) { + if (!is_iterable($value)) { throw CoercionException::withValue($value, $this->toString()); } @@ -81,8 +81,13 @@ public function coerce(mixed $value): iterable } } catch (Throwable $e) { throw match (true) { - $iterating => CoercionException::withValue(null, $this->toString(), PathExpression::iteratorError($i), $e), - default => CoercionException::withValue($v, $this->toString(), PathExpression::path($i), $e) + $iterating => CoercionException::withValue( + null, + $this->toString(), + PathExpression::iteratorError($i), + $e, + ), + default => CoercionException::withValue($v, $this->toString(), PathExpression::path($i), $e), }; } @@ -98,7 +103,7 @@ public function coerce(mixed $value): iterable */ public function assert(mixed $value): array { - if (! is_array($value) || !array_is_list($value)) { + if (!is_array($value) || !array_is_list($value)) { throw AssertException::withValue($value, $this->toString()); } diff --git a/src/Psl/Type/Internal/VectorType.php b/src/Psl/Type/Internal/VectorType.php index 9fe59e49..dbeda2e6 100644 --- a/src/Psl/Type/Internal/VectorType.php +++ b/src/Psl/Type/Internal/VectorType.php @@ -29,7 +29,7 @@ * @param Type\TypeInterface $value_type */ public function __construct( - private readonly Type\TypeInterface $value_type + private readonly Type\TypeInterface $value_type, ) { } @@ -63,8 +63,13 @@ public function coerce(mixed $value): Collection\VectorInterface } } catch (Throwable $e) { throw match (true) { - $iterating => CoercionException::withValue(null, $this->toString(), PathExpression::iteratorError($i), $e), - default => CoercionException::withValue($v, $this->toString(), PathExpression::path($i), $e) + $iterating => CoercionException::withValue( + null, + $this->toString(), + PathExpression::iteratorError($i), + $e, + ), + default => CoercionException::withValue($v, $this->toString(), PathExpression::path($i), $e), }; } @@ -117,10 +122,6 @@ public function assert(mixed $value): Collection\VectorInterface public function toString(): string { - return Str\format( - '%s<%s>', - Collection\VectorInterface::class, - $this->value_type->toString(), - ); + return Str\format('%s<%s>', Collection\VectorInterface::class, $this->value_type->toString()); } } diff --git a/src/Psl/Type/intersection.php b/src/Psl/Type/intersection.php index 454764e0..ba2051bd 100644 --- a/src/Psl/Type/intersection.php +++ b/src/Psl/Type/intersection.php @@ -17,11 +17,8 @@ * * @return TypeInterface */ -function intersection( - TypeInterface $first, - TypeInterface $second, - TypeInterface ...$rest -): TypeInterface { +function intersection(TypeInterface $first, TypeInterface $second, TypeInterface ...$rest): TypeInterface +{ $accumulated_type = new Internal\IntersectionType($first, $second); foreach ($rest as $type) { diff --git a/src/Psl/Type/resource.php b/src/Psl/Type/resource.php index c0ffcbe7..f6613404 100644 --- a/src/Psl/Type/resource.php +++ b/src/Psl/Type/resource.php @@ -11,7 +11,7 @@ * * @return TypeInterface */ -function resource(?string $kind = null): TypeInterface +function resource(null|string $kind = null): TypeInterface { return new Internal\ResourceType($kind); } diff --git a/src/Psl/Type/union.php b/src/Psl/Type/union.php index f5d7cc3f..abed7302 100644 --- a/src/Psl/Type/union.php +++ b/src/Psl/Type/union.php @@ -15,11 +15,8 @@ * * @return TypeInterface */ -function union( - TypeInterface $first, - TypeInterface $second, - TypeInterface ...$rest -): TypeInterface { +function union(TypeInterface $first, TypeInterface $second, TypeInterface ...$rest): TypeInterface +{ $accumulated_type = new Internal\UnionType($first, $second); foreach ($rest as $type) { diff --git a/src/Psl/Unix/connect.php b/src/Psl/Unix/connect.php index 9ceb71ed..0db4ba28 100644 --- a/src/Psl/Unix/connect.php +++ b/src/Psl/Unix/connect.php @@ -16,7 +16,7 @@ * @throws Network\Exception\RuntimeException If failed to connect to client on the given address. * @throws Network\Exception\TimeoutException If $timeout is non-null, and the operation timed-out. */ -function connect(string $path, ?Duration $timeout = null): Network\StreamSocketInterface +function connect(string $path, null|Duration $timeout = null): Network\StreamSocketInterface { // @codeCoverageIgnoreStart if (OS\is_windows()) { diff --git a/src/Psl/Vec/chunk.php b/src/Psl/Vec/chunk.php index 2c5d09e5..65668c0e 100644 --- a/src/Psl/Vec/chunk.php +++ b/src/Psl/Vec/chunk.php @@ -24,7 +24,7 @@ function chunk(iterable $iterable, int $size): array $ii = 0; $chunk_number = -1; foreach ($iterable as $value) { - if ($ii % $size === 0) { + if (($ii % $size) === 0) { $result[] = []; $chunk_number++; } diff --git a/src/Psl/Vec/chunk_with_keys.php b/src/Psl/Vec/chunk_with_keys.php index 4adde763..b335de5e 100644 --- a/src/Psl/Vec/chunk_with_keys.php +++ b/src/Psl/Vec/chunk_with_keys.php @@ -26,7 +26,7 @@ function chunk_with_keys(iterable $iterable, int $size): array $ii = 0; $chunk_number = -1; foreach ($iterable as $k => $value) { - if ($ii % $size === 0) { + if (($ii % $size) === 0) { $result[] = []; $chunk_number++; } diff --git a/src/Psl/Vec/filter.php b/src/Psl/Vec/filter.php index 3532a97b..d1bccacb 100644 --- a/src/Psl/Vec/filter.php +++ b/src/Psl/Vec/filter.php @@ -31,7 +31,7 @@ * * @return list */ -function filter(iterable $iterable, ?Closure $predicate = null): array +function filter(iterable $iterable, null|Closure $predicate = null): array { /** @var (Closure(T): bool) $predicate */ $predicate = $predicate ?? static fn(mixed $value): bool => (bool) $value; @@ -41,11 +41,11 @@ function filter(iterable $iterable, ?Closure $predicate = null): array /** * @param T $t */ - static fn(mixed $t): bool => $predicate($t) + static fn(mixed $t): bool => $predicate($t), )); } - $result = []; + $result = []; foreach ($iterable as $v) { if ($predicate($v)) { $result[] = $v; diff --git a/src/Psl/Vec/filter_keys.php b/src/Psl/Vec/filter_keys.php index 627d3252..afdd73ba 100644 --- a/src/Psl/Vec/filter_keys.php +++ b/src/Psl/Vec/filter_keys.php @@ -34,7 +34,7 @@ * * @return list */ -function filter_keys(iterable $iterable, ?Closure $predicate = null): array +function filter_keys(iterable $iterable, null|Closure $predicate = null): array { /** @var (Closure(Tk): bool) $predicate */ $predicate = $predicate ?? static fn(mixed $value): bool => (bool) $value; @@ -45,11 +45,11 @@ function filter_keys(iterable $iterable, ?Closure $predicate = null): array * @param Tk $t */ static fn($t): bool => $predicate($t), - ARRAY_FILTER_USE_KEY + ARRAY_FILTER_USE_KEY, )); } - $result = []; + $result = []; foreach ($iterable as $k => $v) { if ($predicate($k)) { $result[] = $v; diff --git a/src/Psl/Vec/filter_nulls.php b/src/Psl/Vec/filter_nulls.php index fd0cc4c6..767ff0d9 100644 --- a/src/Psl/Vec/filter_nulls.php +++ b/src/Psl/Vec/filter_nulls.php @@ -25,6 +25,6 @@ function filter_nulls(iterable $iterable): array /** * @param T|null $value */ - static fn($value): bool => null !== $value + static fn($value): bool => null !== $value, ); } diff --git a/src/Psl/Vec/filter_with_key.php b/src/Psl/Vec/filter_with_key.php index 8555fc92..0e70c30a 100644 --- a/src/Psl/Vec/filter_with_key.php +++ b/src/Psl/Vec/filter_with_key.php @@ -37,14 +37,15 @@ * * @return list */ -function filter_with_key(iterable $iterable, ?Closure $predicate = null): array +function filter_with_key(iterable $iterable, null|Closure $predicate = null): array { - $predicate = $predicate ?? + $predicate = + $predicate ?? /** * @param Tk $_k * @param Tv $v */ - static fn (mixed $_k, mixed $v): bool => (bool) $v; + static fn(mixed $_k, mixed $v): bool => (bool) $v; if (is_array($iterable)) { return array_values(array_filter( @@ -54,7 +55,7 @@ function filter_with_key(iterable $iterable, ?Closure $predicate = null): array * @param Tk $k */ static fn($v, $k): bool => $predicate($k, $v), - ARRAY_FILTER_USE_BOTH + ARRAY_FILTER_USE_BOTH, )); } diff --git a/src/Psl/Vec/map.php b/src/Psl/Vec/map.php index d7e2a8f4..6f2ecb2f 100644 --- a/src/Psl/Vec/map.php +++ b/src/Psl/Vec/map.php @@ -38,7 +38,7 @@ function map(iterable $iterable, Closure $function): array * @param Tv $v */ static fn($v) => $function($v), - $iterable + $iterable, )); } diff --git a/src/Psl/Vec/range.php b/src/Psl/Vec/range.php index 59b1e79a..ab92ce35 100644 --- a/src/Psl/Vec/range.php +++ b/src/Psl/Vec/range.php @@ -47,7 +47,7 @@ */ function range(int|float $start, int|float $end, int|float|null $step = null): array { - if ((float) $start === (float) $end) { + if (((float) $start) === ((float) $end)) { return [$start]; } diff --git a/src/Psl/Vec/reverse.php b/src/Psl/Vec/reverse.php index 9788c2af..14f36ea4 100644 --- a/src/Psl/Vec/reverse.php +++ b/src/Psl/Vec/reverse.php @@ -26,7 +26,7 @@ function reverse(iterable $iterable): array return []; } - $size = Iter\count($values); + $size = Iter\count($values); $result = []; for ($i = $size - 1; $i >= 0; $i--) { $result[] = $values[$i]; diff --git a/src/Psl/Vec/slice.php b/src/Psl/Vec/slice.php index bcfd979a..c7f5e8d3 100644 --- a/src/Psl/Vec/slice.php +++ b/src/Psl/Vec/slice.php @@ -23,7 +23,7 @@ * * @return list */ -function slice(iterable $iterable, int $start, ?int $length = null): array +function slice(iterable $iterable, int $start, null|int $length = null): array { $result = []; if (0 === $length) { @@ -37,7 +37,7 @@ function slice(iterable $iterable, int $start, ?int $length = null): array } $result[] = $value; - if (null !== $length && $i >= $start + $length) { + if (null !== $length && $i >= ($start + $length)) { break; } } diff --git a/src/Psl/Vec/sort.php b/src/Psl/Vec/sort.php index 7139919c..1348db1e 100644 --- a/src/Psl/Vec/sort.php +++ b/src/Psl/Vec/sort.php @@ -22,7 +22,7 @@ * * @return list */ -function sort(iterable $iterable, ?Closure $comparator = null): array +function sort(iterable $iterable, null|Closure $comparator = null): array { $array = values($iterable); if (null !== $comparator) { diff --git a/src/Psl/Vec/sort_by.php b/src/Psl/Vec/sort_by.php index 0a8d754a..cff51e40 100644 --- a/src/Psl/Vec/sort_by.php +++ b/src/Psl/Vec/sort_by.php @@ -25,7 +25,7 @@ * * @return list */ -function sort_by(iterable $iterable, Closure $scalar_func, ?Closure $comparator = null): array +function sort_by(iterable $iterable, Closure $scalar_func, null|Closure $comparator = null): array { /** @var array $order_by */ $order_by = []; diff --git a/src/Psl/Vec/unique_scalar.php b/src/Psl/Vec/unique_scalar.php index 81c35f9e..007e46fe 100644 --- a/src/Psl/Vec/unique_scalar.php +++ b/src/Psl/Vec/unique_scalar.php @@ -32,6 +32,6 @@ function unique_scalar(iterable $iterable): array * * @pure */ - static fn($v) => $v + static fn($v) => $v, ); } diff --git a/tests/benchmark/Type/ArrayKeyTypeBench.php b/tests/benchmark/Type/ArrayKeyTypeBench.php index 5606b927..b67244f8 100644 --- a/tests/benchmark/Type/ArrayKeyTypeBench.php +++ b/tests/benchmark/Type/ArrayKeyTypeBench.php @@ -20,19 +20,16 @@ final class ArrayKeyTypeBench extends GenericTypeBench */ public function provideHappyPathCoercion(): array { - return array_merge( - $this->strictlyValidDataSet(), - [ - 'instanceof Stringable (explicit)' => [ - 'type' => Type\array_key(), - 'value' => new ImplicitStringableObject(), - ], - 'instanceof Stringable (implicit)' => [ - 'type' => Type\array_key(), - 'value' => new ExplicitStringableObject(), - ], - ] - ); + return array_merge($this->strictlyValidDataSet(), [ + 'instanceof Stringable (explicit)' => [ + 'type' => Type\array_key(), + 'value' => new ImplicitStringableObject(), + ], + 'instanceof Stringable (implicit)' => [ + 'type' => Type\array_key(), + 'value' => new ExplicitStringableObject(), + ], + ]); } /** @@ -58,11 +55,11 @@ private function strictlyValidDataSet(): array { return [ 'string' => [ - 'type' => Type\array_key(), + 'type' => Type\array_key(), 'value' => 'foo', ], - 'int' => [ - 'type' => Type\array_key(), + 'int' => [ + 'type' => Type\array_key(), 'value' => 123, ], ]; diff --git a/tests/benchmark/Type/DictTypeBench.php b/tests/benchmark/Type/DictTypeBench.php index 6a81ce3d..4bc2cbcf 100644 --- a/tests/benchmark/Type/DictTypeBench.php +++ b/tests/benchmark/Type/DictTypeBench.php @@ -27,7 +27,7 @@ public function provideHappyPathCoercion(): array $arraysAndIterables[$key . ' array'] = $pair; $arraysAndIterables[$key . ' iterable'] = [ 'type' => $pair['type'], - 'value' => new ArrayIterator($pair['value']) + 'value' => new ArrayIterator($pair['value']), ]; } @@ -107,7 +107,7 @@ private function arrayDataSet(): array 'map, large' => [ 'type' => Type\dict(Type\string(), Type\mixed()), 'value' => Dict\associate( - Vec\map(Vec\range(0, 99), static fn (int $key): string => 'key' . (string) $key), + Vec\map(Vec\range(0, 99), static fn(int $key): string => 'key' . ((string) $key)), Vec\fill(100, null), ), ], diff --git a/tests/benchmark/Type/IntTypeBench.php b/tests/benchmark/Type/IntTypeBench.php index 35e6d039..cfd653f1 100644 --- a/tests/benchmark/Type/IntTypeBench.php +++ b/tests/benchmark/Type/IntTypeBench.php @@ -20,27 +20,24 @@ final class IntTypeBench extends GenericTypeBench */ public function provideHappyPathCoercion(): array { - return array_merge( - $this->strictlyValidDataSet(), - [ - 'string' => [ - 'type' => Type\int(), - 'value' => '123', - ], - 'float' => [ - 'type' => Type\int(), - 'value' => 123.0, - ], - 'instanceof Stringable (explicit)' => [ - 'type' => Type\int(), - 'value' => new ImplicitStringableObject(), - ], - 'instanceof Stringable (implicit)' => [ - 'type' => Type\int(), - 'value' => new ExplicitStringableObject(), - ], - ] - ); + return array_merge($this->strictlyValidDataSet(), [ + 'string' => [ + 'type' => Type\int(), + 'value' => '123', + ], + 'float' => [ + 'type' => Type\int(), + 'value' => 123.0, + ], + 'instanceof Stringable (explicit)' => [ + 'type' => Type\int(), + 'value' => new ImplicitStringableObject(), + ], + 'instanceof Stringable (implicit)' => [ + 'type' => Type\int(), + 'value' => new ExplicitStringableObject(), + ], + ]); } /** @@ -64,11 +61,9 @@ public function provideHappyPathMatches(): array */ private function strictlyValidDataSet(): array { - return [ - 'int' => [ - 'type' => Type\int(), - 'value' => 123, - ], - ]; + return ['int' => [ + 'type' => Type\int(), + 'value' => 123, + ]]; } } diff --git a/tests/benchmark/Type/NonEmptyStringTypeBench.php b/tests/benchmark/Type/NonEmptyStringTypeBench.php index bc079d50..7e2ddb69 100644 --- a/tests/benchmark/Type/NonEmptyStringTypeBench.php +++ b/tests/benchmark/Type/NonEmptyStringTypeBench.php @@ -20,23 +20,20 @@ final class NonEmptyStringTypeBench extends GenericTypeBench */ public function provideHappyPathCoercion(): array { - return array_merge( - $this->strictlyValidDataSet(), - [ - 'int' => [ - 'type' => Type\non_empty_string(), - 'value' => 123, - ], - 'instanceof Stringable (explicit)' => [ - 'type' => Type\non_empty_string(), - 'value' => new ImplicitStringableObject(), - ], - 'instanceof Stringable (implicit)' => [ - 'type' => Type\non_empty_string(), - 'value' => new ExplicitStringableObject(), - ], - ] - ); + return array_merge($this->strictlyValidDataSet(), [ + 'int' => [ + 'type' => Type\non_empty_string(), + 'value' => 123, + ], + 'instanceof Stringable (explicit)' => [ + 'type' => Type\non_empty_string(), + 'value' => new ImplicitStringableObject(), + ], + 'instanceof Stringable (implicit)' => [ + 'type' => Type\non_empty_string(), + 'value' => new ExplicitStringableObject(), + ], + ]); } /** @@ -60,11 +57,9 @@ public function provideHappyPathMatches(): array */ private function strictlyValidDataSet(): array { - return [ - 'string' => [ - 'type' => Type\non_empty_string(), - 'value' => 'foo', - ], - ]; + return ['string' => [ + 'type' => Type\non_empty_string(), + 'value' => 'foo', + ]]; } } diff --git a/tests/benchmark/Type/ShapeTypeBench.php b/tests/benchmark/Type/ShapeTypeBench.php index 88fd79ca..5c8eb54f 100644 --- a/tests/benchmark/Type/ShapeTypeBench.php +++ b/tests/benchmark/Type/ShapeTypeBench.php @@ -37,12 +37,15 @@ public function provideHappyPathCoercion(): array 'value' => new ArrayIterator(['foo' => 'bar']), ], 'complex shape with optional values, minimum array value' => [ - 'type' => Type\shape([ - 'foo' => Type\mixed(), - 'bar' => Type\mixed(), - 'baz' => Type\mixed(), - 'tab' => Type\optional(Type\mixed()), - ], true), + 'type' => Type\shape( + [ + 'foo' => Type\mixed(), + 'bar' => Type\mixed(), + 'baz' => Type\mixed(), + 'tab' => Type\optional(Type\mixed()), + ], + true, + ), 'value' => [ 'foo' => null, 'bar' => null, @@ -50,12 +53,15 @@ public function provideHappyPathCoercion(): array ], ], 'complex shape with optional values, minimum iterable value' => [ - 'type' => Type\shape([ - 'foo' => Type\mixed(), - 'bar' => Type\mixed(), - 'baz' => Type\mixed(), - 'tab' => Type\optional(Type\mixed()), - ], true), + 'type' => Type\shape( + [ + 'foo' => Type\mixed(), + 'bar' => Type\mixed(), + 'baz' => Type\mixed(), + 'tab' => Type\optional(Type\mixed()), + ], + true, + ), 'value' => new ArrayIterator([ 'foo' => null, 'bar' => null, @@ -63,12 +69,15 @@ public function provideHappyPathCoercion(): array ]), ], 'complex shape with optional values, array value with further values' => [ - 'type' => Type\shape([ - 'foo' => Type\mixed(), - 'bar' => Type\mixed(), - 'baz' => Type\mixed(), - 'tab' => Type\optional(Type\mixed()), - ], true), + 'type' => Type\shape( + [ + 'foo' => Type\mixed(), + 'bar' => Type\mixed(), + 'baz' => Type\mixed(), + 'tab' => Type\optional(Type\mixed()), + ], + true, + ), 'value' => [ 'foo' => null, 'bar' => null, @@ -81,12 +90,15 @@ public function provideHappyPathCoercion(): array ], ], 'complex shape with optional values, iterable value with further values' => [ - 'type' => Type\shape([ - 'foo' => Type\mixed(), - 'bar' => Type\mixed(), - 'baz' => Type\mixed(), - 'tab' => Type\optional(Type\mixed()), - ], true), + 'type' => Type\shape( + [ + 'foo' => Type\mixed(), + 'bar' => Type\mixed(), + 'baz' => Type\mixed(), + 'tab' => Type\optional(Type\mixed()), + ], + true, + ), 'value' => new ArrayIterator([ 'foo' => null, 'bar' => null, @@ -107,49 +119,46 @@ public function provideHappyPathCoercion(): array 'likes' => Type\int(), 'comments' => Type\optional(Type\vec(Type\shape([ 'user' => Type\string(), - 'comment' => Type\string() + 'comment' => Type\string(), ]))), ])), - 'dictionary' => Type\dict(Type\string(), Type\vec(Type\shape([ - 'title' => Type\string(), - 'content' => Type\string(), - ]))), + 'dictionary' => Type\dict( + Type\string(), + Type\vec(Type\shape([ + 'title' => Type\string(), + 'content' => Type\string(), + ])), + ), 'pagination' => Type\optional(Type\shape([ 'currentPage' => Type\uint(), 'totalPages' => Type\uint(), 'perPage' => Type\uint(), 'totalRows' => Type\uint(), - ])) + ])), ]), 'value' => [ 'name' => 'ok', - 'articles' => [ - [ - 'title' => 'ok', - 'content' => 'ok', - 'likes' => 1, - 'comments' => [ - [ - 'user' => 'ok', - 'comment' => 'ok' - ], - [ - 'user' => 'ok', - 'comment' => 'ok', - ] - ] - ] - ], - 'dictionary' => [ - 'key' => [ + 'articles' => [[ + 'title' => 'ok', + 'content' => 'ok', + 'likes' => 1, + 'comments' => [ + [ + 'user' => 'ok', + 'comment' => 'ok', + ], [ - 'title' => 'ok', - 'content' => 'ok', - ] - ] - ] - ] - ] + 'user' => 'ok', + 'comment' => 'ok', + ], + ], + ]], + 'dictionary' => ['key' => [[ + 'title' => 'ok', + 'content' => 'ok', + ]]], + ], + ], ]; } @@ -168,12 +177,15 @@ public function provideHappyPathAssertion(): array 'value' => ['foo' => 'bar'], ], 'complex shape with optional values, minimum array value' => [ - 'type' => Type\shape([ - 'foo' => Type\mixed(), - 'bar' => Type\mixed(), - 'baz' => Type\mixed(), - 'tab' => Type\optional(Type\mixed()), - ], true), + 'type' => Type\shape( + [ + 'foo' => Type\mixed(), + 'bar' => Type\mixed(), + 'baz' => Type\mixed(), + 'tab' => Type\optional(Type\mixed()), + ], + true, + ), 'value' => [ 'foo' => null, 'bar' => null, @@ -181,12 +193,15 @@ public function provideHappyPathAssertion(): array ], ], 'complex shape with optional values, array value with further values' => [ - 'type' => Type\shape([ - 'foo' => Type\mixed(), - 'bar' => Type\mixed(), - 'baz' => Type\mixed(), - 'tab' => Type\optional(Type\mixed()), - ], true), + 'type' => Type\shape( + [ + 'foo' => Type\mixed(), + 'bar' => Type\mixed(), + 'baz' => Type\mixed(), + 'tab' => Type\optional(Type\mixed()), + ], + true, + ), 'value' => [ 'foo' => null, 'bar' => null, @@ -207,49 +222,46 @@ public function provideHappyPathAssertion(): array 'likes' => Type\int(), 'comments' => Type\optional(Type\vec(Type\shape([ 'user' => Type\string(), - 'comment' => Type\string() + 'comment' => Type\string(), ]))), ])), - 'dictionary' => Type\dict(Type\string(), Type\vec(Type\shape([ - 'title' => Type\string(), - 'content' => Type\string(), - ]))), + 'dictionary' => Type\dict( + Type\string(), + Type\vec(Type\shape([ + 'title' => Type\string(), + 'content' => Type\string(), + ])), + ), 'pagination' => Type\optional(Type\shape([ 'currentPage' => Type\uint(), 'totalPages' => Type\uint(), 'perPage' => Type\uint(), 'totalRows' => Type\uint(), - ])) + ])), ]), 'value' => [ 'name' => 'ok', - 'articles' => [ - [ - 'title' => 'ok', - 'content' => 'ok', - 'likes' => 1, - 'comments' => [ - [ - 'user' => 'ok', - 'comment' => 'ok' - ], - [ - 'user' => 'ok', - 'comment' => 'ok', - ] - ] - ] - ], - 'dictionary' => [ - 'key' => [ + 'articles' => [[ + 'title' => 'ok', + 'content' => 'ok', + 'likes' => 1, + 'comments' => [ [ - 'title' => 'ok', - 'content' => 'ok', - ] - ] - ] - ] - ] + 'user' => 'ok', + 'comment' => 'ok', + ], + [ + 'user' => 'ok', + 'comment' => 'ok', + ], + ], + ]], + 'dictionary' => ['key' => [[ + 'title' => 'ok', + 'content' => 'ok', + ]]], + ], + ], ]; } diff --git a/tests/benchmark/Type/StringTypeBench.php b/tests/benchmark/Type/StringTypeBench.php index 6587848d..18182535 100644 --- a/tests/benchmark/Type/StringTypeBench.php +++ b/tests/benchmark/Type/StringTypeBench.php @@ -20,23 +20,20 @@ final class StringTypeBench extends GenericTypeBench */ public function provideHappyPathCoercion(): array { - return array_merge( - $this->strictlyValidDataSet(), - [ - 'int' => [ - 'type' => Type\string(), - 'value' => 123, - ], - 'instanceof Stringable (explicit)' => [ - 'type' => Type\string(), - 'value' => new ImplicitStringableObject(), - ], - 'instanceof Stringable (implicit)' => [ - 'type' => Type\string(), - 'value' => new ExplicitStringableObject(), - ], - ] - ); + return array_merge($this->strictlyValidDataSet(), [ + 'int' => [ + 'type' => Type\string(), + 'value' => 123, + ], + 'instanceof Stringable (explicit)' => [ + 'type' => Type\string(), + 'value' => new ImplicitStringableObject(), + ], + 'instanceof Stringable (implicit)' => [ + 'type' => Type\string(), + 'value' => new ExplicitStringableObject(), + ], + ]); } /** @@ -60,11 +57,9 @@ public function provideHappyPathMatches(): array */ private function strictlyValidDataSet(): array { - return [ - 'string' => [ - 'type' => Type\string(), - 'value' => 'foo', - ], - ]; + return ['string' => [ + 'type' => Type\string(), + 'value' => 'foo', + ]]; } } diff --git a/tests/benchmark/Type/VecTypeBench.php b/tests/benchmark/Type/VecTypeBench.php index e33687af..8268f7da 100644 --- a/tests/benchmark/Type/VecTypeBench.php +++ b/tests/benchmark/Type/VecTypeBench.php @@ -26,7 +26,7 @@ public function provideHappyPathCoercion(): array $arraysAndIterables[$key . ' array'] = $pair; $arraysAndIterables[$key . ' iterable'] = [ 'type' => $pair['type'], - 'value' => new ArrayIterator($pair['value']) + 'value' => new ArrayIterator($pair['value']), ]; } diff --git a/tests/fixture/Point.php b/tests/fixture/Point.php index edbc5822..26131e63 100644 --- a/tests/fixture/Point.php +++ b/tests/fixture/Point.php @@ -4,11 +4,11 @@ namespace Psl\Tests\Fixture; -final class Point +final readonly class Point { public function __construct( - public readonly int $x, - public readonly int $y, + public int $x, + public int $y, ) { } } diff --git a/tests/fixture/StringEnum.php b/tests/fixture/StringEnum.php index 27918977..dec700a9 100644 --- a/tests/fixture/StringEnum.php +++ b/tests/fixture/StringEnum.php @@ -6,7 +6,7 @@ enum StringEnum: string { - case Foo = "foo"; - case Bar = "1"; - case Baz = "baz"; + case Foo = 'foo'; + case Bar = '1'; + case Baz = 'baz'; } diff --git a/tests/fixture/UnitEnum.php b/tests/fixture/UnitEnum.php index 11c5654a..1610cce6 100644 --- a/tests/fixture/UnitEnum.php +++ b/tests/fixture/UnitEnum.php @@ -8,5 +8,5 @@ enum UnitEnum { case Foo; case Bar; - case Baz ; + case Baz; } diff --git a/tests/static-analysis/Comparison/comparable.php b/tests/static-analysis/Comparison/comparable.php index 6a11260e..8f9977b1 100644 --- a/tests/static-analysis/Comparison/comparable.php +++ b/tests/static-analysis/Comparison/comparable.php @@ -44,7 +44,6 @@ public function normalizedValue(): int } } - function test_covariant_limitations(): Order { $cm = new Centimeters(); diff --git a/tests/static-analysis/Fun/pipe.php b/tests/static-analysis/Fun/pipe.php index a86e9a22..beb6457a 100644 --- a/tests/static-analysis/Fun/pipe.php +++ b/tests/static-analysis/Fun/pipe.php @@ -8,33 +8,23 @@ function test_too_few_argument_dont_matter(): int { - $stages = pipe( - static fn (): int => 2, - ); + $stages = pipe(static fn(): int => 2); return $stages('hello'); } /** - * @psalm-suppress InvalidArgument, UnusedClosureParam + * @psalm-suppress InvalidArgument */ function test_too_many_argument_count_issues(): int { - $stages = pipe( - static fn (string $x, string $y): int => 2, - ); + $stages = pipe(static fn(string $_x, string $_y): int => 2); return $stages('hello'); } -/** - * @psalm-suppress UnusedClosureParam - */ function test_variadic_and_default_params(): int { - $stages = pipe( - static fn (int $y, string $x = 'hello'): float => 1.2, - static fn (float ...$items): int => 23 - ); + $stages = pipe(static fn(int $_y, string $_x = 'hello'): float => 1.2, static fn(float ...$_items): int => 23); return $stages(123); } @@ -57,59 +47,42 @@ function test_empty_pipe(): string */ function test_invalid_arguments(): void { - $stages = pipe( - 'hello', - 'world' - ); + $stages = pipe('hello', 'world'); $stages('hello'); } /** - * @psalm-suppress InvalidScalarArgument, UnusedClosureParam + * @psalm-suppress InvalidScalarArgument */ function test_invalid_return_to_input_type(): float { - $stages = pipe( - static fn (string $x): int => 2, - static fn (string $y): float => 1.2 - ); + $stages = pipe(static fn(string $_x): int => 2, static fn(string $_y): float => 1.2); return $stages('hello'); } /** - * @psalm-suppress UnusedClosureParam, InvalidArgument + * @psalm-suppress InvalidArgument */ function test_invalid_input_type(): float { - $stages = pipe( - static fn (string $x): int => 2, - static fn (int $y): float => 1.2 - ); + $stages = pipe(static fn(string $_x): int => 2, static fn(int $_y): float => 1.2); return $stages(143); } /** * @throws InvariantViolationException * - * @psalm-suppress UnusedClosureParam, RedundantCondition + * @psalm-suppress RedundantCondition */ function test_output_type_is_known(): void { - $stages = pipe( - static fn (string $x): int => 2, - ); + $stages = pipe(static fn(string $_x): int => 2); Psl\invariant(is_int($stages('hello')), 'Expected output of int'); } -/** - * @psalm-suppress UnusedClosureParam - */ function test_first_class_callables(): int { - $stages = pipe( - $assignment = static fn (string $x): int => 2, - (static fn (): int => 2)(...), - ); + $stages = pipe($assignment = static fn(string $_x): int => 2, (static fn(): int => 2)(...)); return $stages('hello'); } diff --git a/tests/static-analysis/Iter/count.php b/tests/static-analysis/Iter/count.php index dad77e5f..554f5160 100644 --- a/tests/static-analysis/Iter/count.php +++ b/tests/static-analysis/Iter/count.php @@ -49,19 +49,11 @@ function return_array(): array function test(): void { - take_positive_integer( - Iter\count(return_non_empty_array()) - ); + take_positive_integer(Iter\count(return_non_empty_array())); - take_positive_integer( - Iter\count(return_non_empty_list()) - ); + take_positive_integer(Iter\count(return_non_empty_list())); - take_positive_integer( - Iter\count(return_non_empty_keyed_array()) - ); + take_positive_integer(Iter\count(return_non_empty_keyed_array())); - take_zero( - Iter\count(return_array()) - ); + take_zero(Iter\count(return_array())); } diff --git a/tests/static-analysis/Iter/first.php b/tests/static-analysis/Iter/first.php index 929cf5e3..4e91abb9 100644 --- a/tests/static-analysis/Iter/first.php +++ b/tests/static-analysis/Iter/first.php @@ -31,27 +31,15 @@ function return_non_empty_keyed_array(): array function test(): void { - take_integer( - Iter\first(return_non_empty_integer_list()) - ); + take_integer(Iter\first(return_non_empty_integer_list())); - take_integer( - Iter\first_key(return_non_empty_integer_list()) - ); + take_integer(Iter\first_key(return_non_empty_integer_list())); - take_integer( - Iter\first(return_non_empty_integer_array()) - ); + take_integer(Iter\first(return_non_empty_integer_array())); - take_integer( - Iter\first_key(return_non_empty_integer_array()) - ); + take_integer(Iter\first_key(return_non_empty_integer_array())); - take_integer( - Iter\first(return_non_empty_keyed_array()) - ); + take_integer(Iter\first(return_non_empty_keyed_array())); - take_integer( - Iter\first_key(return_non_empty_keyed_array()) - ); + take_integer(Iter\first_key(return_non_empty_keyed_array())); } diff --git a/tests/static-analysis/Iter/last.php b/tests/static-analysis/Iter/last.php index 39c0c450..0374114c 100644 --- a/tests/static-analysis/Iter/last.php +++ b/tests/static-analysis/Iter/last.php @@ -31,27 +31,15 @@ function return_non_empty_keyed_array(): array function test(): void { - take_integer( - Iter\last(return_non_empty_integer_list()) - ); + take_integer(Iter\last(return_non_empty_integer_list())); - take_integer( - Iter\last_key(return_non_empty_integer_list()) - ); + take_integer(Iter\last_key(return_non_empty_integer_list())); - take_integer( - Iter\last(return_non_empty_integer_array()) - ); + take_integer(Iter\last(return_non_empty_integer_array())); - take_integer( - Iter\last_key(return_non_empty_integer_array()) - ); + take_integer(Iter\last_key(return_non_empty_integer_array())); - take_integer( - Iter\last(return_non_empty_keyed_array()) - ); + take_integer(Iter\last(return_non_empty_keyed_array())); - take_integer( - Iter\last_key(return_non_empty_keyed_array()) - ); + take_integer(Iter\last_key(return_non_empty_keyed_array())); } diff --git a/tests/static-analysis/Option/proceed.php b/tests/static-analysis/Option/proceed.php index f8e38fa1..e033b617 100644 --- a/tests/static-analysis/Option/proceed.php +++ b/tests/static-analysis/Option/proceed.php @@ -13,9 +13,6 @@ function proceed(): void */ function test_proceed(Option\Option $option): string { - return $option->proceed( - static fn (int $value) => "There is $value of them.", - static fn () => 'There are none.', - ); + return $option->proceed(static fn(int $value) => "There is $value of them.", static fn() => 'There are none.'); } } diff --git a/tests/static-analysis/Option/unwrap.php b/tests/static-analysis/Option/unwrap.php index 40172047..d60ca0d1 100644 --- a/tests/static-analysis/Option/unwrap.php +++ b/tests/static-analysis/Option/unwrap.php @@ -4,22 +4,22 @@ use Psl\Option; -function test_some_unwrap_or(): ?string +function test_some_unwrap_or(): null|string { return Option\some('string')->unwrapOr(null); } -function test_none_unwrap_or(): ?string +function test_none_unwrap_or(): null|string { return Option\none()->unwrapOr(null); } -function test_some_unwrap_or_else(): ?string +function test_some_unwrap_or_else(): null|string { - return Option\some('string')->unwrapOrElse(static fn () => null); + return Option\some('string')->unwrapOrElse(static fn() => null); } -function test_none_unwrap_or_else(): ?string +function test_none_unwrap_or_else(): null|string { return Option\none()->unwrapOrElse(static fn() => null); } diff --git a/tests/static-analysis/Option/zip.php b/tests/static-analysis/Option/zip.php index 8388dbfe..41f03ba8 100644 --- a/tests/static-analysis/Option/zip.php +++ b/tests/static-analysis/Option/zip.php @@ -64,7 +64,7 @@ function test_some_unzip(): array */ function test_some_zip_with() { - return Option\some(1)->zipWith(Option\some('2'), static fn($a, $b) => $a + (int) $b); + return Option\some(1)->zipWith(Option\some('2'), static fn($a, $b) => $a + ((int) $b)); } /** @@ -72,5 +72,5 @@ function test_some_zip_with() */ function test_some_zip_with_2() { - return Option\some(1)->zipWith(Option\some('2'), static fn($a, $b) => $b); + return Option\some(1)->zipWith(Option\some('2'), static fn($_a, $b) => $b); } diff --git a/tests/static-analysis/Result/try_catch.php b/tests/static-analysis/Result/try_catch.php index 7bc2d4ad..c37f4925 100644 --- a/tests/static-analysis/Result/try_catch.php +++ b/tests/static-analysis/Result/try_catch.php @@ -4,21 +4,15 @@ use Psl\Result; -function test_try_catch(): ?string +function test_try_catch(): null|string { - return Result\try_catch( - static fn(): string => 'hello', - static fn(): ?string => null, - ); + return Result\try_catch(static fn(): string => 'hello', static fn(): null|string => null); } - -function test_try_catch_composed(): ?string +function test_try_catch_composed(): null|string { - return ( - static fn (int $id) => Result\try_catch( - static fn(): string => 'hello ' . (string) $id, - static fn(): ?string => null, - ) - )(1); + return (static fn(int $id) => Result\try_catch( + static fn(): string => 'hello ' . ((string) $id), + static fn(): null|string => null, + ))(1); } diff --git a/tests/static-analysis/Str/chunk.php b/tests/static-analysis/Str/chunk.php index 6b830cfd..4b60588a 100644 --- a/tests/static-analysis/Str/chunk.php +++ b/tests/static-analysis/Str/chunk.php @@ -32,19 +32,11 @@ function take_non_empty_lowercase_string_list(array $_list): void */ function test(): void { - take_non_empty_string_list( - Str\chunk(return_nonempty_string()) - ); + take_non_empty_string_list(Str\chunk(return_nonempty_string())); - take_non_empty_lowercase_string_list( - Str\chunk(return_nonempty_lowercase_string()) - ); + take_non_empty_lowercase_string_list(Str\chunk(return_nonempty_lowercase_string())); - take_non_empty_string_list( - Str\Byte\chunk(return_nonempty_string()) - ); + take_non_empty_string_list(Str\Byte\chunk(return_nonempty_string())); - take_non_empty_lowercase_string_list( - Str\Byte\chunk(return_nonempty_lowercase_string()) - ); + take_non_empty_lowercase_string_list(Str\Byte\chunk(return_nonempty_lowercase_string())); } diff --git a/tests/static-analysis/Str/lowercase.php b/tests/static-analysis/Str/lowercase.php index af2b0ee0..17912c2b 100644 --- a/tests/static-analysis/Str/lowercase.php +++ b/tests/static-analysis/Str/lowercase.php @@ -34,27 +34,15 @@ function return_non_falsy_string(): string */ function test(): void { - take_lowercase_string( - Str\lowercase('hello') - ); + take_lowercase_string(Str\lowercase('hello')); - take_lowercase_string( - Str\Byte\lowercase('hello') - ); + take_lowercase_string(Str\Byte\lowercase('hello')); - take_non_empty_lowercase_string( - Str\lowercase(return_non_empty_string()) - ); + take_non_empty_lowercase_string(Str\lowercase(return_non_empty_string())); - take_non_empty_lowercase_string( - Str\lowercase(return_non_falsy_string()) - ); + take_non_empty_lowercase_string(Str\lowercase(return_non_falsy_string())); - take_non_empty_lowercase_string( - Str\Byte\lowercase(return_non_empty_string()) - ); + take_non_empty_lowercase_string(Str\Byte\lowercase(return_non_empty_string())); - take_non_empty_lowercase_string( - Str\Byte\lowercase(return_non_falsy_string()) - ); + take_non_empty_lowercase_string(Str\Byte\lowercase(return_non_falsy_string())); } diff --git a/tests/static-analysis/Str/slice.php b/tests/static-analysis/Str/slice.php index fafc147b..fad9a491 100644 --- a/tests/static-analysis/Str/slice.php +++ b/tests/static-analysis/Str/slice.php @@ -23,15 +23,9 @@ function return_lowercase_string(): string */ function tests(): void { - take_lowercase_string( - Str\slice(return_lowercase_string(), 3, 5) - ); + take_lowercase_string(Str\slice(return_lowercase_string(), 3, 5)); - take_lowercase_string( - Str\Byte\slice(return_lowercase_string(), 3, 5) - ); + take_lowercase_string(Str\Byte\slice(return_lowercase_string(), 3, 5)); - take_lowercase_string( - Str\Grapheme\slice(return_lowercase_string(), 3, 5) - ); + take_lowercase_string(Str\Grapheme\slice(return_lowercase_string(), 3, 5)); } diff --git a/tests/static-analysis/Str/splice.php b/tests/static-analysis/Str/splice.php index f33bc386..690ad03a 100644 --- a/tests/static-analysis/Str/splice.php +++ b/tests/static-analysis/Str/splice.php @@ -22,11 +22,7 @@ function return_lowercase_string(): string */ function test(): void { - take_lowercase_string( - Str\splice(return_lowercase_string(), return_lowercase_string(), 0) - ); + take_lowercase_string(Str\splice(return_lowercase_string(), return_lowercase_string(), 0)); - take_lowercase_string( - Str\Byte\splice(return_lowercase_string(), return_lowercase_string(), 0) - ); + take_lowercase_string(Str\Byte\splice(return_lowercase_string(), return_lowercase_string(), 0)); } diff --git a/tests/static-analysis/Str/split.php b/tests/static-analysis/Str/split.php index 4510f985..b001d3a4 100644 --- a/tests/static-analysis/Str/split.php +++ b/tests/static-analysis/Str/split.php @@ -32,19 +32,11 @@ function take_non_empty_lowercase_string_list(array $_list): void */ function test(): void { - take_non_empty_string_list( - Str\split(return_nonempty_string(), 'x') - ); + take_non_empty_string_list(Str\split(return_nonempty_string(), 'x')); - take_non_empty_lowercase_string_list( - Str\split(return_nonempty_lowercase_string(), 'x') - ); + take_non_empty_lowercase_string_list(Str\split(return_nonempty_lowercase_string(), 'x')); - take_non_empty_string_list( - Str\Byte\split(return_nonempty_string(), 'x') - ); + take_non_empty_string_list(Str\Byte\split(return_nonempty_string(), 'x')); - take_non_empty_lowercase_string_list( - Str\Byte\split(return_nonempty_lowercase_string(), 'x') - ); + take_non_empty_lowercase_string_list(Str\Byte\split(return_nonempty_lowercase_string(), 'x')); } diff --git a/tests/static-analysis/Str/uppercase.php b/tests/static-analysis/Str/uppercase.php index a8ec4114..7d63cffb 100644 --- a/tests/static-analysis/Str/uppercase.php +++ b/tests/static-analysis/Str/uppercase.php @@ -29,19 +29,11 @@ function return_non_falsy_string(): string */ function test(): void { - take_non_empty_string( - Str\uppercase(return_non_empty_string()) - ); + take_non_empty_string(Str\uppercase(return_non_empty_string())); - take_non_empty_string( - Str\Byte\uppercase(return_non_empty_string()) - ); + take_non_empty_string(Str\Byte\uppercase(return_non_empty_string())); - take_non_empty_string( - Str\uppercase(return_non_falsy_string()) - ); + take_non_empty_string(Str\uppercase(return_non_falsy_string())); - take_non_empty_string( - Str\Byte\uppercase(return_non_falsy_string()) - ); + take_non_empty_string(Str\Byte\uppercase(return_non_falsy_string())); } diff --git a/tests/static-analysis/Type/converted.php b/tests/static-analysis/Type/converted.php index 345d93ad..bb5d3028 100644 --- a/tests/static-analysis/Type/converted.php +++ b/tests/static-analysis/Type/converted.php @@ -13,9 +13,5 @@ */ function testsPurity(): Type\TypeInterface { - return Type\converted( - Type\int(), - Type\string(), - static fn (int $value): string => (string) $value - ); + return Type\converted(Type\int(), Type\string(), static fn(int $value): string => (string) $value); } diff --git a/tests/static-analysis/Type/intersection.php b/tests/static-analysis/Type/intersection.php index 939d9ea1..1391c645 100644 --- a/tests/static-analysis/Type/intersection.php +++ b/tests/static-analysis/Type/intersection.php @@ -8,11 +8,9 @@ use Psl\Type; /** - * @psalm-suppress UnusedParam - * - * @param Map&ResultInterface&stdClass&Vector $value + * @param Map&ResultInterface&stdClass&Vector $_value */ -function takes_valid_intersection($value): void +function takes_valid_intersection($_value): void { } @@ -23,10 +21,7 @@ function test(): void Type\instance_of(Map::class), Type\intersection( Type\instance_of(ResultInterface::class), - Type\intersection( - Type\instance_of(stdClass::class), - Type\instance_of(Vector::class), - ) + Type\intersection(Type\instance_of(stdClass::class), Type\instance_of(Vector::class)), ), ); diff --git a/tests/static-analysis/Type/nonnull.php b/tests/static-analysis/Type/nonnull.php index 0ceb01d4..643e2d67 100644 --- a/tests/static-analysis/Type/nonnull.php +++ b/tests/static-analysis/Type/nonnull.php @@ -9,7 +9,7 @@ /** * @throws Type\Exception\AssertException */ -function returns_non_null_assertion(?string $state): string +function returns_non_null_assertion(null|string $state): string { return Type\nonnull()->assert($state); } @@ -17,7 +17,7 @@ function returns_non_null_assertion(?string $state): string /** * @throws Type\Exception\AssertException */ -function returns_non_null_assertion_asserted(?string $state): string +function returns_non_null_assertion_asserted(null|string $state): string { Type\nonnull()->assert($state); @@ -27,7 +27,7 @@ function returns_non_null_assertion_asserted(?string $state): string /** * @throws Type\Exception\CoercionException */ -function returns_non_null_coercion(?string $state): string +function returns_non_null_coercion(null|string $state): string { return Type\nonnull()->coerce($state); } @@ -58,7 +58,5 @@ function returns_falsy_match(null $state = null): bool */ function returns_mixed_in_shape(mixed $data): array { - return Type\shape([ - 'mightBeNull' => Type\nonnull(), - ])->coerce($data); + return Type\shape(['mightBeNull' => Type\nonnull()])->coerce($data); } diff --git a/tests/static-analysis/Type/union.php b/tests/static-analysis/Type/union.php index a1eca209..3fca082d 100644 --- a/tests/static-analysis/Type/union.php +++ b/tests/static-analysis/Type/union.php @@ -5,11 +5,9 @@ use Psl\Type; /** - * @psalm-suppress UnusedParam - * * @param 'PENDING'|'PROCESSING'|'COMPLETED'|'ERROR' $state */ -function takes_valid_state(string $state): void +function takes_valid_state(string $_state): void { } @@ -20,11 +18,8 @@ function test(): void Type\literal_scalar('PENDING'), Type\union( Type\literal_scalar('PROCESSING'), - Type\union( - Type\literal_scalar('COMPLETED'), - Type\literal_scalar('ERROR'), - ) - ) + Type\union(Type\literal_scalar('COMPLETED'), Type\literal_scalar('ERROR')), + ), ); /** @psalm-suppress MissingThrowsDocblock */ diff --git a/tests/unit/Async/AwaitableTest.php b/tests/unit/Async/AwaitableTest.php index b694e75a..10f2800b 100644 --- a/tests/unit/Async/AwaitableTest.php +++ b/tests/unit/Async/AwaitableTest.php @@ -186,23 +186,13 @@ public function testThenOnSuccess(): void }); $awaitable = $awaitable - ->then( - static fn(string $result) => Str\reverse($result), - static fn(Throwable $exception) => exit(0), - ) + ->then(static fn(string $result) => Str\reverse($result), static fn(Throwable $_exception) => exit(0)) ->then( static fn(string $result) => throw new InvariantViolationException($result), - static fn(Throwable $exception) => exit(0), - ) - ->then( - static fn($result) => exit(0), - static fn(Throwable $exception) => throw $exception, - ) - ->then( - static fn($result) => exit(0), - static fn(Throwable $exception) => $exception->getMessage(), + static fn(Throwable $_exception) => exit(0), ) - ; + ->then(static fn($_result) => exit(0), static fn(Throwable $exception) => throw $exception) + ->then(static fn($_result) => exit(0), static fn(Throwable $exception) => $exception->getMessage()); static::assertSame('olleh', $awaitable->await()); } @@ -218,8 +208,7 @@ public function testMap(): void ->map(static fn(string $result) => Str\reverse($result)) ->map(static fn(string $result) => throw new InvariantViolationException($result)) ->catch(static fn(InvariantViolationException $exception): string => $exception->getMessage()) - ->always(static fn() => $ref->value = 'hello') - ; + ->always(static fn() => $ref->value = 'hello'); static::assertSame('olleh', $awaitable->await()); static::assertSame('hello', $ref->value); diff --git a/tests/unit/Async/KeyedSemaphoreTest.php b/tests/unit/Async/KeyedSemaphoreTest.php index cc9821c5..7af47bfb 100644 --- a/tests/unit/Async/KeyedSemaphoreTest.php +++ b/tests/unit/Async/KeyedSemaphoreTest.php @@ -39,9 +39,18 @@ public function testSequenceOperationWaitsForPendingOperationsWhenLimitIsNotReac $spy->value[] = $data['value']; }); - Async\run(static fn() => $ks->waitFor('operation', ['time' => DateTime\Duration::milliseconds(3), 'value' => 'a'])); - Async\run(static fn() => $ks->waitFor('operation', ['time' => DateTime\Duration::milliseconds(4), 'value' => 'b'])); - Async\run(static fn() => $ks->waitFor('operation', ['time' => DateTime\Duration::milliseconds(5), 'value' => 'c'])); + Async\run(static fn() => $ks->waitFor('operation', [ + 'time' => DateTime\Duration::milliseconds(3), + 'value' => 'a', + ])); + Async\run(static fn() => $ks->waitFor('operation', [ + 'time' => DateTime\Duration::milliseconds(4), + 'value' => 'b', + ])); + Async\run(static fn() => $ks->waitFor('operation', [ + 'time' => DateTime\Duration::milliseconds(5), + 'value' => 'c', + ])); $last = Async\run(static fn() => $ks->waitFor('operation', ['time' => null, 'value' => 'd'])); $last->await(); @@ -65,7 +74,10 @@ public function testOperationWaitsForPendingOperationsWhenLimitIsNotReached(): v Async\run(static fn() => $ks->waitFor('key', ['time' => DateTime\Duration::milliseconds(3), 'value' => 'a'])); Async\run(static fn() => $ks->waitFor('key', ['time' => DateTime\Duration::milliseconds(4), 'value' => 'b'])); - $beforeLast = Async\run(static fn() => $ks->waitFor('key', ['time' => DateTime\Duration::milliseconds(5), 'value' => 'c'])); + $beforeLast = Async\run(static fn() => $ks->waitFor('key', [ + 'time' => DateTime\Duration::milliseconds(5), + 'value' => 'c', + ])); Async\run(static fn() => $ks->waitFor('key', ['time' => null, 'value' => 'd'])); $beforeLast->await(); @@ -172,13 +184,13 @@ public function testCancelAllPendingOperations(): void $ingoing = [ Async\run(static fn() => $ks->waitFor('foo', 'ingoing')), Async\run(static fn() => $ks->waitFor('bar', 'ingoing')), - Async\run(static fn() => $ks->waitFor('baz', 'ingoing')) + Async\run(static fn() => $ks->waitFor('baz', 'ingoing')), ]; $pending = [ Async\run(static fn() => $ks->waitFor('foo', 'pending')), Async\run(static fn() => $ks->waitFor('bar', 'pending')), - Async\run(static fn() => $ks->waitFor('baz', 'pending')) + Async\run(static fn() => $ks->waitFor('baz', 'pending')), ]; Async\sleep(DateTime\Duration::milliseconds(10)); diff --git a/tests/unit/Async/KeyedSequenceTest.php b/tests/unit/Async/KeyedSequenceTest.php index 5f1074d1..f9443d11 100644 --- a/tests/unit/Async/KeyedSequenceTest.php +++ b/tests/unit/Async/KeyedSequenceTest.php @@ -39,9 +39,18 @@ public function testSequenceOperationWaitsForPendingOperationsWhenLimitIsNotReac $spy->value[] = $data['value']; }); - Async\run(static fn() => $ks->waitFor('operation', ['time' => DateTime\Duration::milliseconds(3), 'value' => 'a'])); - Async\run(static fn() => $ks->waitFor('operation', ['time' => DateTime\Duration::milliseconds(4), 'value' => 'b'])); - Async\run(static fn() => $ks->waitFor('operation', ['time' => DateTime\Duration::milliseconds(5), 'value' => 'c'])); + Async\run(static fn() => $ks->waitFor('operation', [ + 'time' => DateTime\Duration::milliseconds(3), + 'value' => 'a', + ])); + Async\run(static fn() => $ks->waitFor('operation', [ + 'time' => DateTime\Duration::milliseconds(4), + 'value' => 'b', + ])); + Async\run(static fn() => $ks->waitFor('operation', [ + 'time' => DateTime\Duration::milliseconds(5), + 'value' => 'c', + ])); $last = Async\run(static fn() => $ks->waitFor('operation', ['time' => null, 'value' => 'd'])); $last->await(); @@ -149,13 +158,13 @@ public function testCancelAllPendingOperations(): void $ingoing = [ Async\run(static fn() => $ks->waitFor('foo', 'ingoing')), Async\run(static fn() => $ks->waitFor('bar', 'ingoing')), - Async\run(static fn() => $ks->waitFor('baz', 'ingoing')) + Async\run(static fn() => $ks->waitFor('baz', 'ingoing')), ]; $pending = [ Async\run(static fn() => $ks->waitFor('foo', 'pending')), Async\run(static fn() => $ks->waitFor('bar', 'pending')), - Async\run(static fn() => $ks->waitFor('baz', 'pending')) + Async\run(static fn() => $ks->waitFor('baz', 'pending')), ]; Async\sleep(DateTime\Duration::milliseconds(10)); diff --git a/tests/unit/Async/SemaphoreTest.php b/tests/unit/Async/SemaphoreTest.php index 5b7443d8..7b7e9c54 100644 --- a/tests/unit/Async/SemaphoreTest.php +++ b/tests/unit/Async/SemaphoreTest.php @@ -61,7 +61,10 @@ public function testOperationWaitsForPendingOperationsWhenLimitIsNotReached(): v Async\run(static fn() => $semaphore->waitFor(['time' => Datetime\Duration::milliseconds(3), 'value' => 'a'])); Async\run(static fn() => $semaphore->waitFor(['time' => Datetime\Duration::milliseconds(4), 'value' => 'b'])); - $beforeLast = Async\run(static fn() => $semaphore->waitFor(['time' => Datetime\Duration::milliseconds(5), 'value' => 'c'])); + $beforeLast = Async\run(static fn() => $semaphore->waitFor([ + 'time' => Datetime\Duration::milliseconds(5), + 'value' => 'c', + ])); Async\run(static fn() => $semaphore->waitFor(['time' => null, 'value' => 'd'])); $beforeLast->await(); diff --git a/tests/unit/Channel/BoundedChannelTest.php b/tests/unit/Channel/BoundedChannelTest.php index 5242e9f5..7060c7f5 100644 --- a/tests/unit/Channel/BoundedChannelTest.php +++ b/tests/unit/Channel/BoundedChannelTest.php @@ -267,10 +267,7 @@ public function testReceiveWaitsWhenChannelIsEmpty(): void */ [$receiver, $sender] = Channel\bounded(1); - Async\Scheduler::delay( - DateTime\Duration::milliseconds(1), - static fn() => $sender->send('hello'), - ); + Async\Scheduler::delay(DateTime\Duration::milliseconds(1), static fn() => $sender->send('hello')); static::assertTrue($receiver->isEmpty()); diff --git a/tests/unit/Class/ClassTest.php b/tests/unit/Class/ClassTest.php index dd7d0884..cda134fe 100644 --- a/tests/unit/Class/ClassTest.php +++ b/tests/unit/Class/ClassTest.php @@ -21,7 +21,7 @@ public function test( bool $readonly, bool $abstract, array $methods = [], - array $constants = [] + array $constants = [], ): void { static::assertSame($exists, Class\exists($classname)); static::assertSame($exists, Class\defined($classname)); diff --git a/tests/unit/Collection/AbstractMapTest.php b/tests/unit/Collection/AbstractMapTest.php index 6e7ef4a0..6d95aa57 100644 --- a/tests/unit/Collection/AbstractMapTest.php +++ b/tests/unit/Collection/AbstractMapTest.php @@ -39,13 +39,17 @@ public function testCount(): void static::assertCount(0, $this->default()); static::assertCount(0, $this->create([])); static::assertCount(1, $this->create(['foo' => 'bar'])); - static::assertSame(5, $this->create([ - 1 => 'foo', - 2 => 'bar', - 4 => 'baz', - 8 => 'qux', - 16 => 'hax' // ?? - ])->count()); + static::assertSame( + 5, + $this->create([ + 1 => 'foo', + 2 => 'bar', + 4 => 'baz', + 8 => 'qux', + 16 => + 'hax', // ?? + ])->count(), + ); } public function testValues(): void @@ -66,7 +70,7 @@ public function testValues(): void static::assertSame(2, $values->at(1)); static::assertSame(3, $values->at(2)); - $map = $this->create([]); + $map = $this->create([]); $values = $map->values(); static::assertInstanceOf($this->vectorClass, $values); @@ -83,16 +87,19 @@ public function testJsonSerialize(): void $array = $map->jsonSerialize(); - static::assertSame([ - 'foo' => 1, - 'bar' => 2, - 'baz' => 3, - ], $array); + static::assertSame( + [ + 'foo' => 1, + 'bar' => 2, + 'baz' => 3, + ], + $array, + ); } public function testKeys(): void { - $map = $this->create([ + $map = $this->create([ 'foo' => 1, 'bar' => 2, 'baz' => 3, @@ -105,7 +112,7 @@ public function testKeys(): void static::assertSame('bar', $keys->at(1)); static::assertSame('baz', $keys->at(2)); - $map = $this->create([]); + $map = $this->create([]); $keys = $map->keys(); static::assertInstanceOf($this->vectorClass, $keys); @@ -121,7 +128,7 @@ public function testFilter(): void 3 => 'qux', ]); - $filtered = $map->filter(static fn (string $item) => Str\contains($item, 'b')); + $filtered = $map->filter(static fn(string $item) => Str\contains($item, 'b')); static::assertInstanceOf($this->mapClass, $filtered); static::assertNotSame($map, $filtered); @@ -138,7 +145,7 @@ public function testFilter(): void 3 => 'qux', ]); - $filtered = $map->filter(static fn (string $item) => Str\contains($item, 'hello')); + $filtered = $map->filter(static fn(string $item) => Str\contains($item, 'hello')); static::assertInstanceOf($this->mapClass, $filtered); static::assertNotContains('bar', $filtered); @@ -157,7 +164,7 @@ public function testFilterWithKey(): void 3 => 'qux', ]); - $filtered = $map->filterWithKey(static fn (int $k, string $v) => 'foo' === $v || 3 === $k); + $filtered = $map->filterWithKey(static fn(int $k, string $v) => 'foo' === $v || 3 === $k); static::assertInstanceOf($this->mapClass, $filtered); static::assertNotSame($map, $filtered); @@ -174,7 +181,7 @@ public function testFilterWithKey(): void 3 => 'qux', ]); - $filtered = $map->filterWithKey(static fn (int $k, string $v) => 4 === $k); + $filtered = $map->filterWithKey(static fn(int $k, string $_v) => 4 === $k); static::assertInstanceOf($this->mapClass, $filtered); static::assertNotContains('bar', $filtered); @@ -193,15 +200,18 @@ public function testMap(): void 3 => 'qux', ]); - $mapped = $map->map(static fn (string $item) => Str\uppercase($item)); + $mapped = $map->map(static fn(string $item) => Str\uppercase($item)); static::assertInstanceOf($this->mapClass, $mapped); - static::assertSame([ - 0 => 'FOO', - 1 => 'BAR', - 2 => 'BAZ', - 3 => 'QUX', - ], $mapped->toArray()); + static::assertSame( + [ + 0 => 'FOO', + 1 => 'BAR', + 2 => 'BAZ', + 3 => 'QUX', + ], + $mapped->toArray(), + ); static::assertNotSame($map, $mapped); static::assertCount(4, $mapped); @@ -212,7 +222,7 @@ public function testMap(): void 3 => 'qux', ]); - $mapped = $map->map(static fn (string $item) => $item); + $mapped = $map->map(static fn(string $item) => $item); static::assertInstanceOf($this->mapClass, $mapped); static::assertNotSame($map, $mapped); @@ -229,15 +239,18 @@ public function testMapWithKey(): void 3 => 'qux', ]); - $mapped = $map->mapWithKey(static fn (int $k, string $v) => Str\format('%s ( %d )', $v, $k)); + $mapped = $map->mapWithKey(static fn(int $k, string $v) => Str\format('%s ( %d )', $v, $k)); static::assertInstanceOf($this->mapClass, $mapped); - static::assertSame([ - 0 => 'foo ( 0 )', - 1 => 'bar ( 1 )', - 2 => 'baz ( 2 )', - 3 => 'qux ( 3 )', - ], $mapped->toArray()); + static::assertSame( + [ + 0 => 'foo ( 0 )', + 1 => 'bar ( 1 )', + 2 => 'baz ( 2 )', + 3 => 'qux ( 3 )', + ], + $mapped->toArray(), + ); static::assertNotSame($map, $mapped); static::assertCount(4, $mapped); @@ -248,14 +261,14 @@ public function testMapWithKey(): void 3 => 'qux', ]); - $mapped = $map->mapWithKey(static fn (int $k, string $v) => $k); + $mapped = $map->mapWithKey(static fn(int $k, string $_v) => $k); static::assertInstanceOf($this->mapClass, $mapped); static::assertNotSame($map, $mapped); static::assertSame($map->keys()->toArray(), $mapped->toArray()); static::assertCount(4, $mapped); - $mapped = $map->mapWithKey(static fn (int $k, string $v) => $v); + $mapped = $map->mapWithKey(static fn(int $_k, string $v) => $v); static::assertInstanceOf($this->mapClass, $mapped); static::assertNotSame($map, $mapped); @@ -340,43 +353,43 @@ public function testLinearSearch(): void public function testZip(): void { - $map = $this->create([]); + $map = $this->create([]); $zipped = $map->zip([]); static::assertInstanceOf($this->mapClass, $zipped); static::assertCount(0, $zipped); - $map = $this->create([]); + $map = $this->create([]); $zipped = $map->zip([1, 2]); static::assertInstanceOf($this->mapClass, $zipped); static::assertCount(0, $zipped); - $map = $this->create([1 => 'foo', 2 => 'bar']); + $map = $this->create([1 => 'foo', 2 => 'bar']); $zipped = $map->zip([]); static::assertInstanceOf($this->mapClass, $zipped); static::assertCount(0, $zipped); - $map = $this->create([1 => 'foo', 2 => 'bar']); + $map = $this->create([1 => 'foo', 2 => 'bar']); $zipped = $map->zip(['baz', 'qux']); static::assertInstanceOf($this->mapClass, $zipped); static::assertCount(2, $zipped); static::assertSame(['foo', 'baz'], $zipped->at(1)); static::assertSame(['bar', 'qux'], $zipped->at(2)); - $map = $this->create([1 => 'foo', 2 => 'bar', 3 => 'baz', 4 => 'qux']); + $map = $this->create([1 => 'foo', 2 => 'bar', 3 => 'baz', 4 => 'qux']); $zipped = $map->zip(['hello', 'world']); static::assertInstanceOf($this->mapClass, $zipped); static::assertCount(2, $zipped); static::assertSame(['foo', 'hello'], $zipped->at(1)); static::assertSame(['bar', 'world'], $zipped->at(2)); - $map = $this->create([1 => 'hello', 2 => 'world']); + $map = $this->create([1 => 'hello', 2 => 'world']); $zipped = $map->zip(['foo', 'bar', 'baz', 'qux']); static::assertInstanceOf($this->mapClass, $zipped); static::assertCount(2, $zipped); static::assertSame(['hello', 'foo'], $zipped->at(1)); static::assertSame(['world', 'bar'], $zipped->at(2)); - $map = $this->create([1 => 'hello', 2 => 'world']); + $map = $this->create([1 => 'hello', 2 => 'world']); $zipped = $map->zip(['foo' => 'foo', 'bar' => 'bar']); static::assertInstanceOf($this->mapClass, $zipped); static::assertCount(2, $zipped); @@ -386,20 +399,20 @@ public function testZip(): void public function testTake(): void { - $map = $this->create([]); + $map = $this->create([]); $rest = $map->take(2); static::assertInstanceOf($this->mapClass, $rest); static::assertNotSame($map, $rest); static::assertCount(0, $rest); - $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); + $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); $rest = $map->take(4); static::assertInstanceOf($this->mapClass, $rest); static::assertNotSame($map, $rest); static::assertCount(2, $rest); static::assertSame($map->toArray(), $rest->toArray()); - $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); + $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); $rest = $map->take(1); static::assertInstanceOf($this->mapClass, $rest); static::assertNotSame($map, $rest); @@ -409,27 +422,27 @@ public function testTake(): void public function testTakeWhile(): void { - $map = $this->create([]); - $rest = $map->takeWhile(static fn ($v) => false); + $map = $this->create([]); + $rest = $map->takeWhile(static fn($_v) => false); static::assertInstanceOf($this->mapClass, $rest); static::assertNotSame($map, $rest); static::assertCount(0, $rest); - $map = $this->create([]); - $rest = $map->takeWhile(static fn ($v) => true); + $map = $this->create([]); + $rest = $map->takeWhile(static fn($_v) => true); static::assertInstanceOf($this->mapClass, $rest); static::assertNotSame($map, $rest); static::assertCount(0, $rest); - $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); - $rest = $map->takeWhile(static fn ($v) => true); + $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); + $rest = $map->takeWhile(static fn($_v) => true); static::assertInstanceOf($this->mapClass, $rest); static::assertNotSame($map, $rest); static::assertCount(2, $rest); static::assertSame($map->toArray(), $rest->toArray()); - $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); - $rest = $map->takeWhile(static fn ($v) => 'bar' === $v); + $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); + $rest = $map->takeWhile(static fn($v) => 'bar' === $v); static::assertInstanceOf($this->mapClass, $rest); static::assertNotSame($map, $rest); static::assertCount(1, $rest); @@ -438,26 +451,26 @@ public function testTakeWhile(): void public function testDrop(): void { - $map = $this->create([]); + $map = $this->create([]); $rest = $map->drop(2); static::assertInstanceOf($this->mapClass, $rest); static::assertNotSame($map, $rest); static::assertCount(0, $rest); - $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); + $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); $rest = $map->drop(4); static::assertInstanceOf($this->mapClass, $rest); static::assertNotSame($map, $rest); static::assertCount(0, $rest); - $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); + $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); $rest = $map->drop(1); static::assertInstanceOf($this->mapClass, $rest); static::assertNotSame($map, $rest); static::assertCount(1, $rest); static::assertSame('qux', $rest->at('baz')); - $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); + $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); $rest = $map->drop(0); static::assertInstanceOf($this->mapClass, $rest); static::assertNotSame($map, $rest); @@ -467,33 +480,33 @@ public function testDrop(): void public function testDropWhile(): void { - $map = $this->create([]); - $rest = $map->dropWhile(static fn ($v) => true); + $map = $this->create([]); + $rest = $map->dropWhile(static fn($_v) => true); static::assertInstanceOf($this->mapClass, $rest); static::assertNotSame($map, $rest); static::assertCount(0, $rest); - $map = $this->create([]); - $rest = $map->dropWhile(static fn ($v) => false); + $map = $this->create([]); + $rest = $map->dropWhile(static fn($_v) => false); static::assertInstanceOf($this->mapClass, $rest); static::assertNotSame($map, $rest); static::assertCount(0, $rest); - $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); - $rest = $map->dropWhile(static fn ($v) => true); + $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); + $rest = $map->dropWhile(static fn($_v) => true); static::assertInstanceOf($this->mapClass, $rest); static::assertNotSame($map, $rest); static::assertCount(0, $rest); - $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); - $rest = $map->dropWhile(static fn ($v) => false); + $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); + $rest = $map->dropWhile(static fn($_v) => false); static::assertInstanceOf($this->mapClass, $rest); static::assertNotSame($map, $rest); static::assertCount(2, $rest); static::assertSame($map->toArray(), $rest->toArray()); - $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); - $rest = $map->dropWhile(static fn ($v) => 'bar' === $v); + $map = $this->create(['foo' => 'bar', 'baz' => 'qux']); + $rest = $map->dropWhile(static fn($v) => 'bar' === $v); static::assertInstanceOf($this->mapClass, $rest); static::assertNotSame($map, $rest); static::assertCount(1, $rest); @@ -523,12 +536,15 @@ public function testSlice(): void static::assertInstanceOf($this->mapClass, $slice1); static::assertNotSame($slice2, $map); static::assertCount(4, $slice2); - static::assertSame([ - 2 => 'bar', - 3 => 'bar', - 4 => 'baz', - 5 => 'baz', - ], $slice2->toArray()); + static::assertSame( + [ + 2 => 'bar', + 3 => 'bar', + 4 => 'baz', + 5 => 'baz', + ], + $slice2->toArray(), + ); } public function testAt(): void @@ -577,7 +593,7 @@ public function testChunk(): void $map = $this->create([ 'foo' => 'hello', 'bar' => 'world', - 'baz' => '!' + 'baz' => '!', ]); $chunks = $map->chunk(2); @@ -596,7 +612,7 @@ public function testChunk(): void protected function default(): MapInterface { - return ($this->mapClass)::default(); + return $this->mapClass::default(); } /** diff --git a/tests/unit/Collection/AbstractSetTest.php b/tests/unit/Collection/AbstractSetTest.php index 70fa28c4..408f89e5 100644 --- a/tests/unit/Collection/AbstractSetTest.php +++ b/tests/unit/Collection/AbstractSetTest.php @@ -31,13 +31,16 @@ public function testCount(): void static::assertCount(0, $this->default()); static::assertCount(0, $this->createFromList([])); static::assertCount(2, $this->createFromList(['foo', 'bar'])); - static::assertSame(5, $this->createFromList([ - 'foo', - 'bar', - 'baz', - 'qux', - 'hax' // ?? - ])->count()); + static::assertSame( + 5, + $this->createFromList([ + 'foo', + 'bar', + 'baz', + 'qux', + 'hax', // ?? + ])->count(), + ); } public function testValues(): void @@ -74,7 +77,7 @@ public function testKeys(): void 'bar', 'baz', ]); - $keys = $vector->keys(); + $keys = $vector->keys(); static::assertCount(3, $keys); static::assertSame('foo', $keys->at(0)); @@ -82,7 +85,7 @@ public function testKeys(): void static::assertSame('baz', $keys->at(2)); $vector = $this->createFromList([]); - $keys = $vector->keys(); + $keys = $vector->keys(); static::assertCount(0, $keys); } @@ -96,7 +99,7 @@ public function testFilter(): void 'qux', ]); - $filtered = $vector->filter(static fn (string $item) => Str\contains($item, 'b')); + $filtered = $vector->filter(static fn(string $item) => Str\contains($item, 'b')); static::assertInstanceOf($this->setClass, $filtered); static::assertNotSame($vector, $filtered); @@ -113,7 +116,7 @@ public function testFilter(): void 'qux', ]); - $filtered = $vector->filter(static fn (string $item) => Str\contains($item, 'hello')); + $filtered = $vector->filter(static fn(string $item) => Str\contains($item, 'hello')); static::assertInstanceOf($this->setClass, $filtered); static::assertNotContains('bar', $filtered); @@ -132,7 +135,7 @@ public function testFilterWithKey(): void 'qux', ]); - $filtered = $vector->filterWithKey(static fn (string $item) => Str\contains($item, 'b')); + $filtered = $vector->filterWithKey(static fn(string $item) => Str\contains($item, 'b')); static::assertInstanceOf($this->setClass, $filtered); static::assertNotSame($vector, $filtered); @@ -149,7 +152,7 @@ public function testFilterWithKey(): void 'qux', ]); - $filtered = $vector->filterWithKey(static fn (string $item) => Str\contains($item, 'hello')); + $filtered = $vector->filterWithKey(static fn(string $item) => Str\contains($item, 'hello')); static::assertInstanceOf($this->setClass, $filtered); static::assertNotContains('bar', $filtered); @@ -168,15 +171,18 @@ public function testMap(): void 'qux', ]); - $mapped = $set->map(static fn (string $item) => Str\uppercase($item)); + $mapped = $set->map(static fn(string $item) => Str\uppercase($item)); static::assertInstanceOf($this->setClass, $mapped); - static::assertSame([ - 'FOO' => 'FOO', - 'BAR' => 'BAR', - 'BAZ' => 'BAZ', - 'QUX' => 'QUX', - ], $mapped->toArray()); + static::assertSame( + [ + 'FOO' => 'FOO', + 'BAR' => 'BAR', + 'BAZ' => 'BAZ', + 'QUX' => 'QUX', + ], + $mapped->toArray(), + ); static::assertNotSame($set, $mapped); static::assertCount(4, $mapped); @@ -187,7 +193,7 @@ public function testMap(): void 'qux', ]); - $mapped = $set->map(static fn (string $item) => $item); + $mapped = $set->map(static fn(string $item) => $item); static::assertInstanceOf($this->setClass, $mapped); static::assertNotSame($set, $mapped); @@ -203,15 +209,18 @@ public function testMapWithKey(): void 'qux', ]); - $mapped = $set->mapWithKey(static fn (string $item) => Str\uppercase($item)); + $mapped = $set->mapWithKey(static fn(string $item) => Str\uppercase($item)); static::assertInstanceOf($this->setClass, $mapped); - static::assertSame([ - 'FOO' => 'FOO', - 'BAR' => 'BAR', - 'BAZ' => 'BAZ', - 'QUX' => 'QUX', - ], $mapped->toArray()); + static::assertSame( + [ + 'FOO' => 'FOO', + 'BAR' => 'BAR', + 'BAZ' => 'BAZ', + 'QUX' => 'QUX', + ], + $mapped->toArray(), + ); static::assertNotSame($set, $mapped); static::assertCount(4, $mapped); @@ -222,7 +231,7 @@ public function testMapWithKey(): void 'qux', ]); - $mapped = $set->mapWithKey(static fn (string $item) => $item); + $mapped = $set->mapWithKey(static fn(string $item) => $item); static::assertInstanceOf($this->setClass, $mapped); static::assertNotSame($set, $mapped); @@ -316,20 +325,20 @@ public function testLinearSearch(): void public function testTake(): void { $set = $this->default(); - $rest = $set->take(2); + $rest = $set->take(2); static::assertInstanceOf($this->setClass, $rest); static::assertNotSame($set, $rest); static::assertCount(0, $rest); $set = $this->createFromList(['bar', 'qux']); - $rest = $set->take(4); + $rest = $set->take(4); static::assertInstanceOf($this->setClass, $rest); static::assertNotSame($set, $rest); static::assertCount(2, $rest); static::assertSame($set->toArray(), $rest->toArray()); $set = $this->createFromList(['bar', 'qux']); - $rest = $set->take(1); + $rest = $set->take(1); static::assertInstanceOf($this->setClass, $rest); static::assertNotSame($set, $rest); static::assertCount(1, $rest); @@ -339,26 +348,26 @@ public function testTake(): void public function testTakeWhile(): void { $set = $this->default(); - $rest = $set->takeWhile(static fn ($v) => false); + $rest = $set->takeWhile(static fn($_v) => false); static::assertInstanceOf($this->setClass, $rest); static::assertNotSame($set, $rest); static::assertCount(0, $rest); $set = $this->default(); - $rest = $set->takeWhile(static fn ($v) => true); + $rest = $set->takeWhile(static fn($_v) => true); static::assertInstanceOf($this->setClass, $rest); static::assertNotSame($set, $rest); static::assertCount(0, $rest); $set = $this->createFromList(['bar', 'qux']); - $rest = $set->takeWhile(static fn ($v) => true); + $rest = $set->takeWhile(static fn($_v) => true); static::assertInstanceOf($this->setClass, $rest); static::assertNotSame($set, $rest); static::assertCount(2, $rest); static::assertSame($set->toArray(), $rest->toArray()); $set = $this->createFromList(['bar', 'qux']); - $rest = $set->takeWhile(static fn ($v) => 'bar' === $v); + $rest = $set->takeWhile(static fn($v) => 'bar' === $v); static::assertInstanceOf($this->setClass, $rest); static::assertNotSame($set, $rest); static::assertCount(1, $rest); @@ -368,26 +377,26 @@ public function testTakeWhile(): void public function testDrop(): void { $set = $this->default(); - $rest = $set->drop(2); + $rest = $set->drop(2); static::assertInstanceOf($this->setClass, $rest); static::assertNotSame($set, $rest); static::assertCount(0, $rest); $set = $this->createFromList(['bar', 'qux']); - $rest = $set->drop(4); + $rest = $set->drop(4); static::assertInstanceOf($this->setClass, $rest); static::assertNotSame($set, $rest); static::assertCount(0, $rest); $set = $this->createFromList(['bar', 'qux']); - $rest = $set->drop(1); + $rest = $set->drop(1); static::assertInstanceOf($this->setClass, $rest); static::assertNotSame($set, $rest); static::assertCount(1, $rest); static::assertSame('qux', $rest->at('qux')); $set = $this->createFromList(['bar', 'qux']); - $rest = $set->drop(0); + $rest = $set->drop(0); static::assertInstanceOf($this->setClass, $rest); static::assertNotSame($set, $rest); static::assertCount(2, $rest); @@ -397,32 +406,32 @@ public function testDrop(): void public function testDropWhile(): void { $set = $this->default(); - $rest = $set->dropWhile(static fn ($v) => true); + $rest = $set->dropWhile(static fn($_v) => true); static::assertInstanceOf($this->setClass, $rest); static::assertNotSame($set, $rest); static::assertCount(0, $rest); $set = $this->default(); - $rest = $set->dropWhile(static fn ($v) => false); + $rest = $set->dropWhile(static fn($_v) => false); static::assertInstanceOf($this->setClass, $rest); static::assertNotSame($set, $rest); static::assertCount(0, $rest); $set = $this->createFromList(['bar', 'qux']); - $rest = $set->dropWhile(static fn ($v) => true); + $rest = $set->dropWhile(static fn($_v) => true); static::assertInstanceOf($this->setClass, $rest); static::assertNotSame($set, $rest); static::assertCount(0, $rest); $set = $this->createFromList(['bar', 'qux']); - $rest = $set->dropWhile(static fn ($v) => false); + $rest = $set->dropWhile(static fn($_v) => false); static::assertInstanceOf($this->setClass, $rest); static::assertNotSame($set, $rest); static::assertCount(2, $rest); static::assertSame($set->toArray(), $rest->toArray()); $set = $this->createFromList(['bar', 'qux']); - $rest = $set->dropWhile(static fn ($v) => 'bar' === $v); + $rest = $set->dropWhile(static fn($v) => 'bar' === $v); static::assertInstanceOf($this->setClass, $rest); static::assertNotSame($set, $rest); static::assertCount(1, $rest); @@ -452,12 +461,15 @@ public function testSlice(): void static::assertInstanceOf($this->setClass, $slice1); static::assertNotSame($slice2, $vector); static::assertCount(4, $slice2); - static::assertSame([ - 'baz' => 'baz', - 'qux' => 'qux', - 'hax' => 'hax', - 'dax' => 'dax', - ], $slice2->toArray()); + static::assertSame( + [ + 'baz' => 'baz', + 'qux' => 'qux', + 'hax' => 'hax', + 'dax' => 'dax', + ], + $slice2->toArray(), + ); } public function testAt(): void @@ -522,7 +534,7 @@ public function testChunk(): void protected function default(): SetInterface { - return ($this->setClass)::default(); + return $this->setClass::default(); } /** diff --git a/tests/unit/Collection/AbstractVectorTest.php b/tests/unit/Collection/AbstractVectorTest.php index 31c12ddf..c3fbb35f 100644 --- a/tests/unit/Collection/AbstractVectorTest.php +++ b/tests/unit/Collection/AbstractVectorTest.php @@ -31,13 +31,16 @@ public function testCount(): void static::assertCount(0, $this->default()); static::assertCount(0, $this->create([])); static::assertCount(2, $this->create(['foo', 'bar'])); - static::assertSame(5, $this->create([ - 'foo', - 'bar', - 'baz', - 'qux', - 'hax' // ?? - ])->count()); + static::assertSame( + 5, + $this->create([ + 'foo', + 'bar', + 'baz', + 'qux', + 'hax', // ?? + ])->count(), + ); } public function testValues(): void @@ -77,7 +80,7 @@ public function testKeys(): void 'bar', 'baz', ]); - $keys = $vector->keys(); + $keys = $vector->keys(); static::assertInstanceOf($this->vectorClass, $keys); static::assertCount(3, $keys); @@ -86,7 +89,7 @@ public function testKeys(): void static::assertSame(2, $keys->at(2)); $vector = $this->create([]); - $keys = $vector->keys(); + $keys = $vector->keys(); static::assertInstanceOf($this->vectorClass, $keys); static::assertCount(0, $keys); @@ -101,7 +104,7 @@ public function testFilter(): void 'qux', ]); - $filtered = $vector->filter(static fn (string $item) => Str\contains($item, 'b')); + $filtered = $vector->filter(static fn(string $item) => Str\contains($item, 'b')); static::assertInstanceOf($this->vectorClass, $filtered); static::assertNotSame($vector, $filtered); @@ -118,7 +121,7 @@ public function testFilter(): void 'qux', ]); - $filtered = $vector->filter(static fn (string $item) => Str\contains($item, 'hello')); + $filtered = $vector->filter(static fn(string $item) => Str\contains($item, 'hello')); static::assertInstanceOf($this->vectorClass, $filtered); static::assertNotContains('bar', $filtered); @@ -137,7 +140,7 @@ public function testFilterWithKey(): void 'qux', ]); - $filtered = $vector->filterWithKey(static fn (int $k, string $v) => 'foo' === $v || 3 === $k); + $filtered = $vector->filterWithKey(static fn(int $k, string $v) => 'foo' === $v || 3 === $k); static::assertInstanceOf($this->vectorClass, $filtered); static::assertNotSame($vector, $filtered); @@ -154,7 +157,7 @@ public function testFilterWithKey(): void 'qux', ]); - $filtered = $vector->filterWithKey(static fn (int $k, string $v) => 4 === $k); + $filtered = $vector->filterWithKey(static fn(int $k, string $_v) => 4 === $k); static::assertInstanceOf($this->vectorClass, $filtered); static::assertNotContains('bar', $filtered); @@ -173,15 +176,18 @@ public function testMap(): void 'qux', ]); - $mapped = $vector->map(static fn (string $item) => Str\uppercase($item)); + $mapped = $vector->map(static fn(string $item) => Str\uppercase($item)); static::assertInstanceOf($this->vectorClass, $mapped); - static::assertSame([ - 'FOO', - 'BAR', - 'BAZ', - 'QUX', - ], $mapped->toArray()); + static::assertSame( + [ + 'FOO', + 'BAR', + 'BAZ', + 'QUX', + ], + $mapped->toArray(), + ); static::assertNotSame($vector, $mapped); static::assertCount(4, $mapped); @@ -192,7 +198,7 @@ public function testMap(): void 'qux', ]); - $mapped = $vector->map(static fn (string $item) => $item); + $mapped = $vector->map(static fn(string $item) => $item); static::assertInstanceOf($this->vectorClass, $mapped); static::assertNotSame($vector, $mapped); @@ -209,15 +215,18 @@ public function testMapWithKey(): void 3 => 'qux', ]); - $mapped = $vector->mapWithKey(static fn (int $k, string $v) => Str\format('%s ( %d )', $v, $k)); + $mapped = $vector->mapWithKey(static fn(int $k, string $v) => Str\format('%s ( %d )', $v, $k)); static::assertInstanceOf($this->vectorClass, $mapped); - static::assertSame([ - 'foo ( 0 )', - 'bar ( 1 )', - 'baz ( 2 )', - 'qux ( 3 )', - ], $mapped->toArray()); + static::assertSame( + [ + 'foo ( 0 )', + 'bar ( 1 )', + 'baz ( 2 )', + 'qux ( 3 )', + ], + $mapped->toArray(), + ); static::assertNotSame($vector, $mapped); static::assertCount(4, $mapped); @@ -228,14 +237,14 @@ public function testMapWithKey(): void 'qux', ]); - $mapped = $vector->mapWithKey(static fn (int $k, string $v) => $k); + $mapped = $vector->mapWithKey(static fn(int $k, string $_v) => $k); static::assertInstanceOf($this->vectorClass, $mapped); static::assertNotSame($vector, $mapped); static::assertSame($vector->keys()->toArray(), $mapped->toArray()); static::assertCount(4, $mapped); - $mapped = $vector->mapWithKey(static fn (int $k, string $v) => $v); + $mapped = $vector->mapWithKey(static fn(int $_k, string $v) => $v); static::assertInstanceOf($this->vectorClass, $mapped); static::assertNotSame($vector, $mapped); @@ -360,20 +369,20 @@ public function testZip(): void public function testTake(): void { $vector = $this->create([]); - $rest = $vector->take(2); + $rest = $vector->take(2); static::assertInstanceOf($this->vectorClass, $rest); static::assertNotSame($vector, $rest); static::assertCount(0, $rest); $vector = $this->create(['bar', 'qux']); - $rest = $vector->take(4); + $rest = $vector->take(4); static::assertInstanceOf($this->vectorClass, $rest); static::assertNotSame($vector, $rest); static::assertCount(2, $rest); static::assertSame($vector->toArray(), $rest->toArray()); $vector = $this->create(['bar', 'qux']); - $rest = $vector->take(1); + $rest = $vector->take(1); static::assertInstanceOf($this->vectorClass, $rest); static::assertNotSame($vector, $rest); static::assertCount(1, $rest); @@ -383,26 +392,26 @@ public function testTake(): void public function testTakeWhile(): void { $vector = $this->create([]); - $rest = $vector->takeWhile(static fn ($v) => false); + $rest = $vector->takeWhile(static fn($_v) => false); static::assertInstanceOf($this->vectorClass, $rest); static::assertNotSame($vector, $rest); static::assertCount(0, $rest); $vector = $this->create([]); - $rest = $vector->takeWhile(static fn ($v) => true); + $rest = $vector->takeWhile(static fn($_v) => true); static::assertInstanceOf($this->vectorClass, $rest); static::assertNotSame($vector, $rest); static::assertCount(0, $rest); $vector = $this->create(['bar', 'qux']); - $rest = $vector->takeWhile(static fn ($v) => true); + $rest = $vector->takeWhile(static fn($_v) => true); static::assertInstanceOf($this->vectorClass, $rest); static::assertNotSame($vector, $rest); static::assertCount(2, $rest); static::assertSame($vector->toArray(), $rest->toArray()); $vector = $this->create(['bar', 'qux']); - $rest = $vector->takeWhile(static fn ($v) => 'bar' === $v); + $rest = $vector->takeWhile(static fn($v) => 'bar' === $v); static::assertInstanceOf($this->vectorClass, $rest); static::assertNotSame($vector, $rest); static::assertCount(1, $rest); @@ -412,26 +421,26 @@ public function testTakeWhile(): void public function testDrop(): void { $vector = $this->create([]); - $rest = $vector->drop(2); + $rest = $vector->drop(2); static::assertInstanceOf($this->vectorClass, $rest); static::assertNotSame($vector, $rest); static::assertCount(0, $rest); $vector = $this->create(['bar', 'qux']); - $rest = $vector->drop(4); + $rest = $vector->drop(4); static::assertInstanceOf($this->vectorClass, $rest); static::assertNotSame($vector, $rest); static::assertCount(0, $rest); $vector = $this->create(['bar', 'qux']); - $rest = $vector->drop(1); + $rest = $vector->drop(1); static::assertInstanceOf($this->vectorClass, $rest); static::assertNotSame($vector, $rest); static::assertCount(1, $rest); static::assertSame('qux', $rest->at(0)); $vector = $this->create(['bar', 'qux']); - $rest = $vector->drop(0); + $rest = $vector->drop(0); static::assertInstanceOf($this->vectorClass, $rest); static::assertNotSame($vector, $rest); static::assertCount(2, $rest); @@ -441,32 +450,32 @@ public function testDrop(): void public function testDropWhile(): void { $vector = $this->create([]); - $rest = $vector->dropWhile(static fn ($v) => true); + $rest = $vector->dropWhile(static fn($_v) => true); static::assertInstanceOf($this->vectorClass, $rest); static::assertNotSame($vector, $rest); static::assertCount(0, $rest); $vector = $this->create([]); - $rest = $vector->dropWhile(static fn ($v) => false); + $rest = $vector->dropWhile(static fn($_v) => false); static::assertInstanceOf($this->vectorClass, $rest); static::assertNotSame($vector, $rest); static::assertCount(0, $rest); $vector = $this->create(['bar', 'qux']); - $rest = $vector->dropWhile(static fn ($v) => true); + $rest = $vector->dropWhile(static fn($_v) => true); static::assertInstanceOf($this->vectorClass, $rest); static::assertNotSame($vector, $rest); static::assertCount(0, $rest); $vector = $this->create(['bar', 'qux']); - $rest = $vector->dropWhile(static fn ($v) => false); + $rest = $vector->dropWhile(static fn($_v) => false); static::assertInstanceOf($this->vectorClass, $rest); static::assertNotSame($vector, $rest); static::assertCount(2, $rest); static::assertSame($vector->toArray(), $rest->toArray()); $vector = $this->create(['bar', 'qux']); - $rest = $vector->dropWhile(static fn ($v) => 'bar' === $v); + $rest = $vector->dropWhile(static fn($v) => 'bar' === $v); static::assertInstanceOf($this->vectorClass, $rest); static::assertNotSame($vector, $rest); static::assertCount(1, $rest); @@ -496,12 +505,15 @@ public function testSlice(): void static::assertInstanceOf($this->vectorClass, $slice1); static::assertNotSame($slice2, $vector); static::assertCount(4, $slice2); - static::assertSame([ - 'bar', - 'bar', - 'baz', - 'baz', - ], $slice2->toArray()); + static::assertSame( + [ + 'bar', + 'bar', + 'baz', + 'baz', + ], + $slice2->toArray(), + ); } public function testAt(): void @@ -566,7 +578,7 @@ public function testChunk(): void protected function default(): VectorInterface { - return ($this->vectorClass)::default(); + return $this->vectorClass::default(); } /** diff --git a/tests/unit/Collection/MutableMapTest.php b/tests/unit/Collection/MutableMapTest.php index df2ae468..6766c651 100644 --- a/tests/unit/Collection/MutableMapTest.php +++ b/tests/unit/Collection/MutableMapTest.php @@ -23,7 +23,7 @@ final class MutableMapTest extends AbstractMapTest public function testClear(): void { - $map = $this->create(['foo' => 'bar']); + $map = $this->create(['foo' => 'bar']); $cleared = $map->clear(); static::assertSame($cleared, $map); @@ -38,10 +38,7 @@ public function testSet(): void 'baz' => 'qux', ]); - $modified = $map - ->set('foo', 'foo') - ->set('bar', 'bar') - ->set('baz', 'baz'); + $modified = $map->set('foo', 'foo')->set('bar', 'bar')->set('baz', 'baz'); static::assertSame($modified, $map); @@ -132,9 +129,7 @@ public function testRemove(): void 'baz' => 'qux', ]); - $modified = $map - ->remove('foo') - ->remove('bar'); + $modified = $map->remove('foo')->remove('bar'); static::assertSame($modified, $map); static::assertCount(1, $map); @@ -200,7 +195,6 @@ public function testOffsetIssetThrowsForInvalidOffsetType(): void 'baz' => '3', ]); - $this->expectException(Exception\InvalidOffsetException::class); $this->expectExceptionMessage('Invalid map read offset type, expected a string or an integer.'); diff --git a/tests/unit/Collection/MutableSetTest.php b/tests/unit/Collection/MutableSetTest.php index 0356dd15..a24166f9 100644 --- a/tests/unit/Collection/MutableSetTest.php +++ b/tests/unit/Collection/MutableSetTest.php @@ -16,10 +16,9 @@ final class MutableSetTest extends AbstractSetTest */ protected string $setClass = MutableSet::class; - public function testClear(): void { - $set = $this->createFromList(['foo', 'bar']); + $set = $this->createFromList(['foo', 'bar']); $cleared = $set->clear(); static::assertSame($cleared, $set); @@ -39,8 +38,7 @@ public function testAdd(): void ->add('foo') ->add('bar') ->add('baz') - ->add('qux') - ; + ->add('qux'); static::assertSame($modified, $set); @@ -90,9 +88,7 @@ public function testRemove(): void 'baz', ]); - $modified = $set - ->remove('foo') - ->remove('bar'); + $modified = $set->remove('foo')->remove('bar'); static::assertSame($modified, $set); static::assertCount(1, $set); diff --git a/tests/unit/Collection/MutableVectorTest.php b/tests/unit/Collection/MutableVectorTest.php index c8dd5bbc..acf8f42a 100644 --- a/tests/unit/Collection/MutableVectorTest.php +++ b/tests/unit/Collection/MutableVectorTest.php @@ -19,7 +19,7 @@ final class MutableVectorTest extends AbstractVectorTest public function testClear(): void { - $vector = $this->create(['foo', 'bar']); + $vector = $this->create(['foo', 'bar']); $cleared = $vector->clear(); static::assertSame($cleared, $vector); @@ -34,10 +34,7 @@ public function testSet(): void 'qux', ]); - $modified = $vector - ->set(0, 'foo') - ->set(1, 'bar') - ->set(2, 'baz'); + $modified = $vector->set(0, 'foo')->set(1, 'bar')->set(2, 'baz'); static::assertSame($modified, $vector); @@ -80,13 +77,13 @@ public function testSetAll(): void public function testAdd(): void { $vector = $this->create([ - 'foo', 'bar', - 'baz', 'qux', + 'foo', + 'bar', + 'baz', + 'qux', ]); - $modified = $vector - ->add('hello') - ->add('world'); + $modified = $vector->add('hello')->add('world'); static::assertSame($modified, $vector); @@ -101,15 +98,16 @@ public function testAdd(): void public function testAddAll(): void { $vector = $this->create([ - 'foo', 'bar', - 'baz', 'qux', + 'foo', + 'bar', + 'baz', + 'qux', ]); - $modified = $vector - ->addAll([ - 'hello', - 'world', - ]); + $modified = $vector->addAll([ + 'hello', + 'world', + ]); static::assertSame($modified, $vector); @@ -129,16 +127,13 @@ public function testRemove(): void 'baz', ]); - $modified = $vector - ->remove(0) - ->remove(0); + $modified = $vector->remove(0)->remove(0); static::assertSame($modified, $vector); static::assertCount(1, $vector); static::assertSame('baz', $vector->get(0)); } - public function testArrayAccess(): void { $vector = $this->create([ diff --git a/tests/unit/Comparison/AbstractComparisonTest.php b/tests/unit/Comparison/AbstractComparisonTest.php index 4cba0c0f..83b4354d 100644 --- a/tests/unit/Comparison/AbstractComparisonTest.php +++ b/tests/unit/Comparison/AbstractComparisonTest.php @@ -22,30 +22,30 @@ public static function provideComparisonCases(): Generator yield 'comparable-default' => [ self::createComparableIntWrapper(0), self::createComparableIntWrapper(0), - Order::default() + Order::default(), ]; yield 'comparable-equal' => [ self::createComparableIntWrapper(0), self::createComparableIntWrapper(0), - Order::Equal + Order::Equal, ]; yield 'comparable-less' => [ self::createComparableIntWrapper(0), self::createComparableIntWrapper(1), - Order::Less + Order::Less, ]; yield 'comparable-greater' => [ self::createComparableIntWrapper(1), self::createComparableIntWrapper(0), - Order::Greater + Order::Greater, ]; } protected static function createComparableIntWrapper(int $i): Comparable { - return new class ($i) implements Comparable { + return new class($i) implements Comparable { public function __construct( - public readonly int $int + public readonly int $int, ) { } public function compare(mixed $other): Order @@ -57,10 +57,10 @@ public function compare(mixed $other): Order protected static function createIncomparableWrapper(int $i, string $additionalInfo = ''): Comparable { - return new class ($i, $additionalInfo) implements Comparable { + return new class($i, $additionalInfo) implements Comparable { public function __construct( public readonly int $int, - public readonly string $additionalInfo + public readonly string $additionalInfo, ) { } diff --git a/tests/unit/Comparison/CompareTest.php b/tests/unit/Comparison/CompareTest.php index 05d024e1..185e2564 100644 --- a/tests/unit/Comparison/CompareTest.php +++ b/tests/unit/Comparison/CompareTest.php @@ -17,7 +17,6 @@ public function testItCanCompare(mixed $a, mixed $b, Order $expected): void static::assertSame($expected, Comparison\compare($a, $b)); } - public function testItCanFailComparing(): void { $a = self::createIncomparableWrapper(1); @@ -29,7 +28,6 @@ public function testItCanFailComparing(): void Comparison\compare($a, $b); } - public function testItCanFailComparingWithAdditionalInfo(): void { $a = self::createIncomparableWrapper(1, 'Can only compare even numbers'); diff --git a/tests/unit/Comparison/GreaterOrEqualTest.php b/tests/unit/Comparison/GreaterOrEqualTest.php index e30501eb..ca1f31f6 100644 --- a/tests/unit/Comparison/GreaterOrEqualTest.php +++ b/tests/unit/Comparison/GreaterOrEqualTest.php @@ -14,6 +14,9 @@ class GreaterOrEqualTest extends AbstractComparisonTest */ public function testItCanCheckGreaterOrEqual(mixed $a, mixed $b, Order $expected): void { - static::assertSame($expected === Order::Greater || $expected === Order::Equal, Comparison\greater_or_equal($a, $b)); + static::assertSame( + $expected === Order::Greater || $expected === Order::Equal, + Comparison\greater_or_equal($a, $b), + ); } } diff --git a/tests/unit/DateTime/DateTimeTest.php b/tests/unit/DateTime/DateTimeTest.php index 4e737106..26eaaa09 100644 --- a/tests/unit/DateTime/DateTimeTest.php +++ b/tests/unit/DateTime/DateTimeTest.php @@ -34,7 +34,7 @@ public function testNow(): void public function testTodayAt(): void { $now = DateTime::now(); - $today = DateTime::todayAt(14, 00, 00); + $today = DateTime::todayAt(14, 0o0, 0o0); static::assertSame($now->getDate(), $today->getDate()); static::assertNotSame($now->getTime(), $today->getTime()); @@ -72,12 +72,12 @@ public function testFromParts(): void static::assertSame(0, $datetime->getMinutes()); static::assertSame(0, $datetime->getSeconds()); static::assertSame(1, $datetime->getNanoseconds()); - static::assertSame([2024, 2, 4, 14, 0, 0, 1,], $datetime->getParts()); + static::assertSame([2024, 2, 4, 14, 0, 0, 1], $datetime->getParts()); } public function testFromPartsWithDefaults(): void { - $datetime = DateTime::fromParts(Timezone::UTC, 2024, Month::February, 4,); + $datetime = DateTime::fromParts(Timezone::UTC, 2024, Month::February, 4); static::assertSame(Timezone::UTC, $datetime->getTimezone()); static::assertSame(2024, $datetime->getYear()); @@ -90,7 +90,6 @@ public function testFromPartsWithDefaults(): void static::assertSame(0, $datetime->getNanoseconds()); } - /** * @dataProvider provideInvalidComponentParts */ @@ -102,7 +101,7 @@ public function testFromPartsWithInvalidComponent( int $hours, int $minutes, int $seconds, - int $nanoseconds + int $nanoseconds, ): void { $this->expectException(UnexpectedValueException::class); $this->expectExceptionMessage($expectedMessage); @@ -113,12 +112,66 @@ public function testFromPartsWithInvalidComponent( public static function provideInvalidComponentParts(): array { return [ - ['Unexpected year value encountered. Provided "0", but the calendar expects "1". Check the year for accuracy and ensure it\'s within the supported range.', 0, 1, 1, 0, 0, 0, 0], - ['Unexpected month value encountered. Provided "0", but the calendar expects "12". Ensure the month is within the 1-12 range and matches the specific year context.', 2024, 0, 1, 0, 0, 0, 0], - ['Unexpected day value encountered. Provided "0", but the calendar expects "31". Ensure the day is valid for the given month and year, considering variations like leap years.', 2024, 1, 0, 0, 0, 0, 0], - ['Unexpected hours value encountered. Provided "-1", but the calendar expects "23". Ensure the hour falls within a 24-hour day.', 2024, 1, 1, -1, 0, 0, 0], - ['Unexpected minutes value encountered. Provided "-1", but the calendar expects "59". Check the minutes value for errors and ensure it\'s within the 0-59 range.', 2024, 1, 1, 0, -1, 0, 0], - ['Unexpected seconds value encountered. Provided "59", but the calendar expects "-1". Ensure the seconds are correct and within the 0-59 range.', 2024, 1, 1, 0, 0, -1, 0], + [ + 'Unexpected year value encountered. Provided "0", but the calendar expects "1". Check the year for accuracy and ensure it\'s within the supported range.', + 0, + 1, + 1, + 0, + 0, + 0, + 0, + ], + [ + 'Unexpected month value encountered. Provided "0", but the calendar expects "12". Ensure the month is within the 1-12 range and matches the specific year context.', + 2024, + 0, + 1, + 0, + 0, + 0, + 0, + ], + [ + 'Unexpected day value encountered. Provided "0", but the calendar expects "31". Ensure the day is valid for the given month and year, considering variations like leap years.', + 2024, + 1, + 0, + 0, + 0, + 0, + 0, + ], + [ + 'Unexpected hours value encountered. Provided "-1", but the calendar expects "23". Ensure the hour falls within a 24-hour day.', + 2024, + 1, + 1, + -1, + 0, + 0, + 0, + ], + [ + 'Unexpected minutes value encountered. Provided "-1", but the calendar expects "59". Check the minutes value for errors and ensure it\'s within the 0-59 range.', + 2024, + 1, + 1, + 0, + -1, + 0, + 0, + ], + [ + 'Unexpected seconds value encountered. Provided "59", but the calendar expects "-1". Ensure the seconds are correct and within the 0-59 range.', + 2024, + 1, + 1, + 0, + 0, + -1, + 0, + ], ]; } @@ -141,13 +194,16 @@ public function testToString(): void static::assertSame('4 Feb 2024, 14:00:00', $datetime->toString()); static::assertSame('04/02/2024, 14:00:00', $datetime->toString(date_style: DateStyle::Short)); - static::assertSame('4 Feb 2024, 14:00:00 Greenwich Mean Time', $datetime->toString(time_style: TimeStyle::Full)); + static::assertSame( + '4 Feb 2024, 14:00:00 Greenwich Mean Time', + $datetime->toString(time_style: TimeStyle::Full), + ); static::assertSame('4 Feb 2024, 15:00:00', $datetime->toString(timezone: TimeZone::EuropeBrussels)); // Formatting depends on version of intl - so compare with intl version instead of hardcoding a label: static::assertSame( create_intl_date_formatter(locale: Locale::DutchBelgium)->format($datetime->getTimestamp()->getSeconds()), - $datetime->toString(locale: Locale::DutchBelgium) + $datetime->toString(locale: Locale::DutchBelgium), ); } @@ -163,7 +219,7 @@ public function testFormat(): void // Formatting depends on version of intl - so compare with intl version instead of hardcoding a label: static::assertSame( create_intl_date_formatter(locale: Locale::DutchBelgium)->format($datetime->getTimestamp()->getSeconds()), - $datetime->toString(locale: Locale::DutchBelgium) + $datetime->toString(locale: Locale::DutchBelgium), ); } @@ -512,7 +568,7 @@ public function testWithTime() public function testTimezoneInfo() { $timeZone = Timezone::EuropeBrussels; - $date = DateTime::fromParts($timeZone, 2024, 01, 01); + $date = DateTime::fromParts($timeZone, 2024, 0o1, 0o1); static::assertSame(!$timeZone->getDaylightSavingTimeOffset($date)->isZero(), $date->isDaylightSavingTime()); static::assertEquals($timeZone->getOffset($date), $date->getTimezoneOffset()); @@ -520,7 +576,7 @@ public function testTimezoneInfo() public function testConvertTimeZone() { - $date = DateTime::fromParts(Timezone::EuropeBrussels, 2024, 01, 01, 1); + $date = DateTime::fromParts(Timezone::EuropeBrussels, 2024, 0o1, 0o1, 1); $converted = $date->convertToTimezone($london = Timezone::EuropeLondon); static::assertSame($london, $converted->getTimezone()); diff --git a/tests/unit/DateTime/DurationTest.php b/tests/unit/DateTime/DurationTest.php index 1274ef2c..a78b355a 100644 --- a/tests/unit/DateTime/DurationTest.php +++ b/tests/unit/DateTime/DurationTest.php @@ -20,11 +20,11 @@ public function testGetters(): void { $t = DateTime\Duration::fromParts(1, 2, 3, 4); - static::assertEquals(1, $t->getHours()); - static::assertEquals(2, $t->getMinutes()); - static::assertEquals(3, $t->getSeconds()); - static::assertEquals(4, $t->getNanoseconds()); - static::assertEquals([1, 2, 3, 4], $t->getParts()); + static::assertSame(1, $t->getHours()); + static::assertSame(2, $t->getMinutes()); + static::assertSame(3, $t->getSeconds()); + static::assertSame(4, $t->getNanoseconds()); + static::assertSame([1, 2, 3, 4], $t->getParts()); } public function testNamedConstructors() @@ -57,10 +57,15 @@ public function provideGetTotalHours(): array /** * @dataProvider provideGetTotalHours */ - public function testGetTotalHours(int $hours, int $minutes, int $seconds, int $nanoseconds, float $expectedHours): void - { + public function testGetTotalHours( + int $hours, + int $minutes, + int $seconds, + int $nanoseconds, + float $expectedHours, + ): void { $time = DateTime\Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); - static::assertEquals($expectedHours, $time->getTotalHours()); + static::assertSame($expectedHours, $time->getTotalHours()); } public function provideGetTotalMinutes(): array @@ -80,10 +85,15 @@ public function provideGetTotalMinutes(): array /** * @dataProvider provideGetTotalMinutes */ - public function testGetTotalMinutes(int $hours, int $minutes, int $seconds, int $nanoseconds, float $expectedMinutes): void - { + public function testGetTotalMinutes( + int $hours, + int $minutes, + int $seconds, + int $nanoseconds, + float $expectedMinutes, + ): void { $time = DateTime\Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); - static::assertEquals($expectedMinutes, $time->getTotalMinutes()); + static::assertSame($expectedMinutes, $time->getTotalMinutes()); } public function provideGetTotalSeconds(): array @@ -103,10 +113,15 @@ public function provideGetTotalSeconds(): array /** * @dataProvider provideGetTotalSeconds */ - public function testGetTotalSeconds(int $hours, int $minutes, int $seconds, int $nanoseconds, float $expectedSeconds): void - { + public function testGetTotalSeconds( + int $hours, + int $minutes, + int $seconds, + int $nanoseconds, + float $expectedSeconds, + ): void { $time = DateTime\Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); - static::assertEquals($expectedSeconds, $time->getTotalSeconds()); + static::assertSame($expectedSeconds, $time->getTotalSeconds()); } public function provideGetTotalMilliseconds(): array @@ -126,17 +141,22 @@ public function provideGetTotalMilliseconds(): array /** * @dataProvider provideGetTotalMilliseconds */ - public function testGetTotalMilliseconds(int $hours, int $minutes, int $seconds, int $nanoseconds, float $expectedMilliseconds): void - { + public function testGetTotalMilliseconds( + int $hours, + int $minutes, + int $seconds, + int $nanoseconds, + float $expectedMilliseconds, + ): void { $time = DateTime\Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); - static::assertEquals($expectedMilliseconds, $time->getTotalMilliseconds()); + static::assertSame($expectedMilliseconds, $time->getTotalMilliseconds()); } public function provideGetTotalMicroseconds(): array { return [ [0, 0, 0, 0, 0.0], - [0, 0, 0, 1, 0.001], + [0, 0, 0, 1, 0.001], [1, 0, 0, 0, 3600000000.0], [1, 30, 0, 0, 5400000000.0], [2, 15, 30, 0, 8130000000.0], @@ -149,34 +169,42 @@ public function provideGetTotalMicroseconds(): array /** * @dataProvider provideGetTotalMicroseconds */ - public function testGetTotalMicroseconds(int $hours, int $minutes, int $seconds, int $nanoseconds, float $expectedMicroseconds): void - { + public function testGetTotalMicroseconds( + int $hours, + int $minutes, + int $seconds, + int $nanoseconds, + float $expectedMicroseconds, + ): void { $time = DateTime\Duration::fromParts($hours, $minutes, $seconds, $nanoseconds); - static::assertEquals($expectedMicroseconds, $time->getTotalMicroseconds()); + static::assertSame($expectedMicroseconds, $time->getTotalMicroseconds()); } public function testSetters(): void { $t = DateTime\Duration::fromParts(1, 2, 3, 4); - static::assertEquals([42, 2, 3, 4], $t->withHours(42)->getParts()); - static::assertEquals([1, 42, 3, 4], $t->withMinutes(42)->getParts()); - static::assertEquals([1, 2, 42, 4], $t->withSeconds(42)->getParts()); - static::assertEquals([1, 2, 3, 42], $t->withNanoseconds(42)->getParts()); - static::assertEquals([2, 3, 3, 4], $t->withMinutes(63)->getParts()); - static::assertEquals([1, 3, 3, 4], $t->withSeconds(63)->getParts()); - static::assertEquals([1, 2, 4, 42], $t->withNanoseconds(DateTime\NANOSECONDS_PER_SECOND + 42)->getParts()); - static::assertEquals([1, 2, 3, 4], $t->getParts()); + static::assertSame([42, 2, 3, 4], $t->withHours(42)->getParts()); + static::assertSame([1, 42, 3, 4], $t->withMinutes(42)->getParts()); + static::assertSame([1, 2, 42, 4], $t->withSeconds(42)->getParts()); + static::assertSame([1, 2, 3, 42], $t->withNanoseconds(42)->getParts()); + static::assertSame([2, 3, 3, 4], $t->withMinutes(63)->getParts()); + static::assertSame([1, 3, 3, 4], $t->withSeconds(63)->getParts()); + static::assertSame([1, 2, 4, 42], $t->withNanoseconds(DateTime\NANOSECONDS_PER_SECOND + 42)->getParts()); + static::assertSame([1, 2, 3, 4], $t->getParts()); } public function testFractionsOfSecond(): void { - static::assertEquals([0, 0, 0, 0], DateTime\Duration::zero()->getParts()); - static::assertEquals([0, 0, 0, 42], DateTime\Duration::nanoseconds(42)->getParts()); - static::assertEquals([0, 0, 1, 42], DateTime\Duration::nanoseconds(DateTime\NANOSECONDS_PER_SECOND + 42)->getParts()); - static::assertEquals([0, 0, 0, 42000], DateTime\Duration::microseconds(42)->getParts()); - static::assertEquals([0, 0, 1, 42000], DateTime\Duration::microseconds(1000042)->getParts()); - static::assertEquals([0, 0, 0, 42000000], DateTime\Duration::milliseconds(42)->getParts()); - static::assertEquals([0, 0, 1, 42000000], DateTime\Duration::milliseconds(1042)->getParts()); + static::assertSame([0, 0, 0, 0], DateTime\Duration::zero()->getParts()); + static::assertSame([0, 0, 0, 42], DateTime\Duration::nanoseconds(42)->getParts()); + static::assertSame( + [0, 0, 1, 42], + DateTime\Duration::nanoseconds(DateTime\NANOSECONDS_PER_SECOND + 42)->getParts(), + ); + static::assertSame([0, 0, 0, 42000], DateTime\Duration::microseconds(42)->getParts()); + static::assertSame([0, 0, 1, 42000], DateTime\Duration::microseconds(1000042)->getParts()); + static::assertSame([0, 0, 0, 42000000], DateTime\Duration::milliseconds(42)->getParts()); + static::assertSame([0, 0, 1, 42000000], DateTime\Duration::milliseconds(1042)->getParts()); } /** @@ -203,21 +231,24 @@ public static function provideNormalized(): array */ public function testNormalized(int $input_s, int $input_ns, int $normalized_s, int $normalized_ns): void { - static::assertEquals( + static::assertSame( [0, 0, $normalized_s, $normalized_ns], - DateTime\Duration::fromParts(0, 0, $input_s, $input_ns)->getParts() + DateTime\Duration::fromParts(0, 0, $input_s, $input_ns)->getParts(), ); } public function testNormalizedHMS(): void { - static::assertEquals([3, 5, 4, 0], DateTime\Duration::fromParts(2, 63, 124)->getParts()); - static::assertEquals([0, 59, 4, 0], DateTime\Duration::fromParts(2, -63, 124)->getParts()); - static::assertEquals([-1, 0, -55, -(DateTime\NANOSECONDS_PER_SECOND - 42)], DateTime\Duration::fromParts(0, -63, 124, 42)->getParts()); - static::assertEquals([42, 0, 0, 0], DateTime\Duration::hours(42)->getParts()); - static::assertEquals([1, 3, 0, 0], DateTime\Duration::minutes(63)->getParts()); - static::assertEquals([0, -1, -3, 0], DateTime\Duration::seconds(-63)->getParts()); - static::assertEquals([0, 0, -1, 0], DateTime\Duration::nanoseconds(-DateTime\NANOSECONDS_PER_SECOND)->getParts()); + static::assertSame([3, 5, 4, 0], DateTime\Duration::fromParts(2, 63, 124)->getParts()); + static::assertSame([0, 59, 4, 0], DateTime\Duration::fromParts(2, -63, 124)->getParts()); + static::assertSame( + [-1, 0, -55, -(DateTime\NANOSECONDS_PER_SECOND - 42)], + DateTime\Duration::fromParts(0, -63, 124, 42)->getParts(), + ); + static::assertSame([42, 0, 0, 0], DateTime\Duration::hours(42)->getParts()); + static::assertSame([1, 3, 0, 0], DateTime\Duration::minutes(63)->getParts()); + static::assertSame([0, -1, -3, 0], DateTime\Duration::seconds(-63)->getParts()); + static::assertSame([0, 0, -1, 0], DateTime\Duration::nanoseconds(-DateTime\NANOSECONDS_PER_SECOND)->getParts()); } /** @@ -239,9 +270,9 @@ public static function providePositiveNegative(): array public function testPositiveNegative(int $h, int $m, int $s, int $ns, int $expected_sign): void { $t = DateTime\Duration::fromParts($h, $m, $s, $ns); - static::assertEquals($expected_sign === 0, $t->isZero()); - static::assertEquals($expected_sign === 1, $t->isPositive()); - static::assertEquals($expected_sign === -1, $t->isNegative()); + static::assertSame($expected_sign === 0, $t->isZero()); + static::assertSame($expected_sign === 1, $t->isPositive()); + static::assertSame($expected_sign === -1, $t->isNegative()); } /** @@ -265,13 +296,13 @@ public function testCompare(DateTime\Duration $a, DateTime\Duration $b, Order $e { $opposite = Order::from(-$expected->value); - static::assertEquals($expected, $a->compare($b)); - static::assertEquals($opposite, $b->compare($a)); - static::assertEquals($expected === Order::Equal, $a->equals($b)); - static::assertEquals($expected === Order::Less, $a->shorter($b)); - static::assertEquals($expected !== Order::Greater, $a->shorterOrEqual($b)); - static::assertEquals($expected === Order::Greater, $a->longer($b)); - static::assertEquals($expected !== Order::Less, $a->longerOrEqual($b)); + static::assertSame($expected, $a->compare($b)); + static::assertSame($opposite, $b->compare($a)); + static::assertSame($expected === Order::Equal, $a->equals($b)); + static::assertSame($expected === Order::Less, $a->shorter($b)); + static::assertSame($expected !== Order::Greater, $a->shorterOrEqual($b)); + static::assertSame($expected === Order::Greater, $a->longer($b)); + static::assertSame($expected !== Order::Less, $a->longerOrEqual($b)); static::assertFalse($a->betweenExclusive($a, $a)); static::assertFalse($a->betweenExclusive($a, $b)); static::assertFalse($a->betweenExclusive($b, $a)); @@ -279,7 +310,7 @@ public function testCompare(DateTime\Duration $a, DateTime\Duration $b, Order $e static::assertTrue($a->betweenInclusive($a, $a)); static::assertTrue($a->betweenInclusive($a, $b)); static::assertTrue($a->betweenInclusive($b, $a)); - static::assertEquals($expected === Order::Equal, $a->betweenInclusive($b, $b)); + static::assertSame($expected === Order::Equal, $a->betweenInclusive($b, $b)); } public function testIsBetween(): void @@ -302,18 +333,18 @@ public function testOperations(): void $z = DateTime\Duration::zero(); $a = DateTime\Duration::fromParts(0, 2, 25); $b = DateTime\Duration::fromParts(0, 0, -63, 42); - static::assertEquals([0, 0, 0, 0], $z->invert()->getParts()); - static::assertEquals([0, -2, -25, 0], $a->invert()->getParts()); - static::assertEquals([0, 1, 2, DateTime\NANOSECONDS_PER_SECOND - 42], $b->invert()->getParts()); - static::assertEquals($a->getParts(), $z->plus($a)->getParts()); - static::assertEquals($b->getParts(), $b->plus($z)->getParts()); - static::assertEquals($b->invert()->getParts(), $z->minus($b)->getParts()); - static::assertEquals($a->getParts(), $a->minus($z)->getParts()); - static::assertEquals([0, 1, 22, 42], $a->plus($b)->getParts()); - static::assertEquals([0, 1, 22, 42], $b->plus($a)->getParts()); - static::assertEquals([0, 3, 27, DateTime\NANOSECONDS_PER_SECOND - 42], $a->minus($b)->getParts()); - static::assertEquals([0, -3, -27, -(DateTime\NANOSECONDS_PER_SECOND - 42)], $b->minus($a)->getParts()); - static::assertEquals($b->invert()->plus($a)->getParts(), $a->minus($b)->getParts()); + static::assertSame([0, 0, 0, 0], $z->invert()->getParts()); + static::assertSame([0, -2, -25, 0], $a->invert()->getParts()); + static::assertSame([0, 1, 2, DateTime\NANOSECONDS_PER_SECOND - 42], $b->invert()->getParts()); + static::assertSame($a->getParts(), $z->plus($a)->getParts()); + static::assertSame($b->getParts(), $b->plus($z)->getParts()); + static::assertSame($b->invert()->getParts(), $z->minus($b)->getParts()); + static::assertSame($a->getParts(), $a->minus($z)->getParts()); + static::assertSame([0, 1, 22, 42], $a->plus($b)->getParts()); + static::assertSame([0, 1, 22, 42], $b->plus($a)->getParts()); + static::assertSame([0, 3, 27, DateTime\NANOSECONDS_PER_SECOND - 42], $a->minus($b)->getParts()); + static::assertSame([0, -3, -27, -(DateTime\NANOSECONDS_PER_SECOND - 42)], $b->minus($a)->getParts()); + static::assertSame($b->invert()->plus($a)->getParts(), $a->minus($b)->getParts()); } /** @@ -346,7 +377,7 @@ public static function provideToString(): array */ public function testToString(int $h, int $m, int $s, int $ns, string $expected): void { - static::assertEquals($expected, DateTime\Duration::fromParts($h, $m, $s, $ns)->toString()); + static::assertSame($expected, DateTime\Duration::fromParts($h, $m, $s, $ns)->toString()); } public function testSerialization(): void diff --git a/tests/unit/DateTime/Exception/InvalidArgumentExceptionTest.php b/tests/unit/DateTime/Exception/InvalidArgumentExceptionTest.php index c30e321f..34aeead1 100644 --- a/tests/unit/DateTime/Exception/InvalidArgumentExceptionTest.php +++ b/tests/unit/DateTime/Exception/InvalidArgumentExceptionTest.php @@ -15,7 +15,7 @@ public function testForYear(): void static::assertSame( 'The year \'-1\' diverges from expectation; a positive integer is required.', - $exception->getMessage() + $exception->getMessage(), ); $this->expectExceptionObject($exception); @@ -28,7 +28,7 @@ public function testForMonth(): void static::assertSame( 'The month \'13\' falls outside the acceptable range of \'1\' to \'12\'.', - $exception->getMessage() + $exception->getMessage(), ); $this->expectExceptionObject($exception); @@ -41,7 +41,7 @@ public function testForDay(): void static::assertSame( 'The day \'32\', for month \'1\' and year \'2021\', does not align with the expected range of \'1\' to \'31\'.', - $exception->getMessage() + $exception->getMessage(), ); $this->expectExceptionObject($exception); @@ -52,10 +52,7 @@ public function testForHours(): void { $exception = InvalidArgumentException::forHours(24); - static::assertSame( - 'The hour \'24\' exceeds the expected range of \'0\' to \'23\'.', - $exception->getMessage() - ); + static::assertSame('The hour \'24\' exceeds the expected range of \'0\' to \'23\'.', $exception->getMessage()); $this->expectExceptionObject($exception); throw $exception; @@ -65,10 +62,7 @@ public function testForMinutes(): void { $exception = InvalidArgumentException::forMinutes(60); - static::assertSame( - 'The minute \'60\' steps beyond the bounds of \'0\' to \'59\'.', - $exception->getMessage() - ); + static::assertSame('The minute \'60\' steps beyond the bounds of \'0\' to \'59\'.', $exception->getMessage()); $this->expectExceptionObject($exception); throw $exception; @@ -80,7 +74,7 @@ public function testForSeconds(): void static::assertSame( 'The seconds \'61\' stretch outside the acceptable range of \'0\' to \'59\'.', - $exception->getMessage() + $exception->getMessage(), ); $this->expectExceptionObject($exception); @@ -93,7 +87,7 @@ public function testForNanoseconds(): void static::assertSame( 'The nanoseconds \'1000000000\' exceed the foreseen limit of \'0\' to \'999999999\'.', - $exception->getMessage() + $exception->getMessage(), ); $this->expectExceptionObject($exception); diff --git a/tests/unit/DateTime/MonthTest.php b/tests/unit/DateTime/MonthTest.php index 3d52a0c1..1cecf763 100644 --- a/tests/unit/DateTime/MonthTest.php +++ b/tests/unit/DateTime/MonthTest.php @@ -16,7 +16,7 @@ final class MonthTest extends TestCase */ public function testGetPrevious(Month $month, Month $expected): void { - static::assertEquals($expected, $month->getPrevious()); + static::assertSame($expected, $month->getPrevious()); } /** @@ -24,7 +24,7 @@ public function testGetPrevious(Month $month, Month $expected): void */ public function testGetNext(Month $month, Month $expected): void { - static::assertEquals($expected, $month->getNext()); + static::assertSame($expected, $month->getNext()); } /** @@ -32,8 +32,8 @@ public function testGetNext(Month $month, Month $expected): void */ public function testGetDays(Month $month, int $expectedForLeapYear, int $expectedForNonLeapYear): void { - static::assertEquals($expectedForLeapYear, $month->getLeapYearDays()); - static::assertEquals($expectedForNonLeapYear, $month->getNonLeapYearDays()); + static::assertSame($expectedForLeapYear, $month->getLeapYearDays()); + static::assertSame($expectedForNonLeapYear, $month->getNonLeapYearDays()); } /** @@ -41,7 +41,7 @@ public function testGetDays(Month $month, int $expectedForLeapYear, int $expecte */ public function testGetDaysForYear(Month $month, int $year, int $expected): void { - static::assertEquals($expected, $month->getDaysForYear($year)); + static::assertSame($expected, $month->getDaysForYear($year)); } /** diff --git a/tests/unit/DateTime/SecondsStyleTest.php b/tests/unit/DateTime/SecondsStyleTest.php index 7a9cc80e..be6e396e 100644 --- a/tests/unit/DateTime/SecondsStyleTest.php +++ b/tests/unit/DateTime/SecondsStyleTest.php @@ -17,7 +17,7 @@ final class SecondsStyleTest extends TestCase */ public function testFromTimestamp(SecondsStyle $expectedSecondsStyle, Timestamp $timestamp): void { - static::assertEquals($expectedSecondsStyle, SecondsStyle::fromTimestamp($timestamp)); + static::assertSame($expectedSecondsStyle, SecondsStyle::fromTimestamp($timestamp)); } /** diff --git a/tests/unit/DateTime/TimestampTest.php b/tests/unit/DateTime/TimestampTest.php index 4ab68b15..431804b2 100644 --- a/tests/unit/DateTime/TimestampTest.php +++ b/tests/unit/DateTime/TimestampTest.php @@ -85,31 +85,28 @@ public function testFromRowSimplifiesNanoseconds(): void { $timestamp = Timestamp::fromParts(0, NANOSECONDS_PER_SECOND * 20); - static::assertEquals(20, $timestamp->getSeconds()); - static::assertEquals(0, $timestamp->getNanoseconds()); + static::assertSame(20, $timestamp->getSeconds()); + static::assertSame(0, $timestamp->getNanoseconds()); - $timestamp = Timestamp::fromParts(0, 100 + NANOSECONDS_PER_SECOND * 20); + $timestamp = Timestamp::fromParts(0, 100 + (NANOSECONDS_PER_SECOND * 20)); - static::assertEquals(20, $timestamp->getSeconds()); - static::assertEquals(100, $timestamp->getNanoseconds()); + static::assertSame(20, $timestamp->getSeconds()); + static::assertSame(100, $timestamp->getNanoseconds()); $timestamp = Timestamp::fromParts(30, -NANOSECONDS_PER_SECOND * 20); - static::assertEquals(10, $timestamp->getSeconds()); - static::assertEquals(0, $timestamp->getNanoseconds()); + static::assertSame(10, $timestamp->getSeconds()); + static::assertSame(0, $timestamp->getNanoseconds()); - $timestamp = Timestamp::fromParts(10, 100 + -NANOSECONDS_PER_SECOND * 20); + $timestamp = Timestamp::fromParts(10, 100 + (-NANOSECONDS_PER_SECOND * 20)); - static::assertEquals(-10, $timestamp->getSeconds()); - static::assertEquals(100, $timestamp->getNanoseconds()); + static::assertSame(-10, $timestamp->getSeconds()); + static::assertSame(100, $timestamp->getNanoseconds()); } public function testParsingFromPattern(): void { - $timestamp = Timestamp::parse( - raw_string: '2024 091', - pattern: FormatPattern::JulianDay, - ); + $timestamp = Timestamp::parse(raw_string: '2024 091', pattern: FormatPattern::JulianDay); $datetime = DateTime::fromTimestamp($timestamp, Timezone::UTC); @@ -156,28 +153,75 @@ public function testParseFails(): void public function provideFormatParsingData(): iterable { - yield [1711917897, FormatPattern::FullDateTime, Timezone::UTC, Locale::English, 'Sunday, March 31, 2024 20:44:57']; - yield [1711917897, FormatPattern::FullDateTime, Timezone::AsiaShanghai, Locale::ChineseTraditional, '星期一, 4月 01, 2024 04:44:57']; - yield [1711917897, FormatPattern::Cookie, Timezone::AmericaNewYork, Locale::EnglishUnitedStates, 'Sunday, 31-Mar-2024 16:44:57 EDT']; - yield [1711917897, FormatPattern::Http, Timezone::EuropeVienna, Locale::GermanAustria, 'So., 31 März 2024 22:44:57 MESZ']; - yield [1711917897, FormatPattern::Email, Timezone::EuropeMadrid, Locale::SpanishSpain, 'dom, 31 mar 2024 22:44:57 GMT+02:00']; - yield [1711917897, FormatPattern::SqlDateTime, Timezone::AfricaTunis, Locale::ArabicTunisia, '2024-03-31 21:44:57']; + yield [ + 1711917897, + FormatPattern::FullDateTime, + Timezone::UTC, + Locale::English, + 'Sunday, March 31, 2024 20:44:57', + ]; + yield [ + 1711917897, + FormatPattern::FullDateTime, + Timezone::AsiaShanghai, + Locale::ChineseTraditional, + '星期一, 4月 01, 2024 04:44:57', + ]; + yield [ + 1711917897, + FormatPattern::Cookie, + Timezone::AmericaNewYork, + Locale::EnglishUnitedStates, + 'Sunday, 31-Mar-2024 16:44:57 EDT', + ]; + yield [ + 1711917897, + FormatPattern::Http, + Timezone::EuropeVienna, + Locale::GermanAustria, + 'So., 31 März 2024 22:44:57 MESZ', + ]; + yield [ + 1711917897, + FormatPattern::Email, + Timezone::EuropeMadrid, + Locale::SpanishSpain, + 'dom, 31 mar 2024 22:44:57 GMT+02:00', + ]; + yield [ + 1711917897, + FormatPattern::SqlDateTime, + Timezone::AfricaTunis, + Locale::ArabicTunisia, + '2024-03-31 21:44:57', + ]; yield [1711832400, FormatPattern::IsoOrdinalDate, Timezone::EuropeMoscow, Locale::RussianRussia, '2024-091']; - yield [1711917897, FormatPattern::Iso8601, Timezone::EuropeLondon, Locale::EnglishUnitedKingdom, '2024-03-31T21:44:57.000+01:00']; + yield [ + 1711917897, + FormatPattern::Iso8601, + Timezone::EuropeLondon, + Locale::EnglishUnitedKingdom, + '2024-03-31T21:44:57.000+01:00', + ]; } /** * @dataProvider provideFormatParsingData */ - public function testFormattingAndPatternParsing(int $timestamp, string|FormatPattern $pattern, Timezone $timezone, Locale $locale, string $expected): void - { + public function testFormattingAndPatternParsing( + int $timestamp, + string|FormatPattern $pattern, + Timezone $timezone, + Locale $locale, + string $expected, + ): void { $timestamp = Timestamp::fromParts($timestamp); $result = $timestamp->format(pattern: $pattern, timezone: $timezone, locale: $locale); static::assertSame($expected, $result); - $other = Timestamp::parse($result, pattern: $pattern, timezone: $timezone, locale: $locale); + $other = Timestamp::parse($result, pattern: $pattern, timezone: $timezone, locale: $locale); static::assertSame($timestamp->getSeconds(), $other->getSeconds()); static::assertSame($timestamp->getNanoseconds(), $other->getNanoseconds()); @@ -201,7 +245,6 @@ public static function provideCompare(): array [Timestamp::fromParts(100), Timestamp::fromParts(42), Order::Greater], [Timestamp::fromParts(42), Timestamp::fromParts(42), Order::Equal], [Timestamp::fromParts(42), Timestamp::fromParts(100), Order::Less], - // Nanoseconds [Timestamp::fromParts(42, 100), Timestamp::fromParts(42, 42), Order::Greater], [Timestamp::fromParts(42, 42), Timestamp::fromParts(42, 42), Order::Equal], @@ -215,13 +258,13 @@ public function testCompare(Timestamp $a, Timestamp $b, Order $expected): void { $opposite = Order::from(-$expected->value); - static::assertEquals($expected, $a->compare($b)); - static::assertEquals($opposite, $b->compare($a)); - static::assertEquals($expected === Order::Equal, $a->equals($b)); - static::assertEquals($expected === Order::Less, $a->before($b)); - static::assertEquals($expected !== Order::Greater, $a->beforeOrAtTheSameTime($b)); - static::assertEquals($expected === Order::Greater, $a->after($b)); - static::assertEquals($expected !== Order::Less, $a->afterOrAtTheSameTime($b)); + static::assertSame($expected, $a->compare($b)); + static::assertSame($opposite, $b->compare($a)); + static::assertSame($expected === Order::Equal, $a->equals($b)); + static::assertSame($expected === Order::Less, $a->before($b)); + static::assertSame($expected !== Order::Greater, $a->beforeOrAtTheSameTime($b)); + static::assertSame($expected === Order::Greater, $a->after($b)); + static::assertSame($expected !== Order::Less, $a->afterOrAtTheSameTime($b)); static::assertFalse($a->betweenTimeExclusive($a, $a)); static::assertFalse($a->betweenTimeExclusive($a, $b)); static::assertFalse($a->betweenTimeExclusive($b, $a)); @@ -229,7 +272,7 @@ public function testCompare(Timestamp $a, Timestamp $b, Order $expected): void static::assertTrue($a->betweenTimeInclusive($a, $a)); static::assertTrue($a->betweenTimeInclusive($a, $b)); static::assertTrue($a->betweenTimeInclusive($b, $a)); - static::assertEquals($expected === Order::Equal, $a->betweenTimeInclusive($b, $b)); + static::assertSame($expected === Order::Equal, $a->betweenTimeInclusive($b, $b)); } public function testNanosecondsModifications(): void diff --git a/tests/unit/Dict/AssociateTest.php b/tests/unit/Dict/AssociateTest.php index b1027c5b..31a52006 100644 --- a/tests/unit/Dict/AssociateTest.php +++ b/tests/unit/Dict/AssociateTest.php @@ -12,10 +12,7 @@ final class AssociateTest extends TestCase { public function testAssociate(): void { - static::assertSame(['a' => 1, 'b' => 2, 'c' => 3], Dict\associate( - ['a', 'b', 'c'], - [1, 2, 3] - )); + static::assertSame(['a' => 1, 'b' => 2, 'c' => 3], Dict\associate(['a', 'b', 'c'], [1, 2, 3])); } public function testAssociateEmpty(): void @@ -25,10 +22,10 @@ public function testAssociateEmpty(): void public function testAssociateCollections(): void { - static::assertSame(['a' => 1, 'b' => 2, 'c' => 3], Dict\associate( - Collection\Vector::fromArray(['a', 'b', 'c']), - Collection\Vector::fromArray([1, 2, 3]) - )); + static::assertSame( + ['a' => 1, 'b' => 2, 'c' => 3], + Dict\associate(Collection\Vector::fromArray(['a', 'b', 'c']), Collection\Vector::fromArray([1, 2, 3])), + ); } public function testAssociateWithMissingKeys(): void @@ -36,10 +33,7 @@ public function testAssociateWithMissingKeys(): void $this->expectException(Dict\Exception\LogicException::class); $this->expectExceptionMessage('Expected length of $keys and $values to be the same'); - Dict\associate( - ['a', 'b', 'c'], - [1, 2, 3, 4] - ); + Dict\associate(['a', 'b', 'c'], [1, 2, 3, 4]); } public function testAssociateWithMissingValues(): void @@ -47,9 +41,6 @@ public function testAssociateWithMissingValues(): void $this->expectException(Dict\Exception\LogicException::class); $this->expectExceptionMessage('Expected length of $keys and $values to be the same'); - Dict\associate( - ['a', 'b', 'c', 'd', 'e', 'f'], - [1, 2, 3, 4] - ); + Dict\associate(['a', 'b', 'c', 'd', 'e', 'f'], [1, 2, 3, 4]); } } diff --git a/tests/unit/Dict/CountValuesTest.php b/tests/unit/Dict/CountValuesTest.php index 6b2e6f34..4d1a9f98 100644 --- a/tests/unit/Dict/CountValuesTest.php +++ b/tests/unit/Dict/CountValuesTest.php @@ -36,12 +36,7 @@ public function provideData(): array ], [ ['foo' => 2, 'bar' => 1, 'baz' => 4], - Vec\concat( - ['foo', 'bar', 'baz'], - ['foo'], - ['baz'], - ['baz', 'baz'], - ), + Vec\concat(['foo', 'bar', 'baz'], ['foo'], ['baz'], ['baz', 'baz']), ], ]; } diff --git a/tests/unit/Dict/DropWhileTest.php b/tests/unit/Dict/DropWhileTest.php index df90c079..9b0608ea 100644 --- a/tests/unit/Dict/DropWhileTest.php +++ b/tests/unit/Dict/DropWhileTest.php @@ -21,9 +21,9 @@ public function testDropWhile(array $expected, array $array, callable $callable) public function provideData(): iterable { - yield [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], static fn (int $_): bool => false]; - yield [[3 => 4, 4 => 5], [1, 2, 3, 4, 5], static fn (int $i) => $i <= 3]; - yield [[2 => 3, 3 => 4, 4 => 5], [1, 2, 3, 4, 5], static fn (int $i) => $i <= 2]; - yield [[], [1, 2, 3, 4, 5], static fn (int $_) => true]; + yield [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], static fn(int $_): bool => false]; + yield [[3 => 4, 4 => 5], [1, 2, 3, 4, 5], static fn(int $i) => $i <= 3]; + yield [[2 => 3, 3 => 4, 4 => 5], [1, 2, 3, 4, 5], static fn(int $i) => $i <= 2]; + yield [[], [1, 2, 3, 4, 5], static fn(int $_) => true]; } } diff --git a/tests/unit/Dict/EqualTest.php b/tests/unit/Dict/EqualTest.php index 5eea1b76..74df7a5d 100644 --- a/tests/unit/Dict/EqualTest.php +++ b/tests/unit/Dict/EqualTest.php @@ -26,25 +26,21 @@ public function provideData(): array ['foo' => 'bar', 'baz' => 'qux'], ['baz' => 'qux', 'foo' => 'bar'], ], - [ false, ['foo' => 0, 'baz' => 1], ['foo' => '0', 'baz' => 1], ], - [ true, [], [], ], - [ false, [null], [], ], - [ false, [new Collection\Vector([])], diff --git a/tests/unit/Dict/FilterKeysTest.php b/tests/unit/Dict/FilterKeysTest.php index 8318496f..e9e9cab5 100644 --- a/tests/unit/Dict/FilterKeysTest.php +++ b/tests/unit/Dict/FilterKeysTest.php @@ -13,7 +13,7 @@ final class FilterKeysTest extends TestCase /** * @dataProvider provideData */ - public function testFilterKeys(array $expected, iterable $iterable, ?callable $predicate = null): void + public function testFilterKeys(array $expected, iterable $iterable, null|callable $predicate = null): void { $result = Dict\filter_keys($iterable, $predicate); @@ -22,11 +22,11 @@ public function testFilterKeys(array $expected, iterable $iterable, ?callable $p public function provideData(): iterable { - yield [[], []]; - yield [[1 => 'b'], ['a', 'b']]; - yield [[], ['a', 'b'], static fn () => false]; - yield [['a', 'b'], ['a', 'b'], static fn (int $_): bool => true]; - yield [['a'], ['a', 'b'], static fn (int $k): bool => 1 !== $k]; - yield [['a'], Collection\Vector::fromArray(['a', 'b']), static fn (int $k): bool => 1 !== $k]; + yield [[], []]; + yield [[1 => 'b'], ['a', 'b']]; + yield [[], ['a', 'b'], static fn() => false]; + yield [['a', 'b'], ['a', 'b'], static fn(int $_): bool => true]; + yield [['a'], ['a', 'b'], static fn(int $k): bool => 1 !== $k]; + yield [['a'], Collection\Vector::fromArray(['a', 'b']), static fn(int $k): bool => 1 !== $k]; } } diff --git a/tests/unit/Dict/FilterNullsTest.php b/tests/unit/Dict/FilterNullsTest.php index 114a9729..d6c87cd5 100644 --- a/tests/unit/Dict/FilterNullsTest.php +++ b/tests/unit/Dict/FilterNullsTest.php @@ -24,12 +24,15 @@ public function testFilterNulls(): void static::assertCount(3, Dict\filter_nulls(Iter\Iterator::create([null, false, '', 0]))); static::assertCount(3, Dict\filter_nulls(new Collection\Vector([null, false, '', 0]))); static::assertCount(3, Dict\filter_nulls(new Collection\Map([null, false, '', 0]))); - static::assertCount(3, Dict\filter_nulls((static function (): iterable { - yield null; - yield false; - yield ''; - yield 0; - yield null; - })())); + static::assertCount( + 3, + Dict\filter_nulls((static function (): iterable { + yield null; + yield false; + yield ''; + yield 0; + yield null; + })()), + ); } } diff --git a/tests/unit/Dict/FilterTest.php b/tests/unit/Dict/FilterTest.php index 33c974e9..eaa4c090 100644 --- a/tests/unit/Dict/FilterTest.php +++ b/tests/unit/Dict/FilterTest.php @@ -12,7 +12,7 @@ final class FilterTest extends TestCase /** * @dataProvider provideData */ - public function testFilter(array $expected, array $array, ?callable $predicate = null): void + public function testFilter(array $expected, array $array, null|callable $predicate = null): void { $result = Dict\filter($array, $predicate); @@ -21,10 +21,10 @@ public function testFilter(array $expected, array $array, ?callable $predicate = public function provideData(): iterable { - yield [[], []]; - yield [['a', 'b'], ['a', 'b']]; - yield [[], ['a', 'b'], static fn () => false]; - yield [['a', 'b'], ['a', 'b'], static fn (string $_): bool => true]; - yield [['a'], ['a', 'b'], static fn (string $v): bool => 'b' !== $v]; + yield [[], []]; + yield [['a', 'b'], ['a', 'b']]; + yield [[], ['a', 'b'], static fn() => false]; + yield [['a', 'b'], ['a', 'b'], static fn(string $_): bool => true]; + yield [['a'], ['a', 'b'], static fn(string $v): bool => 'b' !== $v]; } } diff --git a/tests/unit/Dict/FilterWithKeyTest.php b/tests/unit/Dict/FilterWithKeyTest.php index 19b83d7a..9ae62de6 100644 --- a/tests/unit/Dict/FilterWithKeyTest.php +++ b/tests/unit/Dict/FilterWithKeyTest.php @@ -20,7 +20,7 @@ final class FilterWithKeyTest extends TestCase * * @dataProvider provideData */ - public function testFilterWithKey(array $expected, iterable $iterable, ?callable $predicate = null): void + public function testFilterWithKey(array $expected, iterable $iterable, null|callable $predicate = null): void { $result = Dict\filter_with_key($iterable, $predicate); @@ -29,19 +29,19 @@ public function testFilterWithKey(array $expected, iterable $iterable, ?callable public function provideData(): iterable { - yield [[], []]; - yield [['a', 'b'], ['a', 'b']]; - yield [[], ['a', 'b'], static fn (int $_k, string $_v) => false]; - yield [['a', 'b'], ['a', 'b'], static fn (int $_k, string $_v): bool => true]; - yield [['a'], ['a', 'b'], static fn (int $_k, string $v): bool => 'b' !== $v]; - yield [[], ['a', 'b'], static fn (int $k, string $v): bool => 'b' !== $v && 0 !== $k]; - yield [['a'], ['a', 'b'], static fn (int $k, string $v): bool => 'b' !== $v && 1 !== $k]; - yield [[], ['a', 'b'], static fn (int $k, string $v): bool => 'a' !== $v && 1 !== $k]; - yield [[1 => 'b'], ['a', 'b'], static fn (int $k, string $v): bool => 'a' !== $v && 0 !== $k]; - yield [ + yield [[], []]; + yield [['a', 'b'], ['a', 'b']]; + yield [[], ['a', 'b'], static fn(int $_k, string $_v) => false]; + yield [['a', 'b'], ['a', 'b'], static fn(int $_k, string $_v): bool => true]; + yield [['a'], ['a', 'b'], static fn(int $_k, string $v): bool => 'b' !== $v]; + yield [[], ['a', 'b'], static fn(int $k, string $v): bool => 'b' !== $v && 0 !== $k]; + yield [['a'], ['a', 'b'], static fn(int $k, string $v): bool => 'b' !== $v && 1 !== $k]; + yield [[], ['a', 'b'], static fn(int $k, string $v): bool => 'a' !== $v && 1 !== $k]; + yield [[1 => 'b'], ['a', 'b'], static fn(int $k, string $v): bool => 'a' !== $v && 0 !== $k]; + yield [ [1 => 'b'], Collection\Vector::fromArray(['a', 'b']), - static fn (int $k, string $v): bool => 'a' !== $v && 0 !== $k + static fn(int $k, string $v): bool => 'a' !== $v && 0 !== $k, ]; } } diff --git a/tests/unit/Dict/FromEntriesTest.php b/tests/unit/Dict/FromEntriesTest.php index 334e84ab..de521086 100644 --- a/tests/unit/Dict/FromEntriesTest.php +++ b/tests/unit/Dict/FromEntriesTest.php @@ -19,7 +19,7 @@ public function testFromEntries(): void { $array = Dict\from_entries([ [1, 'hello'], - [2, 'world'] + [2, 'world'], ]); static::assertCount(2, $array); diff --git a/tests/unit/Dict/FromKeysTest.php b/tests/unit/Dict/FromKeysTest.php index 61c0e0d1..c1a4b85b 100644 --- a/tests/unit/Dict/FromKeysTest.php +++ b/tests/unit/Dict/FromKeysTest.php @@ -12,7 +12,7 @@ final class FromKeysTest extends TestCase { public function testFromKeys(): void { - $actual = Dict\from_keys(['hello', 'world'], static fn (string $_key) => false); + $actual = Dict\from_keys(['hello', 'world'], static fn(string $_key) => false); static::assertSame('hello', Iter\first_key($actual)); static::assertSame('world', Iter\last_key($actual)); diff --git a/tests/unit/Dict/GroupByTest.php b/tests/unit/Dict/GroupByTest.php index 330e57b0..2246115b 100644 --- a/tests/unit/Dict/GroupByTest.php +++ b/tests/unit/Dict/GroupByTest.php @@ -26,19 +26,17 @@ public function provideData(): array [ [7 => [2], 8 => [3], 9 => [4], 10 => [5], 11 => [6], 12 => [7, 8, 9, 10]], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - static fn ($i) => $i < 2 ? null : (($i >= 7) ? 12 : ($i + 5)), + static fn($i) => $i < 2 ? null : ($i >= 7 ? 12 : ($i + 5)), ], - [ [7 => [2], 8 => [3], 9 => [4], 10 => [5], 11 => [6], 12 => [7], 13 => [8], 14 => [9], 15 => [10]], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - static fn ($i) => $i < 2 ? null : $i + 5, + static fn($i) => $i < 2 ? null : ($i + 5), ], - [ ['username' => ['@azjezz', '@veewee', '@ocramius'], 'name' => ['Saif', 'Toon', 'Marco']], ['@azjezz', 'Saif', '@veewee', 'Toon', '@ocramius', 'Marco'], - static fn ($name) => Str\starts_with($name, '@') ? 'username' : 'name', + static fn($name) => Str\starts_with($name, '@') ? 'username' : 'name', ], ]; } @@ -47,12 +45,9 @@ public function testGroupByThrowsWhenKeyFunReturnsNonArrayKey(): void { $this->expectException(Exception\InvariantViolationException::class); $this->expectExceptionMessage( - 'Expected $key_func to return a value of type array-key, value of type (object) returned.' + 'Expected $key_func to return a value of type array-key, value of type (object) returned.', ); - Dict\group_by( - [0, 1, 2, 3, 4, 5], - static fn ($x) => new Collection\Vector([$x, $x]) - ); + Dict\group_by([0, 1, 2, 3, 4, 5], static fn($x) => new Collection\Vector([$x, $x])); } } diff --git a/tests/unit/Dict/MapKeysTest.php b/tests/unit/Dict/MapKeysTest.php index 140a262d..b2a6fb29 100644 --- a/tests/unit/Dict/MapKeysTest.php +++ b/tests/unit/Dict/MapKeysTest.php @@ -21,9 +21,9 @@ public function testMapKeys(array $expected, array $array, callable $function): public function provideData(): iterable { - yield [[1, 2, 3], [1, 2, 3], static fn (int $k): int => $k]; - yield [[1, 2 => 2, 4 => 3], [1, 2, 3], static fn (int $k): int => $k * 2]; - yield [['0' => 1, '1' => 2, '2' => 3], [1, 2, 3], static fn (int $k): string => (string) $k]; - yield [[], [], static fn (int $k): string => (string) $k]; + yield [[1, 2, 3], [1, 2, 3], static fn(int $k): int => $k]; + yield [[1, 2 => 2, 4 => 3], [1, 2, 3], static fn(int $k): int => $k * 2]; + yield [['0' => 1, '1' => 2, '2' => 3], [1, 2, 3], static fn(int $k): string => (string) $k]; + yield [[], [], static fn(int $k): string => (string) $k]; } } diff --git a/tests/unit/Dict/MapTest.php b/tests/unit/Dict/MapTest.php index d2a6c426..1860b5a7 100644 --- a/tests/unit/Dict/MapTest.php +++ b/tests/unit/Dict/MapTest.php @@ -22,11 +22,11 @@ public function testMap(array $expected, iterable $iterable, callable $function) public function provideData(): iterable { - yield [[1, 2, 3], [1, 2, 3], static fn (int $v): int => $v]; - yield [[2, 4, 6], [1, 2, 3], static fn (int $v): int => $v * 2]; - yield [['1', '2', '3'], [1, 2, 3], static fn (int $v): string => (string)$v]; - yield [['1', '2', '3'], Collection\Map::fromArray([1, 2, 3]), static fn (int $v): string => (string)$v]; - yield [[], Collection\Map::fromArray([]), static fn (int $v): string => (string)$v]; - yield [[], [], static fn (int $v): string => (string)$v]; + yield [[1, 2, 3], [1, 2, 3], static fn(int $v): int => $v]; + yield [[2, 4, 6], [1, 2, 3], static fn(int $v): int => $v * 2]; + yield [['1', '2', '3'], [1, 2, 3], static fn(int $v): string => (string) $v]; + yield [['1', '2', '3'], Collection\Map::fromArray([1, 2, 3]), static fn(int $v): string => (string) $v]; + yield [[], Collection\Map::fromArray([]), static fn(int $v): string => (string) $v]; + yield [[], [], static fn(int $v): string => (string) $v]; } } diff --git a/tests/unit/Dict/MapWithKeyTest.php b/tests/unit/Dict/MapWithKeyTest.php index 984536b3..8cf28392 100644 --- a/tests/unit/Dict/MapWithKeyTest.php +++ b/tests/unit/Dict/MapWithKeyTest.php @@ -21,9 +21,9 @@ public function testMapWithKey(array $expected, array $array, callable $function public function provideData(): iterable { - yield [[1, 3, 5], [1, 2, 3], static fn (int $k, int $v): int => $k + $v]; - yield [[0, 4, 16], [1, 2, 3], static fn (int $k, int $v): int => $k * (2 ** $v)]; - yield [['1', '3', '5'], [1, 2, 3], static fn (int $k, int $v): string => (string) ($k + $v)]; - yield [[], [], static fn (int $k, int $v): string => (string) ($k + $v)]; + yield [[1, 3, 5], [1, 2, 3], static fn(int $k, int $v): int => $k + $v]; + yield [[0, 4, 16], [1, 2, 3], static fn(int $k, int $v): int => $k * (2 ** $v)]; + yield [['1', '3', '5'], [1, 2, 3], static fn(int $k, int $v): string => (string) ($k + $v)]; + yield [[], [], static fn(int $k, int $v): string => (string) ($k + $v)]; } } diff --git a/tests/unit/Dict/MergeTest.php b/tests/unit/Dict/MergeTest.php index 7c8ae510..22304e4d 100644 --- a/tests/unit/Dict/MergeTest.php +++ b/tests/unit/Dict/MergeTest.php @@ -22,24 +22,20 @@ public function provideData(): array return [ [ ['a' => 'b', 'b' => 'c', 'c' => 'd', 'd' => 'e'], - ['a' => 'foo', 'b' => 'bar'], ['a' => 'b'], ['b' => 'c', 'c' => 'd'], ['d' => 'baz'], ['d' => 'e'], ], - [ [0 => 'b', '1000' => 'b', 'c' => 'c'], - [0 => 'a'], [0 => 'b'], ['1000' => 'a'], ['1000' => 'b'], ['c' => 'c'], ], - [ [1, 2, 9, 8], [0 => 1, 1 => 2], diff --git a/tests/unit/Dict/PartitionTest.php b/tests/unit/Dict/PartitionTest.php index 696706b9..d3639244 100644 --- a/tests/unit/Dict/PartitionTest.php +++ b/tests/unit/Dict/PartitionTest.php @@ -24,31 +24,27 @@ public function provideData(): array [ [[1 => 'bar', 2 => 'baz'], [0 => 'foo', 3 => 'qux']], ['foo', 'bar', 'baz', 'qux'], - static fn (string $str) => Str\starts_with($str, 'b'), + static fn(string $str) => Str\starts_with($str, 'b'), ], - [ [[0 => 'foo', 3 => 'qux'], [1 => 'bar', 2 => 'baz']], ['foo', 'bar', 'baz', 'qux'], - static fn (string $str) => !Str\starts_with($str, 'b'), + static fn(string $str) => !Str\starts_with($str, 'b'), ], - [ [[], []], [], - static fn ($_) => false, + static fn($_) => false, ], - [ [[], ['foo', 'bar', 'baz', 'qux']], ['foo', 'bar', 'baz', 'qux'], - static fn (string $str) => false, + static fn(string $_str) => false, ], - [ [['foo', 'bar', 'baz', 'qux'], []], ['foo', 'bar', 'baz', 'qux'], - static fn (string $str) => true, + static fn(string $_str) => true, ], ]; } diff --git a/tests/unit/Dict/PartitionWithKeyTest.php b/tests/unit/Dict/PartitionWithKeyTest.php index b86fff01..a3cdf9bc 100644 --- a/tests/unit/Dict/PartitionWithKeyTest.php +++ b/tests/unit/Dict/PartitionWithKeyTest.php @@ -24,43 +24,37 @@ public function provideData(): array [ [[1 => 'bar', 2 => 'baz'], [0 => 'foo', 3 => 'qux']], ['foo', 'bar', 'baz', 'qux'], - static fn (int $k, string $str) => Str\starts_with($str, 'b'), + static fn(int $_k, string $str) => Str\starts_with($str, 'b'), ], - [ [[0 => 'foo', 3 => 'qux'], [1 => 'bar', 2 => 'baz']], ['foo', 'bar', 'baz', 'qux'], - static fn (int $k, string $str) => !Str\starts_with($str, 'b'), + static fn(int $_k, string $str) => !Str\starts_with($str, 'b'), ], - [ [[], []], [], - static fn ($_k, $_v) => false, + static fn($_k, $_v) => false, ], - [ [[], ['foo', 'bar', 'baz', 'qux']], ['foo', 'bar', 'baz', 'qux'], - static fn (int $k, string $str) => false, + static fn(int $_k, string $_str) => false, ], - [ [['foo', 'bar', 'baz', 'qux'], []], ['foo', 'bar', 'baz', 'qux'], - static fn (int $k, string $str) => true, + static fn(int $_k, string $_str) => true, ], - [ [[1 => 'bar', 2 => 'baz', 3 => 'qux'], ['foo']], ['foo', 'bar', 'baz', 'qux'], - static fn (int $k, string $str) => (bool) $k, + static fn(int $k, string $_str) => (bool) $k, ], - [ [['foo'], [1 => 'bar', 2 => 'baz', 3 => 'qux']], ['foo', 'bar', 'baz', 'qux'], - static fn (int $k, string $str) => !((bool) $k), + static fn(int $k, string $_str) => !((bool) $k), ], ]; } diff --git a/tests/unit/Dict/PullTest.php b/tests/unit/Dict/PullTest.php index 844dac55..3ca5592f 100644 --- a/tests/unit/Dict/PullTest.php +++ b/tests/unit/Dict/PullTest.php @@ -13,15 +13,23 @@ final class PullTest extends TestCase { public function testPull(): void { - $result = Dict\pull( - Vec\range(0, 10), - static fn ($i) => Str\chr($i + 65), - static fn ($i) => 2 ** $i - ); + $result = Dict\pull(Vec\range(0, 10), static fn($i) => Str\chr($i + 65), static fn($i) => 2 ** $i); - static::assertSame([ - 1 => 'A', 2 => 'B', 4 => 'C', 8 => 'D', 16 => 'E', 32 => 'F', - 64 => 'G', 128 => 'H', 256 => 'I', 512 => 'J', 1024 => 'K' - ], $result); + static::assertSame( + [ + 1 => 'A', + 2 => 'B', + 4 => 'C', + 8 => 'D', + 16 => 'E', + 32 => 'F', + 64 => 'G', + 128 => 'H', + 256 => 'I', + 512 => 'J', + 1024 => 'K', + ], + $result, + ); } } diff --git a/tests/unit/Dict/PullWithKeyTest.php b/tests/unit/Dict/PullWithKeyTest.php index 1f564710..91fb5678 100644 --- a/tests/unit/Dict/PullWithKeyTest.php +++ b/tests/unit/Dict/PullWithKeyTest.php @@ -15,13 +15,25 @@ public function testPull(): void { $result = Dict\pull_with_key( Vec\range(0, 10), - static fn ($k, $v) => Str\chr($v + $k + 65), - static fn ($k, $v) => 2 ** ($v + $k) + static fn($k, $v) => Str\chr($v + $k + 65), + static fn($k, $v) => 2 ** ($v + $k), ); - static::assertSame([ - 1 => 'A', 4 => 'C', 16 => 'E', 64 => 'G', 256 => 'I', 1024 => 'K', - 4096 => 'M', 16384 => 'O', 65536 => 'Q', 262144 => 'S', 1048576 => 'U' - ], $result); + static::assertSame( + [ + 1 => 'A', + 4 => 'C', + 16 => 'E', + 64 => 'G', + 256 => 'I', + 1024 => 'K', + 4096 => 'M', + 16384 => 'O', + 65536 => 'Q', + 262144 => 'S', + 1048576 => 'U', + ], + $result, + ); } } diff --git a/tests/unit/Dict/ReindexTest.php b/tests/unit/Dict/ReindexTest.php index b75c5038..a32c9bf7 100644 --- a/tests/unit/Dict/ReindexTest.php +++ b/tests/unit/Dict/ReindexTest.php @@ -11,7 +11,7 @@ final class ReindexTest extends TestCase { public function testReindex(): void { - $result = Dict\reindex([1, 2, 3], static fn (int $value): int => $value); + $result = Dict\reindex([1, 2, 3], static fn(int $value): int => $value); static::assertSame([1 => 1, 2 => 2, 3 => 3], $result); } diff --git a/tests/unit/Dict/SelectKeysTest.php b/tests/unit/Dict/SelectKeysTest.php index 525646ca..fd343438 100644 --- a/tests/unit/Dict/SelectKeysTest.php +++ b/tests/unit/Dict/SelectKeysTest.php @@ -25,25 +25,21 @@ public function provideData(): array ['foo' => 'bar', 'bar' => 'baz', 'baz' => 'qux', 'qux' => 'foo'], ['foo', 'bar'], ], - [ [], ['baz' => 'qux', 'qux' => 'foo'], ['foo', 'bar'], ], - [ [], [], ['foo', 'bar'], ], - [ [], ['foo' => 'bar', 'bar' => 'baz', 'baz' => 'qux', 'qux' => 'foo'], [], ], - [ [], ['foo' => 'bar', 'bar' => 'baz', 'baz' => 'qux', 'qux' => 'foo'], diff --git a/tests/unit/Dict/SliceTest.php b/tests/unit/Dict/SliceTest.php index bdbe2fd3..1c769f94 100644 --- a/tests/unit/Dict/SliceTest.php +++ b/tests/unit/Dict/SliceTest.php @@ -12,7 +12,7 @@ final class SliceTest extends TestCase /** * @dataProvider provideData */ - public function testSlice(array $expected, array $array, int $n, ?int $l = null): void + public function testSlice(array $expected, array $array, int $n, null|int $l = null): void { $result = Dict\slice($array, $n, $l); diff --git a/tests/unit/Dict/SortByKeyTest.php b/tests/unit/Dict/SortByKeyTest.php index d11bba5a..e45e1bfa 100644 --- a/tests/unit/Dict/SortByKeyTest.php +++ b/tests/unit/Dict/SortByKeyTest.php @@ -13,7 +13,7 @@ final class SortByKeyTest extends TestCase /** * @dataProvider provideData */ - public function testSortByKey(array $expected, array $array, ?callable $comparator = null): void + public function testSortByKey(array $expected, array $array, null|callable $comparator = null): void { static::assertSame($expected, Dict\sort_by_key($array, $comparator)); } @@ -26,11 +26,10 @@ public function provideData(): array ['d' => 'lemon', 'a' => 'orange', 'b' => 'banana', 'c' => 'apple'], null, ], - [ ['d' => 'lemon', 'c' => 'apple', 'b' => 'banana', 'a' => 'orange'], ['d' => 'lemon', 'a' => 'orange', 'b' => 'banana', 'c' => 'apple'], - static fn (string $a, string $b) => Str\ord($a) > Str\ord($b) ? -1 : 1, + static fn(string $a, string $b) => Str\ord($a) > Str\ord($b) ? -1 : 1, ], ]; } diff --git a/tests/unit/Dict/SortByTest.php b/tests/unit/Dict/SortByTest.php index 2a723fa7..497d666a 100644 --- a/tests/unit/Dict/SortByTest.php +++ b/tests/unit/Dict/SortByTest.php @@ -14,19 +14,19 @@ final class SortByTest extends TestCase /** * @dataProvider provideData */ - public function testSortBy(array $expected, array $array, callable $scalar_fun, ?callable $comp = null): void + public function testSortBy(array $expected, array $array, callable $scalar_fun, null|callable $comp = null): void { static::assertSame($expected, Dict\sort_by($array, $scalar_fun, $comp)); } public function provideData(): array { - $a = [1, 2]; - $b = [1, 2, 3, 4]; - $c = ['a' => 'foo', 'b' => 'bar', 'c' => 'baz', 'd' => 'qux', 'e' => 'lax']; + $a = [1, 2]; + $b = [1, 2, 3, 4]; + $c = ['a' => 'foo', 'b' => 'bar', 'c' => 'baz', 'd' => 'qux', 'e' => 'lax']; - $expected = [2 => $a, 0 => $b, 1 => $c]; - $array = [$b, $c, $a]; + $expected = [2 => $a, 0 => $b, 1 => $c]; + $array = [$b, $c, $a]; $scalar_fun = /** * @param array $array @@ -35,7 +35,7 @@ public function provideData(): array * * @pure */ - static fn (array $array): int => Iter\count($array); + static fn(array $array): int => Iter\count($array); return [ [ @@ -43,7 +43,6 @@ public function provideData(): array $array, $scalar_fun, ], - [ [1 => 'a', 2 => 'b', 3 => 'c', 0 => 'd'], ['d', 'a', 'b', 'c'], @@ -54,9 +53,8 @@ public function provideData(): array * * @pure */ - static fn ($v) => $v, + static fn($v) => $v, ], - [ ['a'], ['a'], @@ -67,9 +65,8 @@ public function provideData(): array * * @pure */ - static fn ($v) => $v, + static fn($v) => $v, ], - [ [0 => 'd', 3 => 'c', 2 => 'b', 1 => 'a'], ['d', 'a', 'b', 'c'], @@ -80,8 +77,7 @@ public function provideData(): array * * @pure */ - static fn ($v) => $v, - + static fn($v) => $v, /** * @param string $a * @param string $b @@ -90,9 +86,8 @@ public function provideData(): array * * @pure */ - static fn (string $a, string $b) => Str\ord($a) > Str\ord($b) ? -1 : 1, + static fn(string $a, string $b) => Str\ord($a) > Str\ord($b) ? -1 : 1, ], - [ ['foo' => 'bar', 'baz' => 'qux'], ['foo' => 'bar', 'baz' => 'qux'], @@ -103,9 +98,8 @@ public function provideData(): array * * @pure */ - static fn ($v) => $v, + static fn($v) => $v, ], - [ [4 => 'jumped', 0 => 'the', 1 => 'quick', 2 => 'brown', 3 => 'fox'], ['the', 'quick', 'brown', 'fox', 'jumped'], @@ -116,7 +110,7 @@ public function provideData(): array * * @pure */ - static fn ($v) => Str\Byte\reverse($v), + static fn($v) => Str\Byte\reverse($v), ], ]; } diff --git a/tests/unit/Dict/SortTest.php b/tests/unit/Dict/SortTest.php index 9a8d8fe7..f2a42ff4 100644 --- a/tests/unit/Dict/SortTest.php +++ b/tests/unit/Dict/SortTest.php @@ -12,7 +12,7 @@ final class SortTest extends TestCase /** * @dataProvider provideData */ - public function testSort(array $expected, array $array, ?callable $comparator = null): void + public function testSort(array $expected, array $array, null|callable $comparator = null): void { static::assertSame($expected, Dict\sort($array, $comparator)); } @@ -24,7 +24,6 @@ public function provideData(): array [1 => 'a', 2 => 'b', 0 => 'c'], ['c', 'a', 'b'], ], - [ [8, 9, 10], [8, 9, 10], @@ -36,9 +35,8 @@ public function provideData(): array * * @pure */ - static fn (int $a, int $b) => $a <=> $b ? -1 : 1, + static fn(int $a, int $b) => $a <=> $b ? -1 : 1, ], - [ ['foo' => 'bar', 'bar' => 'baz'], ['foo' => 'bar', 'bar' => 'baz'], diff --git a/tests/unit/Dict/TakeWhileTest.php b/tests/unit/Dict/TakeWhileTest.php index 4ad72abf..9e0ca9e8 100644 --- a/tests/unit/Dict/TakeWhileTest.php +++ b/tests/unit/Dict/TakeWhileTest.php @@ -21,9 +21,9 @@ public function testTakeWhile(array $expected, array $array, callable $callable) public function provideData(): iterable { - yield [[], [1, 2, 3, 4, 5], static fn (int $_): bool => false]; - yield [[1, 2, 3], [1, 2, 3, 4, 5], static fn (int $i) => $i <= 3]; - yield [[1, 2], [1, 2, 3, 4, 5], static fn (int $i) => $i <= 2]; - yield [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], static fn (int $_) => true]; + yield [[], [1, 2, 3, 4, 5], static fn(int $_): bool => false]; + yield [[1, 2, 3], [1, 2, 3, 4, 5], static fn(int $i) => $i <= 3]; + yield [[1, 2], [1, 2, 3, 4, 5], static fn(int $i) => $i <= 2]; + yield [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], static fn(int $_) => true]; } } diff --git a/tests/unit/Dict/UniqueByTest.php b/tests/unit/Dict/UniqueByTest.php index db98b74c..90ce5065 100644 --- a/tests/unit/Dict/UniqueByTest.php +++ b/tests/unit/Dict/UniqueByTest.php @@ -24,13 +24,12 @@ public function provideData(): array [ [0 => 'a', 4 => 'saif'], ['a', 'b', 'c', 'd', 'saif', 'jack'], - static fn (string $value): int => Str\length($value), + static fn(string $value): int => Str\length($value), ], - [ [0 => 'foo', 2 => 'bar', 4 => '@baz'], ['foo', '@foo', 'bar', '@bar', '@baz'], - static fn (string $value): string => Str\replace($value, '@', ''), + static fn(string $value): string => Str\replace($value, '@', ''), ], ]; } diff --git a/tests/unit/Dict/UniqueScalarTest.php b/tests/unit/Dict/UniqueScalarTest.php index 1a21d195..c637ba17 100644 --- a/tests/unit/Dict/UniqueScalarTest.php +++ b/tests/unit/Dict/UniqueScalarTest.php @@ -14,7 +14,7 @@ final class UniqueScalarTest extends TestCase { public function testUniqueScalars(): void { - $array = Vec\fill(10, 'foo'); + $array = Vec\fill(10, 'foo'); $array[] = 'bar'; $unique = Dict\unique_scalar($array); diff --git a/tests/unit/Dict/UniqueTest.php b/tests/unit/Dict/UniqueTest.php index 3adfaa50..03cff6f7 100644 --- a/tests/unit/Dict/UniqueTest.php +++ b/tests/unit/Dict/UniqueTest.php @@ -27,7 +27,7 @@ public function testUniqueWithObjects(): void { $array = Vec\fill(10, 'foo'); $object = new Collection\Map([]); - $array = Vec\concat($array, Vec\fill(10, $object)); + $array = Vec\concat($array, Vec\fill(10, $object)); $unique = Dict\unique($array); diff --git a/tests/unit/File/ReadWriteHandleTest.php b/tests/unit/File/ReadWriteHandleTest.php index 7cd833ba..70cd7337 100644 --- a/tests/unit/File/ReadWriteHandleTest.php +++ b/tests/unit/File/ReadWriteHandleTest.php @@ -114,7 +114,7 @@ public function testAppendToANonWritableFile(): void } $temporary_file = Filesystem\create_temporary_file(); - Filesystem\change_permissions($temporary_file, 0555); + Filesystem\change_permissions($temporary_file, 0o555); $this->expectException(File\Exception\NotWritableException::class); $this->expectExceptionMessage('File "' . $temporary_file . '" is not writable.'); @@ -129,7 +129,7 @@ public function testOpenNonReadableFile(): void } $temporary_file = Filesystem\create_temporary_file(); - Filesystem\change_permissions($temporary_file, 0333); + Filesystem\change_permissions($temporary_file, 0o333); $this->expectException(File\Exception\NotReadableException::class); $this->expectExceptionMessage('File "' . $temporary_file . '" is not readable.'); @@ -146,7 +146,7 @@ public function testThrowsWhenCreatingFile(): void $temporary_file = Filesystem\create_temporary_file(); Filesystem\delete_file($temporary_file); Filesystem\create_directory($temporary_file); - Filesystem\change_permissions($temporary_file, 0555); + Filesystem\change_permissions($temporary_file, 0o555); $file = $temporary_file . Filesystem\SEPARATOR . 'foo'; diff --git a/tests/unit/File/ReadWriteTest.php b/tests/unit/File/ReadWriteTest.php index f1a1b9db..ad7080bf 100644 --- a/tests/unit/File/ReadWriteTest.php +++ b/tests/unit/File/ReadWriteTest.php @@ -96,8 +96,8 @@ public function testWriteFileThrowsForNonWritableFiles(): void { $file = Str\join([$this->directory, 'write.txt'], Filesystem\SEPARATOR); Filesystem\create_file($file); - $permissions = Filesystem\get_permissions($file) & 0777; - Filesystem\change_permissions($file, 0111); + $permissions = Filesystem\get_permissions($file) & 0o777; + Filesystem\change_permissions($file, 0o111); try { $this->expectException(File\Exception\NotWritableException::class); @@ -132,9 +132,10 @@ public function testThrowsWhenDirectoryCreationFails(): void } $target_directory = Env\temp_dir() . DIRECTORY_SEPARATOR . 'you-shall-not-pass'; - Filesystem\create_directory($target_directory, 0000); + Filesystem\create_directory($target_directory, 0o000); - $target_file = $target_directory . DIRECTORY_SEPARATOR . 'fails-on-subdir-creation' . DIRECTORY_SEPARATOR . 'somefile.txt'; + $target_file = + $target_directory . DIRECTORY_SEPARATOR . 'fails-on-subdir-creation' . DIRECTORY_SEPARATOR . 'somefile.txt'; $this->expectException(File\Exception\RuntimeException::class); $this->expectExceptionMessage('Failed to create the directory for file "' . $target_file . '".'); diff --git a/tests/unit/File/WriteHandleTest.php b/tests/unit/File/WriteHandleTest.php index ef12c68d..03591499 100644 --- a/tests/unit/File/WriteHandleTest.php +++ b/tests/unit/File/WriteHandleTest.php @@ -36,7 +36,7 @@ public function testAppendToNonExistingFile(): void public function testAppendToANonWritableFile(): void { $temporary_file = Filesystem\create_temporary_file(); - Filesystem\change_permissions($temporary_file, 0555); + Filesystem\change_permissions($temporary_file, 0o555); $this->expectException(File\Exception\NotWritableException::class); $this->expectExceptionMessage('is not writable.'); @@ -70,7 +70,7 @@ public function testThrowsWhenCreatingFile(): void $temporary_file = Filesystem\create_temporary_file(); Filesystem\delete_file($temporary_file); Filesystem\create_directory($temporary_file); - Filesystem\change_permissions($temporary_file, 0555); + Filesystem\change_permissions($temporary_file, 0o555); $file = $temporary_file . Filesystem\SEPARATOR . 'foo'; @@ -100,9 +100,10 @@ public function testThrowsWhenDirectoryCreationFails(): void } $target_directory = Env\temp_dir() . DIRECTORY_SEPARATOR . 'you-shall-not-pass'; - Filesystem\create_directory($target_directory, 0000); + Filesystem\create_directory($target_directory, 0o000); - $target_file = $target_directory . DIRECTORY_SEPARATOR . 'fails-on-subdir-creation' . DIRECTORY_SEPARATOR . 'somefile.txt'; + $target_file = + $target_directory . DIRECTORY_SEPARATOR . 'fails-on-subdir-creation' . DIRECTORY_SEPARATOR . 'somefile.txt'; $this->expectException(File\Exception\RuntimeException::class); $this->expectExceptionMessage('Failed to create the directory for file "' . $target_file . '".'); diff --git a/tests/unit/Filesystem/AbstractFilesystemTest.php b/tests/unit/Filesystem/AbstractFilesystemTest.php index 7436026d..3fb98c85 100644 --- a/tests/unit/Filesystem/AbstractFilesystemTest.php +++ b/tests/unit/Filesystem/AbstractFilesystemTest.php @@ -24,13 +24,18 @@ protected function setUp(): void static::markTestSkipped('Test can only be executed under *nix OS.'); } - $this->cacheDirectory = Type\string()->assert(Filesystem\canonicalize(Str\join([ - __DIR__, '..', '.cache' - ], Filesystem\SEPARATOR))); + $this->cacheDirectory = Type\string()->assert(Filesystem\canonicalize(Str\join( + [ + __DIR__, + '..', + '.cache', + ], + Filesystem\SEPARATOR, + ))); $this->directory = Str\join([$this->cacheDirectory, $this->function], Filesystem\SEPARATOR); Filesystem\create_directory($this->directory); - $this->directoryPermissions = Filesystem\get_permissions($this->directory) & 0777; + $this->directoryPermissions = Filesystem\get_permissions($this->directory) & 0o777; static::assertTrue(Filesystem\exists($this->directory)); static::assertTrue(Filesystem\is_directory($this->directory)); diff --git a/tests/unit/Filesystem/CopyTest.php b/tests/unit/Filesystem/CopyTest.php index 9a2333c7..f086ef6e 100644 --- a/tests/unit/Filesystem/CopyTest.php +++ b/tests/unit/Filesystem/CopyTest.php @@ -46,7 +46,7 @@ public function testCopyExecutableBits(): void $shell_file = Str\join([$this->directory, 'hello.sh'], Filesystem\SEPARATOR); Filesystem\create_file($shell_file); - Filesystem\change_permissions($shell_file, 0557); + Filesystem\change_permissions($shell_file, 0o557); static::assertTrue(Filesystem\is_executable($shell_file)); diff --git a/tests/unit/Filesystem/DirectoryTest.php b/tests/unit/Filesystem/DirectoryTest.php index 652928bc..7b7bc788 100644 --- a/tests/unit/Filesystem/DirectoryTest.php +++ b/tests/unit/Filesystem/DirectoryTest.php @@ -15,21 +15,32 @@ final class DirectoryTest extends AbstractFilesystemTest public function testReadDirectory(): void { - Filesystem\create_file(Str\join([ - $this->directory, 'hello.txt' - ], Filesystem\SEPARATOR)); - - Filesystem\create_directory(Str\join([ - $this->directory, 'foo' - ], Filesystem\SEPARATOR)); + Filesystem\create_file(Str\join( + [ + $this->directory, + 'hello.txt', + ], + Filesystem\SEPARATOR, + )); + + Filesystem\create_directory(Str\join( + [ + $this->directory, + 'foo', + ], + Filesystem\SEPARATOR, + )); $children = Filesystem\read_directory($this->directory); static::assertCount(2, $children); - static::assertSame([ - Str\join([$this->directory, 'foo'], Filesystem\SEPARATOR), - Str\join([$this->directory, 'hello.txt'], Filesystem\SEPARATOR), - ], Vec\sort($children)); + static::assertSame( + [ + Str\join([$this->directory, 'foo'], Filesystem\SEPARATOR), + Str\join([$this->directory, 'hello.txt'], Filesystem\SEPARATOR), + ], + Vec\sort($children), + ); } public function testReadDirectoryThrowsIfDirectoryDoesNotExist(): void @@ -42,9 +53,13 @@ public function testReadDirectoryThrowsIfDirectoryDoesNotExist(): void public function testReadDirectoryThrowsIfNotDirectory(): void { - $filename = Str\join([ - $this->directory, 'hello.txt' - ], Filesystem\SEPARATOR); + $filename = Str\join( + [ + $this->directory, + 'hello.txt', + ], + Filesystem\SEPARATOR, + ); Filesystem\create_file($filename); @@ -56,7 +71,7 @@ public function testReadDirectoryThrowsIfNotDirectory(): void public function testReadDirectoryThrowsIfNotReadable(): void { - Filesystem\change_permissions($this->directory, 0077); + Filesystem\change_permissions($this->directory, 0o077); $this->expectException(Filesystem\Exception\NotReadableException::class); $this->expectExceptionMessage('Directory "' . $this->directory . '" is not readable.'); @@ -66,7 +81,7 @@ public function testReadDirectoryThrowsIfNotReadable(): void } finally { // restore $this->directory permissions, otherwise we won't // be able to delete it. - Filesystem\change_permissions($this->directory, 0777); + Filesystem\change_permissions($this->directory, 0o777); } } diff --git a/tests/unit/Filesystem/FileTest.php b/tests/unit/Filesystem/FileTest.php index 97e7f4c2..f8ded392 100644 --- a/tests/unit/Filesystem/FileTest.php +++ b/tests/unit/Filesystem/FileTest.php @@ -60,7 +60,7 @@ public function testTemporaryFileThrowsForPrefixWithSeparator(): void $this->expectException(Filesystem\Exception\InvalidArgumentException::class); $this->expectExceptionMessage( - '$prefix should not contain a directory separator ( "' . Filesystem\SEPARATOR . '" ).' + '$prefix should not contain a directory separator ( "' . Filesystem\SEPARATOR . '" ).', ); Filesystem\create_temporary_file($this->directory, $prefix); @@ -174,8 +174,8 @@ public function testFileSizeThrowsForNonReadableFile(): void { $filename = Str\join([$this->directory, 'non-readable.txt'], Filesystem\SEPARATOR); Filesystem\create_file($filename); - $permissions = Filesystem\get_permissions($filename) & 0777; - Filesystem\change_permissions($filename, 0111); + $permissions = Filesystem\get_permissions($filename) & 0o777; + Filesystem\change_permissions($filename, 0o111); static::assertFalse(Filesystem\is_readable($filename)); @@ -193,12 +193,11 @@ public function testCopyThrowsForNonReadableFile(): void { $file = Str\join([$this->directory, 'non-readable.txt'], Filesystem\SEPARATOR); Filesystem\create_file($file); - $permissions = Filesystem\get_permissions($file) & 0777; - Filesystem\change_permissions($file, 0111); + $permissions = Filesystem\get_permissions($file) & 0o777; + Filesystem\change_permissions($file, 0o111); static::assertFalse(Filesystem\is_readable($file)); - $this->expectException(Filesystem\Exception\NotReadableException::class); $this->expectExceptionMessage('File "' . $file . '" is not readable.'); diff --git a/tests/unit/Filesystem/PathTest.php b/tests/unit/Filesystem/PathTest.php index ebda5755..906ffdb2 100644 --- a/tests/unit/Filesystem/PathTest.php +++ b/tests/unit/Filesystem/PathTest.php @@ -17,7 +17,7 @@ public function testPathInformation( string $directory, string $basename, string $filename, - ?string $extension + null|string $extension, ): void { static::assertSame($directory, Filesystem\get_directory($path)); static::assertSame($basename, Filesystem\get_basename($path)); @@ -32,7 +32,7 @@ public function providePathInformationData(): iterable '/home/azjezz/Projects/psl/src', 'bootstrap.php', 'bootstrap', - 'php' + 'php', ]; yield [ @@ -40,7 +40,7 @@ public function providePathInformationData(): iterable '/home/azjezz/Projects/psl/src', 'bootstrap.', 'bootstrap', - null + null, ]; yield [ @@ -48,7 +48,7 @@ public function providePathInformationData(): iterable '/home/azjezz/Projects/psl/src', 'Psl', 'Psl', - null + null, ]; } @@ -59,9 +59,6 @@ public function testGetBasenameWithSuffix(): void public function testGetDirectoryWithMultipleLevels(): void { - static::assertSame( - '/home/azjezz/Projects', - Filesystem\get_directory('/home/azjezz/Projects/psl/src/Psl', 3) - ); + static::assertSame('/home/azjezz/Projects', Filesystem\get_directory('/home/azjezz/Projects/psl/src/Psl', 3)); } } diff --git a/tests/unit/Filesystem/PermissionsTest.php b/tests/unit/Filesystem/PermissionsTest.php index 6c67c1aa..8ee5491d 100644 --- a/tests/unit/Filesystem/PermissionsTest.php +++ b/tests/unit/Filesystem/PermissionsTest.php @@ -17,34 +17,34 @@ public function testChangePermissions(): void Filesystem\create_file($filename); - $permissions = Filesystem\get_permissions($filename) & 0777; + $permissions = Filesystem\get_permissions($filename) & 0o777; try { - Filesystem\change_permissions($filename, 0444); + Filesystem\change_permissions($filename, 0o444); static::assertTrue(Filesystem\is_readable($filename)); static::assertFalse(Filesystem\is_writable($filename)); static::assertFalse(Filesystem\is_executable($filename)); - Filesystem\change_permissions($filename, 0222); + Filesystem\change_permissions($filename, 0o222); static::assertTrue(Filesystem\is_writable($filename)); static::assertFalse(Filesystem\is_readable($filename)); static::assertFalse(Filesystem\is_executable($filename)); - Filesystem\change_permissions($filename, 0111); + Filesystem\change_permissions($filename, 0o111); static::assertTrue(Filesystem\is_executable($filename)); static::assertFalse(Filesystem\is_writable($filename)); static::assertFalse(Filesystem\is_readable($filename)); - Filesystem\change_permissions($filename, 0666); + Filesystem\change_permissions($filename, 0o666); static::assertTrue(Filesystem\is_writable($filename)); static::assertTrue(Filesystem\is_readable($filename)); static::assertFalse(Filesystem\is_executable($filename)); - Filesystem\change_permissions($filename, 0777); + Filesystem\change_permissions($filename, 0o777); static::assertTrue(Filesystem\is_writable($filename)); static::assertTrue(Filesystem\is_readable($filename)); @@ -61,7 +61,7 @@ public function testChangePermissionsThrowsForNonExistingFile(): void $this->expectException(Filesystem\Exception\NotFoundException::class); $this->expectExceptionMessage('Node "' . $filename . '" is not found.'); - Filesystem\change_permissions($filename, 0111); + Filesystem\change_permissions($filename, 0o111); } public function testGetPermissionsThrowsForNonExistingFile(): void diff --git a/tests/unit/Fun/AfterTest.php b/tests/unit/Fun/AfterTest.php index f3bbbfe7..895a155c 100644 --- a/tests/unit/Fun/AfterTest.php +++ b/tests/unit/Fun/AfterTest.php @@ -12,20 +12,14 @@ final class AfterTest extends TestCase { public function testItCombinesAFunctionToExecuteAFunctionAfterAnotherFunction(): void { - $x = Fun\after( - static fn (string $x): string => $x . ' world', - static fn (string $z): string => $z . '!!' - ); + $x = Fun\after(static fn(string $x): string => $x . ' world', static fn(string $z): string => $z . '!!'); static::assertSame('Hello world!!', $x('Hello')); } public function testItCombinesAFunctionThatDealWithDifferentTypes(): void { - $x = Fun\after( - static fn (string $x): int => Str\length($x), - static fn (int $z): string => $z . '!' - ); + $x = Fun\after(static fn(string $x): int => Str\length($x), static fn(int $z): string => $z . '!'); static::assertSame('5!', $x('Hello')); } diff --git a/tests/unit/Fun/LazyTest.php b/tests/unit/Fun/LazyTest.php index a8ce24e5..accfbb4f 100644 --- a/tests/unit/Fun/LazyTest.php +++ b/tests/unit/Fun/LazyTest.php @@ -25,7 +25,7 @@ public function testItDoesNotLoadInitializerDuringCreation(): void public function testItCanBeUsedAsALazyProxy(): void { - $proxy = Fun\lazy(static fn (): int => 132); + $proxy = Fun\lazy(static fn(): int => 132); static::assertSame(132, $proxy()); } @@ -38,7 +38,7 @@ public function doSomething(): int return 132; } }; - $proxy = Fun\lazy(static fn (): object => $x); + $proxy = Fun\lazy(static fn(): object => $x); static::assertSame($x, $proxy()); static::assertSame($x, $proxy()); diff --git a/tests/unit/Fun/PipeTest.php b/tests/unit/Fun/PipeTest.php index cfed2724..66e2e815 100644 --- a/tests/unit/Fun/PipeTest.php +++ b/tests/unit/Fun/PipeTest.php @@ -13,9 +13,9 @@ final class PipeTest extends TestCase public function testItCombinesMultipleFunctionToExecutesInOrder(): void { $x = Fun\pipe( - static fn (string $x): string => $x . ' world', - static fn (string $y): string => $y . '?', - static fn (string $z): string => $z . '!', + static fn(string $x): string => $x . ' world', + static fn(string $y): string => $y . '?', + static fn(string $z): string => $z . '!', ); static::assertSame('Hello world?!', $x('Hello')); @@ -23,10 +23,7 @@ public function testItCombinesMultipleFunctionToExecutesInOrder(): void public function testItCombinesMultipleFunctionsThatDealWithDifferentTypes(): void { - $x = Fun\pipe( - static fn (string $x): int => Str\length($x), - static fn (int $y): string => $y . '!' - ); + $x = Fun\pipe(static fn(string $x): int => Str\length($x), static fn(int $y): string => $y . '!'); static::assertSame('5!', $x('Hello')); } diff --git a/tests/unit/Fun/RethrowTest.php b/tests/unit/Fun/RethrowTest.php index 5cb62043..2ceeb19e 100644 --- a/tests/unit/Fun/RethrowTest.php +++ b/tests/unit/Fun/RethrowTest.php @@ -13,7 +13,7 @@ final class RethrowTest extends TestCase public function testRethrow(): void { $exception = new Exception('foo'); - $rethrow = Fun\rethrow(); + $rethrow = Fun\rethrow(); $this->expectExceptionObject($exception); $rethrow($exception); diff --git a/tests/unit/Fun/TapTest.php b/tests/unit/Fun/TapTest.php index 8e4046f0..6c4db946 100644 --- a/tests/unit/Fun/TapTest.php +++ b/tests/unit/Fun/TapTest.php @@ -15,11 +15,9 @@ final class TapTest extends TestCase public function testItWorksAsACurriedFunctionThatCanBeUsedForPerformingSideEffects(): void { $log = new Ref('123'); - $call = Fun\tap( - static function (string $x) use ($log): void { - $log->value .= $x; - } - ); + $call = Fun\tap(static function (string $x) use ($log): void { + $log->value .= $x; + }); static::assertSame('abc', $call('abc')); static::assertSame('123abc', $log->value); @@ -32,11 +30,11 @@ public function testItCanBeCombinedInOtherFlowsForDebugging(): void { $log = new Ref(''); $result = Fun\pipe( - static fn (string $x) => Hash\hash($x, Hash\Algorithm::Md5), + static fn(string $x) => Hash\hash($x, Hash\Algorithm::Md5), Fun\tap(static function ($x) use ($log): void { $log->value = $x; }), - static fn (string $x): string => Str\truncate($x, 0, 1), + static fn(string $x): string => Str\truncate($x, 0, 1), )('abc'); $md5 = Hash\hash('abc', Hash\Algorithm::Md5); diff --git a/tests/unit/Fun/WhenTest.php b/tests/unit/Fun/WhenTest.php index 5ff57f8e..c627e065 100644 --- a/tests/unit/Fun/WhenTest.php +++ b/tests/unit/Fun/WhenTest.php @@ -14,7 +14,7 @@ public function testItRunsLeftFunction(): void $greet = Fun\when( static fn(string $name): bool => $name === 'Jos', static fn(string $name): string => 'Bonjour ' . $name . '!', - static fn(string $name): string => 'Hello ' . $name . '!' + static fn(string $name): string => 'Hello ' . $name . '!', ); static::assertSame('Bonjour Jos!', $greet('Jos')); @@ -25,7 +25,7 @@ public function testItRunsRightfunction(): void $greet = Fun\when( static fn(string $name): bool => $name === 'Jos', static fn(string $name): string => 'Bonjour ' . $name . '!', - static fn(string $name): string => 'Hello ' . $name . '!' + static fn(string $name): string => 'Hello ' . $name . '!', ); static::assertSame('Hello World!', $greet('World')); diff --git a/tests/unit/Hash/ContextTest.php b/tests/unit/Hash/ContextTest.php index 5503d4c6..a880bb7e 100644 --- a/tests/unit/Hash/ContextTest.php +++ b/tests/unit/Hash/ContextTest.php @@ -11,27 +11,27 @@ final class ContextTest extends TestCase { public function testForAlgorithm(): void { - $context = Hash\Context::forAlgorithm(Hash\Algorithm::Md5) - ->update('The quick brown fox ') - ->update('jumped over the lazy dog.'); + $context = Hash\Context::forAlgorithm(Hash\Algorithm::Md5)->update('The quick brown fox ')->update( + 'jumped over the lazy dog.', + ); static::assertSame('5c6ffbdd40d9556b73a21e63c3e0e904', $context->finalize()); } public function testHmac(): void { - $context = Hash\Context::hmac(Hash\Hmac\Algorithm::Md5, 'secret') - ->update('The quick brown fox ') - ->update('jumped over the lazy dog.'); + $context = Hash\Context::hmac(Hash\Hmac\Algorithm::Md5, 'secret')->update('The quick brown fox ')->update( + 'jumped over the lazy dog.', + ); static::assertSame('7eb2b5c37443418fc77c136dd20e859c', $context->finalize()); } public function testContextIsImmutable(): void { - $first = Hash\Context::forAlgorithm(Hash\Algorithm::Md5); + $first = Hash\Context::forAlgorithm(Hash\Algorithm::Md5); $second = $first->update('The quick brown fox '); - $third = $second->update('jumped over the lazy dog.'); + $third = $second->update('jumped over the lazy dog.'); static::assertNotSame($first, $second); static::assertNotSame($second, $third); @@ -44,9 +44,9 @@ public function testContextIsImmutable(): void public function testContextIsStillValidAfterFinalization(): void { - $context = Hash\Context::forAlgorithm(Hash\Algorithm::Md5) - ->update('The quick brown fox ') - ->update('jumped over the lazy dog.'); + $context = Hash\Context::forAlgorithm(Hash\Algorithm::Md5)->update('The quick brown fox ')->update( + 'jumped over the lazy dog.', + ); static::assertSame('5c6ffbdd40d9556b73a21e63c3e0e904', $context->finalize()); static::assertSame('5983132dd3e26f51fa8611a94c8e05ac', $context->update(' cool!')->finalize()); diff --git a/tests/unit/IO/MemoryHandleTest.php b/tests/unit/IO/MemoryHandleTest.php index 9f22d836..3dc3319e 100644 --- a/tests/unit/IO/MemoryHandleTest.php +++ b/tests/unit/IO/MemoryHandleTest.php @@ -116,7 +116,7 @@ public function testReadAtInvalidOffset(): void public function testReadTooMuch(): void { - $h = new IO\MemoryHandle("herpderp"); + $h = new IO\MemoryHandle('herpderp'); $this->expectException(IO\Exception\RuntimeException::class); $this->expectExceptionMessage('Reached end of file before requested size.'); diff --git a/tests/unit/IO/PipeTest.php b/tests/unit/IO/PipeTest.php index a0c06ab8..310ade34 100644 --- a/tests/unit/IO/PipeTest.php +++ b/tests/unit/IO/PipeTest.php @@ -62,7 +62,10 @@ public function testReadWriteInParallel(): void $read_result = $read_awaitable->await(); static::assertSame('hello', $read_result); - static::assertSame('[read:sleep][write:sleep][read:start][write:start][write:complete][write:close][read:complete][read:close]', $spy->value); + static::assertSame( + '[read:sleep][write:sleep][read:start][write:start][write:complete][write:close][read:complete][read:close]', + $spy->value, + ); } public function testReadFixedSize(): void diff --git a/tests/unit/Interface/InterfaceTest.php b/tests/unit/Interface/InterfaceTest.php index 69389169..e46d6d9f 100644 --- a/tests/unit/Interface/InterfaceTest.php +++ b/tests/unit/Interface/InterfaceTest.php @@ -14,10 +14,8 @@ final class InterfaceTest extends TestCase /** * @dataProvider provideData */ - public function test( - string $interface_name, - bool $exists, - ): void { + public function test(string $interface_name, bool $exists): void + { static::assertSame($exists, Interface\exists($interface_name)); static::assertSame($exists, Interface\defined($interface_name)); } diff --git a/tests/unit/Iter/AllTest.php b/tests/unit/Iter/AllTest.php index ba7a952d..65cf51fb 100644 --- a/tests/unit/Iter/AllTest.php +++ b/tests/unit/Iter/AllTest.php @@ -19,17 +19,17 @@ public function testAll(bool $expected, iterable $iterable, callable $predicate) public function provideData(): iterable { - yield [false, [false, true, true], static fn (bool $value): bool => $value]; - yield [false, [false, true, true], static fn (bool $value): bool => !$value]; - yield [true, [true, true, true], static fn (bool $value): bool => $value]; - yield [false, [true, true, true], static fn (bool $value): bool => !$value]; - yield [false, [false, false, false], static fn (bool $value): bool => $value]; - yield [true, [false, false, false], static fn (bool $value): bool => !$value]; - yield [true, [false, false, false], static fn (bool $value): bool => true]; - yield [false, [false, false, false], static fn (bool $value): bool => false]; - yield [false, [1, 2, 3], static fn (int $i): bool => $i > 3]; - yield [true, [4, 5, 6], static fn (int $i): bool => $i > 3]; - yield [false, [1, 2, 3, 4, 5, 6], static fn (int $i): bool => $i > 3]; - yield [true, [], static fn (bool $value): bool => false]; + yield [false, [false, true, true], static fn(bool $value): bool => $value]; + yield [false, [false, true, true], static fn(bool $value): bool => !$value]; + yield [true, [true, true, true], static fn(bool $value): bool => $value]; + yield [false, [true, true, true], static fn(bool $value): bool => !$value]; + yield [false, [false, false, false], static fn(bool $value): bool => $value]; + yield [true, [false, false, false], static fn(bool $value): bool => !$value]; + yield [true, [false, false, false], static fn(bool $_value): bool => true]; + yield [false, [false, false, false], static fn(bool $_value): bool => false]; + yield [false, [1, 2, 3], static fn(int $i): bool => $i > 3]; + yield [true, [4, 5, 6], static fn(int $i): bool => $i > 3]; + yield [false, [1, 2, 3, 4, 5, 6], static fn(int $i): bool => $i > 3]; + yield [true, [], static fn(bool $_value): bool => false]; } } diff --git a/tests/unit/Iter/AnyTest.php b/tests/unit/Iter/AnyTest.php index 22cfebfd..2546852d 100644 --- a/tests/unit/Iter/AnyTest.php +++ b/tests/unit/Iter/AnyTest.php @@ -19,17 +19,17 @@ public function testAny(bool $expected, iterable $iterable, callable $predicate) public function provideData(): iterable { - yield [true, [false, true, true], static fn (bool $value): bool => $value]; - yield [true, [false, true, true], static fn (bool $value): bool => !$value]; - yield [true, [true, true, true], static fn (bool $value): bool => $value]; - yield [false, [true, true, true], static fn (bool $value): bool => !$value]; - yield [false, [false, false, false], static fn (bool $value): bool => $value]; - yield [true, [false, false, false], static fn (bool $value): bool => !$value]; - yield [true, [false, false, false], static fn (bool $value): bool => true]; - yield [false, [false, false, false], static fn (bool $value): bool => false]; - yield [false, [1, 2, 3], static fn (int $i): bool => $i > 3]; - yield [true, [4, 5, 6], static fn (int $i): bool => $i > 3]; - yield [true, [1, 2, 3, 4, 5, 6], static fn (int $i): bool => $i > 3]; - yield [false, [], static fn (bool $value): bool => false]; + yield [true, [false, true, true], static fn(bool $value): bool => $value]; + yield [true, [false, true, true], static fn(bool $value): bool => !$value]; + yield [true, [true, true, true], static fn(bool $value): bool => $value]; + yield [false, [true, true, true], static fn(bool $value): bool => !$value]; + yield [false, [false, false, false], static fn(bool $value): bool => $value]; + yield [true, [false, false, false], static fn(bool $value): bool => !$value]; + yield [true, [false, false, false], static fn(bool $_value): bool => true]; + yield [false, [false, false, false], static fn(bool $_value): bool => false]; + yield [false, [1, 2, 3], static fn(int $i): bool => $i > 3]; + yield [true, [4, 5, 6], static fn(int $i): bool => $i > 3]; + yield [true, [1, 2, 3, 4, 5, 6], static fn(int $i): bool => $i > 3]; + yield [false, [], static fn(bool $_value): bool => false]; } } diff --git a/tests/unit/Iter/ApplyTest.php b/tests/unit/Iter/ApplyTest.php index 04177b96..c07b3f75 100644 --- a/tests/unit/Iter/ApplyTest.php +++ b/tests/unit/Iter/ApplyTest.php @@ -13,7 +13,7 @@ final class ApplyTest extends TestCase public function testApply(): void { $vec = new MutableVector([]); - Iter\apply([1, 2, 3], static fn (int $i) => $vec->add($i)); + Iter\apply([1, 2, 3], static fn(int $i) => $vec->add($i)); static::assertSame([1, 2, 3], $vec->toArray()); } diff --git a/tests/unit/Iter/ContainsKeyTest.php b/tests/unit/Iter/ContainsKeyTest.php index 733dc0d5..f214cd91 100644 --- a/tests/unit/Iter/ContainsKeyTest.php +++ b/tests/unit/Iter/ContainsKeyTest.php @@ -38,7 +38,7 @@ public function provideData(): iterable yield [true, new Collection\Vector([1, 2]), 0]; yield [true, new Collection\Vector([1, 2]), 1]; yield [false, new Collection\Vector([1, 2]), 2]; - yield [true, (static fn () => yield 'foo' => 'bar')(), 'foo']; - yield [false, (static fn () => yield 'foo' => 'bar')(), 'bar']; + yield [true, (static fn() => yield 'foo' => 'bar')(), 'foo']; + yield [false, (static fn() => yield 'foo' => 'bar')(), 'bar']; } } diff --git a/tests/unit/Iter/ContainsTest.php b/tests/unit/Iter/ContainsTest.php index cbb1bc93..eee7769b 100644 --- a/tests/unit/Iter/ContainsTest.php +++ b/tests/unit/Iter/ContainsTest.php @@ -40,7 +40,7 @@ public function provideData(): iterable yield [false, new Collection\Vector([1, 2]), 0]; yield [true, new Collection\Vector([1, 2]), 1]; yield [true, new Collection\Vector([1, 2]), 2]; - yield [false, (static fn () => yield 'foo' => 'bar')(), 'foo']; - yield [true, (static fn () => yield 'foo' => 'bar')(), 'bar']; + yield [false, (static fn() => yield 'foo' => 'bar')(), 'foo']; + yield [true, (static fn() => yield 'foo' => 'bar')(), 'bar']; } } diff --git a/tests/unit/Iter/CountTest.php b/tests/unit/Iter/CountTest.php index 1e2f8976..c8a1823c 100644 --- a/tests/unit/Iter/CountTest.php +++ b/tests/unit/Iter/CountTest.php @@ -25,7 +25,7 @@ public function provideData(): iterable yield [1, [null]]; yield [3, [1, 2, 3]]; yield [10, Vec\range(1, 10)]; - yield [1, (static fn () => yield 1 => 2)()]; + yield [1, (static fn() => yield 1 => 2)()]; yield [21, Collection\Vector::fromArray(Vec\range(0, 100, 5))]; } } diff --git a/tests/unit/Iter/FirstKeyOptTest.php b/tests/unit/Iter/FirstKeyOptTest.php index dc476c51..e7aba60a 100644 --- a/tests/unit/Iter/FirstKeyOptTest.php +++ b/tests/unit/Iter/FirstKeyOptTest.php @@ -28,9 +28,12 @@ public function provideDataSome(): iterable yield [0, new Collection\Vector(['a', 'b'])]; yield [0, new Collection\Vector(['a' => 'b'])]; yield ['a', new Collection\Map(['a' => 'b'])]; - yield [null, (static function () { - yield null => null; - })()]; + yield [ + null, + (static function () { + yield null => null; + })(), + ]; } /** diff --git a/tests/unit/Iter/FirstKeyTest.php b/tests/unit/Iter/FirstKeyTest.php index ac749c6a..6736191c 100644 --- a/tests/unit/Iter/FirstKeyTest.php +++ b/tests/unit/Iter/FirstKeyTest.php @@ -30,12 +30,18 @@ public function provideData(): iterable yield [0, new Collection\Vector(['a', 'b'])]; yield [0, new Collection\Vector(['a' => 'b'])]; yield ['a', new Collection\Map(['a' => 'b'])]; - yield [null, (static function () { - yield null => null; - })()]; - yield [null, (static function () { - return; - yield; - })()]; + yield [ + null, + (static function () { + yield null => null; + })(), + ]; + yield [ + null, + (static function () { + return; + yield; + })(), + ]; } } diff --git a/tests/unit/Iter/FirstOptTest.php b/tests/unit/Iter/FirstOptTest.php index 7ced3bb0..4eb0ce90 100644 --- a/tests/unit/Iter/FirstOptTest.php +++ b/tests/unit/Iter/FirstOptTest.php @@ -28,9 +28,12 @@ public function provideDataSome(): iterable yield ['a', new Collection\Vector(['a', 'b'])]; yield ['b', new Collection\Vector(['b'])]; yield ['b', new Collection\Map(['a' => 'b', 'c' => 'd'])]; - yield [null, (static function () { - yield null => null; - })()]; + yield [ + null, + (static function () { + yield null => null; + })(), + ]; } /** diff --git a/tests/unit/Iter/FirstTest.php b/tests/unit/Iter/FirstTest.php index c30a354c..2816546d 100644 --- a/tests/unit/Iter/FirstTest.php +++ b/tests/unit/Iter/FirstTest.php @@ -30,12 +30,18 @@ public function provideData(): iterable yield ['a', new Collection\Vector(['a', 'b'])]; yield ['b', new Collection\Vector(['b'])]; yield ['b', new Collection\Map(['a' => 'b', 'c' => 'd'])]; - yield [null, (static function () { - yield null => null; - })()]; - yield [null, (static function () { - return; - yield; - })()]; + yield [ + null, + (static function () { + yield null => null; + })(), + ]; + yield [ + null, + (static function () { + return; + yield; + })(), + ]; } } diff --git a/tests/unit/Iter/IsEmptyTest.php b/tests/unit/Iter/IsEmptyTest.php index 88c12283..f26c7de1 100644 --- a/tests/unit/Iter/IsEmptyTest.php +++ b/tests/unit/Iter/IsEmptyTest.php @@ -21,7 +21,7 @@ public function provideData(): iterable { yield [true, []]; yield [true, Iter\to_iterator([])]; - yield [true, (static fn () => yield from [])()]; + yield [true, (static fn() => yield from [])()]; yield [false, [null]]; yield [false, [false]]; diff --git a/tests/unit/Iter/IteratorTest.php b/tests/unit/Iter/IteratorTest.php index 8ff24b7c..959fa7ac 100644 --- a/tests/unit/Iter/IteratorTest.php +++ b/tests/unit/Iter/IteratorTest.php @@ -13,21 +13,21 @@ final class IteratorTest extends TestCase { public function testCreateFromGenerator(): void { - $iterator = Iter\Iterator::create((static fn () => yield from [1, 2, 3])()); + $iterator = Iter\Iterator::create((static fn() => yield from [1, 2, 3])()); static::assertCount(3, $iterator); } public function testCreateFromFactory(): void { - $iterator = Iter\Iterator::from((static fn () => yield from [1, 2, 3])); + $iterator = Iter\Iterator::from(static fn() => yield from [1, 2, 3]); static::assertCount(3, $iterator); } public function testKeyIteration(): void { - $iterator = Iter\Iterator::from((static fn () => yield from [1, 2, 3])); + $iterator = Iter\Iterator::from(static fn() => yield from [1, 2, 3]); $keys = []; while ($iterator->valid()) { $keys[] = $iterator->key(); @@ -40,7 +40,7 @@ public function testKeyIteration(): void public function testSeek(): void { - $iterator = new Iter\Iterator((static fn () => yield from [1, 2, 3, 4, 5])()); + $iterator = new Iter\Iterator((static fn() => yield from [1, 2, 3, 4, 5])()); static::assertSame(1, $iterator->current()); $iterator->next(); @@ -66,7 +66,7 @@ public function testSeek(): void public function testSeekThrowsForOutOfBoundIndex(): void { - $iterator = new Iter\Iterator((static fn () => yield from [1, 2, 3, 4, 5])()); + $iterator = new Iter\Iterator((static fn() => yield from [1, 2, 3, 4, 5])()); $this->expectException(Iter\Exception\OutOfBoundsException::class); $this->expectExceptionMessage('Position is out-of-bounds.'); @@ -76,7 +76,7 @@ public function testSeekThrowsForOutOfBoundIndex(): void public function testSeekThrowsForPlusOneOutOfBoundIndexWhenCached(): void { - $iterator = new Iter\Iterator((static fn () => yield from [1, 2, 3, 4, 5])()); + $iterator = new Iter\Iterator((static fn() => yield from [1, 2, 3, 4, 5])()); static::assertSame(5, $iterator->count()); @@ -88,7 +88,7 @@ public function testSeekThrowsForPlusOneOutOfBoundIndexWhenCached(): void public function testSeekThrowsForPlusOneOutOfBoundIndex(): void { - $iterator = new Iter\Iterator((static fn () => yield from [1, 2, 3, 4, 5])()); + $iterator = new Iter\Iterator((static fn() => yield from [1, 2, 3, 4, 5])()); $this->expectException(Iter\Exception\OutOfBoundsException::class); $this->expectExceptionMessage('Position is out-of-bounds.'); @@ -151,23 +151,26 @@ public function testIterating(): void * - The iterator is capable of rewinding a generator. * - The generator is not exhausted immediately on construction. */ - static::assertSame([ - 'generator (0)', - 'foreach (0)', - 'generator (1)', - 'foreach (1)', - 'generator (2)', - 'foreach (2)', - 'foreach (0)', - 'foreach (1)', - 'foreach (2)', - 'foreach (0)', - 'foreach (1)', - 'foreach (2)', - 'while (0)', - 'while (1)', - 'while (2)', - ], $spy->toArray()); + static::assertSame( + [ + 'generator (0)', + 'foreach (0)', + 'generator (1)', + 'foreach (1)', + 'generator (2)', + 'foreach (2)', + 'foreach (0)', + 'foreach (1)', + 'foreach (2)', + 'foreach (0)', + 'foreach (1)', + 'foreach (2)', + 'while (0)', + 'while (1)', + 'while (2)', + ], + $spy->toArray(), + ); } public function testCountWhileIterating(): void @@ -190,17 +193,20 @@ public function testCountWhileIterating(): void static::assertSame(['foo', 'bar'], $key); } - static::assertSame([ - 'sending (0)', - 'sending (1)', - 'sending (2)', - 'count (3)', - 'received (0)', - 'count (3)', - 'received (1)', - 'count (3)', - 'received (2)', - ], $spy->toArray()); + static::assertSame( + [ + 'sending (0)', + 'sending (1)', + 'sending (2)', + 'count (3)', + 'received (0)', + 'count (3)', + 'received (1)', + 'count (3)', + 'received (2)', + ], + $spy->toArray(), + ); } public function testRewindingValidGenerator(): void @@ -235,16 +241,19 @@ public function testRewindingValidGenerator(): void $spy->add('for (' . $rewindable->current() . ')'); } - static::assertSame([ - 'generator (0)', - 'foreach (0)', - 'do while (0)', - 'while (0)', - 'for (0)', - 'generator (1)', - 'for (1)', - 'generator (2)', - 'for (2)', - ], $spy->toArray()); + static::assertSame( + [ + 'generator (0)', + 'foreach (0)', + 'do while (0)', + 'while (0)', + 'for (0)', + 'generator (1)', + 'for (1)', + 'generator (2)', + 'for (2)', + ], + $spy->toArray(), + ); } } diff --git a/tests/unit/Iter/LastKeyOptTest.php b/tests/unit/Iter/LastKeyOptTest.php index 7542f7b9..af847a0c 100644 --- a/tests/unit/Iter/LastKeyOptTest.php +++ b/tests/unit/Iter/LastKeyOptTest.php @@ -29,7 +29,7 @@ public function provideDataSome(): iterable yield [4, Iter\to_iterator(Vec\range(4, 8))]; yield [0, [null]]; yield [1, [null, null]]; - yield [[1, 2], (static fn () => yield [1, 2] => 'hello')()]; + yield [[1, 2], (static fn() => yield [1, 2] => 'hello')()]; } /** diff --git a/tests/unit/Iter/LastKeyTest.php b/tests/unit/Iter/LastKeyTest.php index c8910417..64794680 100644 --- a/tests/unit/Iter/LastKeyTest.php +++ b/tests/unit/Iter/LastKeyTest.php @@ -30,6 +30,6 @@ public function provideData(): iterable yield [null, []]; yield [0, [null]]; yield [1, [null, null]]; - yield [[1, 2], (static fn () => yield [1, 2] => 'hello')()]; + yield [[1, 2], (static fn() => yield [1, 2] => 'hello')()]; } } diff --git a/tests/unit/Iter/LastOptTest.php b/tests/unit/Iter/LastOptTest.php index fcadeaa8..4d64e334 100644 --- a/tests/unit/Iter/LastOptTest.php +++ b/tests/unit/Iter/LastOptTest.php @@ -28,9 +28,12 @@ public function provideDataSome(): iterable yield ['b', new Collection\Vector(['a', 'b'])]; yield ['b', new Collection\Vector(['b'])]; yield ['d', new Collection\Map(['a' => 'b', 'c' => 'd'])]; - yield [null, (static function () { - yield null => null; - })()]; + yield [ + null, + (static function () { + yield null => null; + })(), + ]; } /** @@ -45,9 +48,9 @@ public function testLastNone(iterable $iterable): void public function provideDataNone(): iterable { - yield [ []]; - yield [ new SplDoublyLinkedList()]; - yield [ (static function () { + yield [[]]; + yield [new SplDoublyLinkedList()]; + yield [(static function () { return; yield; })()]; diff --git a/tests/unit/Iter/LastTest.php b/tests/unit/Iter/LastTest.php index eb84730a..955b3356 100644 --- a/tests/unit/Iter/LastTest.php +++ b/tests/unit/Iter/LastTest.php @@ -30,12 +30,18 @@ public function provideData(): iterable yield ['b', new Collection\Vector(['a', 'b'])]; yield ['b', new Collection\Vector(['b'])]; yield ['d', new Collection\Map(['a' => 'b', 'c' => 'd'])]; - yield [null, (static function () { - yield null => null; - })()]; - yield [null, (static function () { - return; - yield; - })()]; + yield [ + null, + (static function () { + yield null => null; + })(), + ]; + yield [ + null, + (static function () { + return; + yield; + })(), + ]; } } diff --git a/tests/unit/Iter/RandomTest.php b/tests/unit/Iter/RandomTest.php index 74bb475b..4c941e25 100644 --- a/tests/unit/Iter/RandomTest.php +++ b/tests/unit/Iter/RandomTest.php @@ -12,16 +12,16 @@ final class RandomTest extends TestCase public function testRandom(): void { $iterable = [1, 2, 3, 4, 5]; - $value = Iter\random($iterable); + $value = Iter\random($iterable); static::assertTrue(Iter\contains($iterable, $value)); $iterable = Iter\to_iterator([1, 2, 3, 4, 5]); - $value = Iter\random($iterable); + $value = Iter\random($iterable); static::assertTrue(Iter\contains($iterable, $value)); - $value = Iter\random([1]); + $value = Iter\random([1]); static::assertSame(1, $value); } diff --git a/tests/unit/Iter/ReduceKeysTest.php b/tests/unit/Iter/ReduceKeysTest.php index 75514dc4..b220da88 100644 --- a/tests/unit/Iter/ReduceKeysTest.php +++ b/tests/unit/Iter/ReduceKeysTest.php @@ -19,8 +19,8 @@ public function testReduceKeys($expected, iterable $iterable, callable $function public function provideData(): iterable { - yield [null, [], static fn ($accumulator, $k) => $accumulator, null]; - yield [3, [1, 2, 3], static fn ($accumulator, $k) => $accumulator + $k, 0]; - yield [3, Iter\to_iterator([1, 2, 3]), static fn ($accumulator, $k) => $accumulator + $k, 0]; + yield [null, [], static fn($accumulator, $_k) => $accumulator, null]; + yield [3, [1, 2, 3], static fn($accumulator, $k) => $accumulator + $k, 0]; + yield [3, Iter\to_iterator([1, 2, 3]), static fn($accumulator, $k) => $accumulator + $k, 0]; } } diff --git a/tests/unit/Iter/ReduceTest.php b/tests/unit/Iter/ReduceTest.php index a6901c31..2b318681 100644 --- a/tests/unit/Iter/ReduceTest.php +++ b/tests/unit/Iter/ReduceTest.php @@ -19,8 +19,8 @@ public function testReduce($expected, iterable $iterable, callable $function, $i public function provideData(): iterable { - yield [null, [], static fn ($accumulator, $v) => $accumulator, null]; - yield [6, [1, 2, 3], static fn ($accumulator, $v) => $accumulator + $v, 0]; - yield [6, Iter\to_iterator([1, 2, 3]), static fn ($accumulator, $v) => $accumulator + $v, 0]; + yield [null, [], static fn($accumulator, $_v) => $accumulator, null]; + yield [6, [1, 2, 3], static fn($accumulator, $v) => $accumulator + $v, 0]; + yield [6, Iter\to_iterator([1, 2, 3]), static fn($accumulator, $v) => $accumulator + $v, 0]; } } diff --git a/tests/unit/Iter/ReduceWithKeysTest.php b/tests/unit/Iter/ReduceWithKeysTest.php index 183e392b..0a883cb3 100644 --- a/tests/unit/Iter/ReduceWithKeysTest.php +++ b/tests/unit/Iter/ReduceWithKeysTest.php @@ -19,8 +19,8 @@ public function testReduceWithKeys($expected, iterable $iterable, callable $func public function provideData(): iterable { - yield [null, [], static fn ($accumulator, $k, $v) => $accumulator, null]; - yield [6, [1, 2, 3], static fn ($accumulator, $k, $v) => $accumulator + $v, 0]; - yield [6, Iter\to_iterator([1, 2, 3]), static fn ($accumulator, $k, $v) => $accumulator + $v, 0]; + yield [null, [], static fn($accumulator, $_k, $_v) => $accumulator, null]; + yield [6, [1, 2, 3], static fn($accumulator, $_k, $v) => $accumulator + $v, 0]; + yield [6, Iter\to_iterator([1, 2, 3]), static fn($accumulator, $_k, $v) => $accumulator + $v, 0]; } } diff --git a/tests/unit/Iter/SearchOptTest.php b/tests/unit/Iter/SearchOptTest.php index 58c824e6..60f11c16 100644 --- a/tests/unit/Iter/SearchOptTest.php +++ b/tests/unit/Iter/SearchOptTest.php @@ -19,9 +19,9 @@ public function testSearchSome($expected, iterable $iterable, callable $predicat public function provideDataSome(): iterable { - yield ['baz', ['foo', 'bar', 'baz'], static fn (string $v): bool => 'baz' === $v]; + yield ['baz', ['foo', 'bar', 'baz'], static fn(string $v): bool => 'baz' === $v]; - yield ['baz', Iter\to_iterator(['foo', 'bar', 'baz']), static fn (string $v): bool => 'baz' === $v]; + yield ['baz', Iter\to_iterator(['foo', 'bar', 'baz']), static fn(string $v): bool => 'baz' === $v]; } /** * @dataProvider provideDataNone @@ -32,8 +32,8 @@ public function testSearchNone(iterable $iterable, callable $predicate): void } public function provideDataNone(): iterable { - yield [[], static fn (string $v): bool => 'qux' === $v]; - yield [Iter\to_iterator([]), static fn (string $v): bool => 'qux' === $v]; - yield [Iter\to_iterator(['foo', 'bar', 'baz']), static fn (string $v): bool => 'qux' === $v]; + yield [[], static fn(string $v): bool => 'qux' === $v]; + yield [Iter\to_iterator([]), static fn(string $v): bool => 'qux' === $v]; + yield [Iter\to_iterator(['foo', 'bar', 'baz']), static fn(string $v): bool => 'qux' === $v]; } } diff --git a/tests/unit/Iter/SearchTest.php b/tests/unit/Iter/SearchTest.php index 57c3f1f7..8857ebce 100644 --- a/tests/unit/Iter/SearchTest.php +++ b/tests/unit/Iter/SearchTest.php @@ -19,12 +19,12 @@ public function testSearch($expected, iterable $iterable, callable $predicate): public function provideData(): iterable { - yield ['baz', ['foo', 'bar', 'baz'], static fn (string $v): bool => 'baz' === $v]; - yield [null, ['foo', 'bar', 'baz'], static fn (string $v): bool => 'qux' === $v]; - yield [null, [], static fn (string $v): bool => 'qux' === $v]; + yield ['baz', ['foo', 'bar', 'baz'], static fn(string $v): bool => 'baz' === $v]; + yield [null, ['foo', 'bar', 'baz'], static fn(string $v): bool => 'qux' === $v]; + yield [null, [], static fn(string $v): bool => 'qux' === $v]; - yield ['baz', Iter\to_iterator(['foo', 'bar', 'baz']), static fn (string $v): bool => 'baz' === $v]; - yield [null, Iter\to_iterator(['foo', 'bar', 'baz']), static fn (string $v): bool => 'qux' === $v]; - yield [null, Iter\to_iterator([]), static fn (string $v): bool => 'qux' === $v]; + yield ['baz', Iter\to_iterator(['foo', 'bar', 'baz']), static fn(string $v): bool => 'baz' === $v]; + yield [null, Iter\to_iterator(['foo', 'bar', 'baz']), static fn(string $v): bool => 'qux' === $v]; + yield [null, Iter\to_iterator([]), static fn(string $v): bool => 'qux' === $v]; } } diff --git a/tests/unit/Json/DecodeTest.php b/tests/unit/Json/DecodeTest.php index 9d2a3db2..8a882478 100644 --- a/tests/unit/Json/DecodeTest.php +++ b/tests/unit/Json/DecodeTest.php @@ -11,21 +11,26 @@ final class DecodeTest extends TestCase { public function testDecode(): void { - $actual = Json\decode('{ + $actual = Json\decode( + '{ "name": "azjezz/psl", "type": "library", "description": "PHP Standard Library.", "keywords": ["php", "std", "stdlib", "utility", "psl"], "license": "MIT" - }'); - - static::assertSame([ - 'name' => 'azjezz/psl', - 'type' => 'library', - 'description' => 'PHP Standard Library.', - 'keywords' => ['php', 'std', 'stdlib', 'utility', 'psl'], - 'license' => 'MIT' - ], $actual); + }', + ); + + static::assertSame( + [ + 'name' => 'azjezz/psl', + 'type' => 'library', + 'description' => 'PHP Standard Library.', + 'keywords' => ['php', 'std', 'stdlib', 'utility', 'psl'], + 'license' => 'MIT', + ], + $actual, + ); } public function testDecodeThrowsForInvalidSyntax(): void diff --git a/tests/unit/Json/EncodeTest.php b/tests/unit/Json/EncodeTest.php index 4e4aa093..0d023b4b 100644 --- a/tests/unit/Json/EncodeTest.php +++ b/tests/unit/Json/EncodeTest.php @@ -22,29 +22,32 @@ public function testEncode(): void public function testPrettyEncode(): void { - $actual = Json\encode([ - 'name' => 'azjezz/psl', - 'type' => 'library', - 'description' => 'PHP Standard Library.', - 'keywords' => ['php', 'std', 'stdlib', 'utility', 'psl'], - 'license' => 'MIT' - ], true); + $actual = Json\encode( + [ + 'name' => 'azjezz/psl', + 'type' => 'library', + 'description' => 'PHP Standard Library.', + 'keywords' => ['php', 'std', 'stdlib', 'utility', 'psl'], + 'license' => 'MIT', + ], + true, + ); $json = Str\replace(<<toArray()); @@ -47,15 +47,20 @@ public function testTypedVector(): void public function testTypedThrowsWhenUnableToCoerce(): void { $this->expectException(Json\Exception\DecodeException::class); - $this->expectExceptionMessage('Could not coerce "string" to type "' . MapInterface::class . '" at path "name".'); + $this->expectExceptionMessage( + 'Could not coerce "string" to type "' . MapInterface::class . '" at path "name".', + ); - Json\typed('{ + Json\typed( + '{ "name": "azjezz/psl", "type": "library", "description": "PHP Standard Library.", "keywords": ["php", "std", "stdlib", "utility", "psl"], "license": "MIT" - }', Type\map(Type\string(), Type\int())); + }', + Type\map(Type\string(), Type\int()), + ); } public function testsTypedAsserts(): void diff --git a/tests/unit/Locale/LocaleTest.php b/tests/unit/Locale/LocaleTest.php index d61c09e0..15a673bf 100644 --- a/tests/unit/Locale/LocaleTest.php +++ b/tests/unit/Locale/LocaleTest.php @@ -14,7 +14,7 @@ final class LocaleTest extends TestCase { - private ?string $defaultLocale = null; + private null|string $defaultLocale = null; protected function setUp(): void { $this->defaultLocale = locale_get_default(); diff --git a/tests/unit/Math/AbsTest.php b/tests/unit/Math/AbsTest.php index c9eed44f..26931105 100644 --- a/tests/unit/Math/AbsTest.php +++ b/tests/unit/Math/AbsTest.php @@ -19,26 +19,23 @@ public function testAbs($expected, $number): void public function provideData(): array { - return [ + return [ [ 5, - 5 + 5, ], - [ 5, - -5 + -5, ], - [ 5.5, - -5.5 + -5.5, ], - [ 10.5, - 10.5 - ] + 10.5, + ], ]; } } diff --git a/tests/unit/Math/AcosTest.php b/tests/unit/Math/AcosTest.php index ef194530..d4448cd2 100644 --- a/tests/unit/Math/AcosTest.php +++ b/tests/unit/Math/AcosTest.php @@ -33,7 +33,7 @@ public function provideData(): array [ 1.0471975511965979, 0.5, - ] + ], ]; } } diff --git a/tests/unit/Math/AsinTest.php b/tests/unit/Math/AsinTest.php index 18f830cf..cdfdb312 100644 --- a/tests/unit/Math/AsinTest.php +++ b/tests/unit/Math/AsinTest.php @@ -24,22 +24,19 @@ public function provideData(): array return [ [ 0.5235987755982989, - 0.5 + 0.5, ], - [ 0.9272952180016123, - 0.8 + 0.8, ], - [ 0.0, - 0.0 + 0.0, ], - [ 0.41151684606748806, - 0.4 + 0.4, ], ]; } diff --git a/tests/unit/Math/Atan2Test.php b/tests/unit/Math/Atan2Test.php index 736b8541..025089b2 100644 --- a/tests/unit/Math/Atan2Test.php +++ b/tests/unit/Math/Atan2Test.php @@ -27,30 +27,26 @@ public function provideData(): array 1.0, 1.0, ], - [ 0.8960553845713439, 1.0, - 0.8 + 0.8, ], - [ 0.0, 0.0, - 0.0 + 0.0, ], - [ 0.7853981633974483, 0.4, 0.4, ], - [ -2.260001062633476, -0.5, -0.412, - ] + ], ]; } } diff --git a/tests/unit/Math/AtanTest.php b/tests/unit/Math/AtanTest.php index 4d1bdaa5..815f14c8 100644 --- a/tests/unit/Math/AtanTest.php +++ b/tests/unit/Math/AtanTest.php @@ -24,28 +24,24 @@ public function provideData(): array return [ [ 0.7853981633974483, - 1.0 + 1.0, ], - [ 0.6747409422235527, - 0.8 + 0.8, ], - [ 0.0, - 0.0 + 0.0, ], - [ 0.3805063771123649, - 0.4 + 0.4, ], - [ -0.4636476090008061, - -0.5 - ] + -0.5, + ], ]; } } diff --git a/tests/unit/Math/BaseConvertTest.php b/tests/unit/Math/BaseConvertTest.php index c808b5cf..81ed2057 100644 --- a/tests/unit/Math/BaseConvertTest.php +++ b/tests/unit/Math/BaseConvertTest.php @@ -24,57 +24,50 @@ public function provideData(): array '2', '10', 2, - 16 + 16, ], - [ '2', '10', 2, - 10 + 10, ], - [ 'f', '15', 10, - 16 + 16, ], - [ '10', '2', 16, - 2 + 2, ], - [ '1010101111001', '5497', 10, - 2 + 2, ], - [ '48p', '1010101111001', 2, - 36 + 36, ], - [ 'pphlmw9v', '2014587925987', 10, - 36 + 36, ], - [ 'zik0zj', (string) Math\INT32_MAX, 10, - 36 - ] + 36, + ], ]; } } diff --git a/tests/unit/Math/CeilTest.php b/tests/unit/Math/CeilTest.php index 53a077ae..d5998979 100644 --- a/tests/unit/Math/CeilTest.php +++ b/tests/unit/Math/CeilTest.php @@ -22,28 +22,24 @@ public function provideData(): array return [ [ 5.0, - 5.0 + 5.0, ], - [ 5.0, - 4.8 + 4.8, ], - [ 0.0, - 0.0 + 0.0, ], - [ 1.0, - 0.4 + 0.4, ], - [ -6.0, - -6.5 - ] + -6.5, + ], ]; } } diff --git a/tests/unit/Math/ClampTest.php b/tests/unit/Math/ClampTest.php index d723aac9..ef51a0da 100644 --- a/tests/unit/Math/ClampTest.php +++ b/tests/unit/Math/ClampTest.php @@ -32,43 +32,43 @@ public function provideData(): array 'expected' => 10, 'number' => 10, 'min' => 2, - 'max' => 20 + 'max' => 20, ], [ 'expected' => 10, 'number' => 20, 'min' => 1, - 'max' => 10 + 'max' => 10, ], [ 'expected' => 10, 'number' => 5, 'min' => 10, - 'max' => 20 + 'max' => 20, ], [ 'expected' => 10, 'number' => 10, 'min' => 10, - 'max' => 20 + 'max' => 20, ], [ 'expected' => 10, 'number' => 10, 'min' => 1, - 'max' => 10 + 'max' => 10, ], [ 'expected' => 10, 'number' => 20, 'min' => 10, - 'max' => 10 + 'max' => 10, ], [ 'expected' => 10.0, 'number' => 10.0, 'min' => 2.0, - 'max' => 20.0 + 'max' => 20.0, ], ]; } diff --git a/tests/unit/Math/CosTest.php b/tests/unit/Math/CosTest.php index 5a37e952..c89d1c81 100644 --- a/tests/unit/Math/CosTest.php +++ b/tests/unit/Math/CosTest.php @@ -24,28 +24,24 @@ public function provideData(): array return [ [ 0.5403023058681398, - 1.0 + 1.0, ], - [ 1.0, - 0.0 + 0.0, ], - [ 0.10291095660695612, 45.45, ], - [ 0.28366218546322625, - -5 + -5, ], - [ -0.9983206000589924, - -15.65 - ] + -15.65, + ], ]; } } diff --git a/tests/unit/Math/DivTest.php b/tests/unit/Math/DivTest.php index 76eae3aa..9b12f299 100644 --- a/tests/unit/Math/DivTest.php +++ b/tests/unit/Math/DivTest.php @@ -35,30 +35,27 @@ public function testDivInt64MinByMinusOne(): void public function provideData(): array { - return[ + return [ [ 2, 5, 2, ], - [ 5, 10, - 2 + 2, ], - [ 0, 15, - 20 + 20, ], - [ 1, 10, - 10 - ] + 10, + ], ]; } } diff --git a/tests/unit/Math/ExpTest.php b/tests/unit/Math/ExpTest.php index 1b961b92..3e2e38d4 100644 --- a/tests/unit/Math/ExpTest.php +++ b/tests/unit/Math/ExpTest.php @@ -24,16 +24,14 @@ public function provideData(): array 162754.79141900392, 12.0, ], - [ 298.8674009670603, 5.7, ], - [ Math\INFINITY, 1000000, - ] + ], ]; } } diff --git a/tests/unit/Math/FloatAsserts.php b/tests/unit/Math/FloatAsserts.php index 99634946..d87ac049 100644 --- a/tests/unit/Math/FloatAsserts.php +++ b/tests/unit/Math/FloatAsserts.php @@ -19,7 +19,7 @@ public static function assertFloatEquals(float $a, float $b, float $epsilon = PH { TestCase::assertTrue( Math\abs($a - $b) <= $epsilon, - 'Failed asserting that float ' . $a . ' is equal to ' . $b . '.' + 'Failed asserting that float ' . $a . ' is equal to ' . $b . '.', ); } } diff --git a/tests/unit/Math/FloorTest.php b/tests/unit/Math/FloorTest.php index 1013c257..88901471 100644 --- a/tests/unit/Math/FloorTest.php +++ b/tests/unit/Math/FloorTest.php @@ -24,26 +24,22 @@ public function provideData(): array 4, 4.3, ], - [ 9, 9.9, ], - [ 3, - Math\PI + Math\PI, ], - [ -4, - -Math\PI + -Math\PI, ], - [ 2, - Math\E - ] + Math\E, + ], ]; } } diff --git a/tests/unit/Math/FromBaseTest.php b/tests/unit/Math/FromBaseTest.php index 2bd29664..28edde25 100644 --- a/tests/unit/Math/FromBaseTest.php +++ b/tests/unit/Math/FromBaseTest.php @@ -24,26 +24,23 @@ public function provideData(): array [ 5497, '1010101111001', - 2 + 2, ], - [ 2014587925987, 'pphlmw9v', - 36 + 36, ], - [ Math\INT32_MAX, 'zik0zj', - 36 + 36, ], - [ 15, 'F', - 16 - ] + 16, + ], ]; } diff --git a/tests/unit/Math/LogTest.php b/tests/unit/Math/LogTest.php index 5b824f58..948cef37 100644 --- a/tests/unit/Math/LogTest.php +++ b/tests/unit/Math/LogTest.php @@ -12,7 +12,7 @@ final class LogTest extends TestCase /** * @dataProvider provideData */ - public function testLog(float $expected, float $number, ?float $base = null): void + public function testLog(float $expected, float $number, null|float $base = null): void { static::assertSame($expected, Math\log($number, $base)); } @@ -23,25 +23,22 @@ public function provideData(): array [ 1.6863989535702288, 5.4, - null + null, ], - [ 0.6574784600188808, 5.4, - 13 + 13, ], - [ 1.7323937598229686, 54.0, - 10 + 10, ], - [ 0, 1, - null + null, ], ]; } diff --git a/tests/unit/Math/MaxByTest.php b/tests/unit/Math/MaxByTest.php index 0b93a1bc..18b445e2 100644 --- a/tests/unit/Math/MaxByTest.php +++ b/tests/unit/Math/MaxByTest.php @@ -25,7 +25,7 @@ public function provideData(): Generator yield [ 'bazqux', ['foo', 'bar', 'baz', 'qux', 'foobar', 'bazqux'], - static fn ($value) => Str\length($value), + static fn($value) => Str\length($value), ]; yield [ @@ -33,21 +33,21 @@ public function provideData(): Generator [ ['foo'], ['foo', 'bar'], - ['foo', 'bar', 'baz'] + ['foo', 'bar', 'baz'], ], - static fn ($arr) => Iter\count($arr), + static fn($arr) => Iter\count($arr), ]; yield [ 9, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], - static fn ($i) => $i, + static fn($i) => $i, ]; yield [ null, [], - static fn ($i) => $i, + static fn($i) => $i, ]; } } diff --git a/tests/unit/Math/MaxTest.php b/tests/unit/Math/MaxTest.php index 200ce75f..80675307 100644 --- a/tests/unit/Math/MaxTest.php +++ b/tests/unit/Math/MaxTest.php @@ -24,16 +24,14 @@ public function provideData(): array 10, [0, 2, 4, 6, 8, 10], ], - [ 15, [0, 2, 4, 6, 8, 10, 15], ], - [ null, - [] - ] + [], + ], ]; } } diff --git a/tests/unit/Math/MaxvaTest.php b/tests/unit/Math/MaxvaTest.php index 98ebe18b..eb3e6192 100644 --- a/tests/unit/Math/MaxvaTest.php +++ b/tests/unit/Math/MaxvaTest.php @@ -25,25 +25,23 @@ public function provideData(): array 10, 10, 5, - ...Vec\range(0, 9, 2) + ...Vec\range(0, 9, 2), ], - [ 18, 18, 15, ...Vec\range(0, 10), - 15 + 15, ], - [ 64, 19, 15, ...Vec\range(0, 45, 5), 52, - 64 - ] + 64, + ], ]; } } diff --git a/tests/unit/Math/MeanTest.php b/tests/unit/Math/MeanTest.php index fcc51b8e..0069dc0b 100644 --- a/tests/unit/Math/MeanTest.php +++ b/tests/unit/Math/MeanTest.php @@ -33,7 +33,6 @@ public function provideData(): array 8, ], ], - [ 7.357142857142858, [ @@ -53,7 +52,6 @@ public function provideData(): array 15, ], ], - [ 26.785714285714285, [ @@ -73,16 +71,14 @@ public function provideData(): array 64, ], ], - [ 100.0, - Vec\fill(100, 100) + Vec\fill(100, 100), ], - [ null, - [] - ] + [], + ], ]; } } diff --git a/tests/unit/Math/MedianTest.php b/tests/unit/Math/MedianTest.php index 94f3d3e2..14c584fe 100644 --- a/tests/unit/Math/MedianTest.php +++ b/tests/unit/Math/MedianTest.php @@ -29,7 +29,6 @@ public function provideData(): array ...Vec\range(0, 9, 2), ], ], - [ 6.5, [ @@ -39,7 +38,6 @@ public function provideData(): array 15, ], ], - [ 22.5, [ @@ -50,16 +48,14 @@ public function provideData(): array 64, ], ], - [ 100.0, - Vec\fill(100, 100) + Vec\fill(100, 100), ], - [ null, - [] - ] + [], + ], ]; } } diff --git a/tests/unit/Math/MinByTest.php b/tests/unit/Math/MinByTest.php index d107a221..09d1b50b 100644 --- a/tests/unit/Math/MinByTest.php +++ b/tests/unit/Math/MinByTest.php @@ -26,7 +26,7 @@ public function provideData(): Generator yield [ 'qux', ['foo', 'bar', 'baz', 'qux', 'foobar', 'bazqux'], - static fn ($value) => Str\length($value), + static fn($value) => Str\length($value), ]; yield [ @@ -34,21 +34,21 @@ public function provideData(): Generator [ ['foo'], ['foo', 'bar'], - ['foo', 'bar', 'baz'] + ['foo', 'bar', 'baz'], ], - static fn ($arr) => Iter\count($arr), + static fn($arr) => Iter\count($arr), ]; yield [ 0, [...Vec\range(0, 9)], - static fn ($i) => $i, + static fn($i) => $i, ]; yield [ null, [], - static fn ($i) => $i, + static fn($i) => $i, ]; } } diff --git a/tests/unit/Math/MinTest.php b/tests/unit/Math/MinTest.php index d79ed2b2..633be603 100644 --- a/tests/unit/Math/MinTest.php +++ b/tests/unit/Math/MinTest.php @@ -23,18 +23,16 @@ public function provideData(): array return [ [ 0, - [...Vec\range(0, 10, 2)] + [...Vec\range(0, 10, 2)], ], - [ 4, - [...Vec\range(5, 10), 4] + [...Vec\range(5, 10), 4], ], - [ null, - [] - ] + [], + ], ]; } } diff --git a/tests/unit/Math/MinvaTest.php b/tests/unit/Math/MinvaTest.php index d0253aed..c99cc0e0 100644 --- a/tests/unit/Math/MinvaTest.php +++ b/tests/unit/Math/MinvaTest.php @@ -25,25 +25,23 @@ public function provideData(): array 5, 10, 5, - ...Vec\range(7, 9, 2) + ...Vec\range(7, 9, 2), ], - [ 4, 18, 15, ...Vec\range(4, 10), - 15 + 15, ], - [ 15, 19, 15, ...Vec\range(40, 45, 5), 52, - 64 - ] + 64, + ], ]; } } diff --git a/tests/unit/Math/RoundTest.php b/tests/unit/Math/RoundTest.php index 5ea36a45..3bbd0eb1 100644 --- a/tests/unit/Math/RoundTest.php +++ b/tests/unit/Math/RoundTest.php @@ -25,37 +25,31 @@ public function provideData(): array 5.45663, 2, ], - [ 4.8, 4.811, 1, ], - [ 5.0, 5.42, - 0 + 0, ], - [ 5.0, 4.8, - 0 + 0, ], - [ 0.0, 0.4242, 0, ], - [ 0.5, 0.4634, 1, ], - [ -6.57778, -6.5777777777, diff --git a/tests/unit/Math/SinTest.php b/tests/unit/Math/SinTest.php index ebc514ea..d2c560f9 100644 --- a/tests/unit/Math/SinTest.php +++ b/tests/unit/Math/SinTest.php @@ -24,28 +24,24 @@ public function provideData(): array return [ [ -0.9589242746631385, - 5.0 + 5.0, ], - [ -0.9961646088358407, - 4.8 + 4.8, ], - [ 0.0, - 0.0 + 0.0, ], - [ 0.3894183423086505, - 0.4 + 0.4, ], - [ -0.21511998808781552, - -6.5 - ] + -6.5, + ], ]; } } diff --git a/tests/unit/Math/SqrtTest.php b/tests/unit/Math/SqrtTest.php index 236b1f3e..7222fb50 100644 --- a/tests/unit/Math/SqrtTest.php +++ b/tests/unit/Math/SqrtTest.php @@ -22,33 +22,28 @@ public function provideData(): array return [ [ 2.23606797749979, - 5.0 + 5.0, ], - [ 2.1908902300206643, - 4.8 + 4.8, ], - [ 0.6324555320336759, - 0.4 + 0.4, ], - [ 2.5495097567963922, - 6.5 + 6.5, ], - [ 1.4142135623730951, - 2 + 2, ], - [ 1, - 1 - ] + 1, + ], ]; } } diff --git a/tests/unit/Math/SumFloatsTest.php b/tests/unit/Math/SumFloatsTest.php index af90aee7..00cef901 100644 --- a/tests/unit/Math/SumFloatsTest.php +++ b/tests/unit/Math/SumFloatsTest.php @@ -29,7 +29,6 @@ public function provideData(): array ...Vec\range(0, 9.8798, 0.48), ], ], - [ 103.0, [ @@ -39,7 +38,6 @@ public function provideData(): array 15, ], ], - [ 323.54, [ @@ -48,7 +46,7 @@ public function provideData(): array ...Vec\range(0.5, 45, 5.98), 52.8, 64, - ] + ], ], ]; } diff --git a/tests/unit/Math/SumTest.php b/tests/unit/Math/SumTest.php index 9062769d..a3031292 100644 --- a/tests/unit/Math/SumTest.php +++ b/tests/unit/Math/SumTest.php @@ -29,7 +29,6 @@ public function provideData(): array ...Vec\range(0, 9), ], ], - [ 103, [ @@ -39,7 +38,6 @@ public function provideData(): array 15, ], ], - [ 534, [ @@ -48,7 +46,7 @@ public function provideData(): array ...Vec\range(0, 45, 5), 52, 64, - ] + ], ], ]; } diff --git a/tests/unit/Math/TanTest.php b/tests/unit/Math/TanTest.php index 07514263..ddd10e86 100644 --- a/tests/unit/Math/TanTest.php +++ b/tests/unit/Math/TanTest.php @@ -25,28 +25,24 @@ public function provideData(): array [ -3.380515006246586, 5.0, - 0.00000000000001 + 0.00000000000001, ], - [ -11.384870654242922, - 4.8 + 4.8, ], - [ 0.0, - 0.0 + 0.0, ], - [ 0.4227932187381618, - 0.4 + 0.4, ], - [ -0.22027720034589682, - -6.5 - ] + -6.5, + ], ]; } } diff --git a/tests/unit/Math/ToBaseTest.php b/tests/unit/Math/ToBaseTest.php index eb060959..689e3498 100644 --- a/tests/unit/Math/ToBaseTest.php +++ b/tests/unit/Math/ToBaseTest.php @@ -23,26 +23,23 @@ public function provideData(): array [ '1010101111001', 5497, - 2 + 2, ], - [ 'pphlmw9v', 2014587925987, - 36 + 36, ], - [ 'zik0zj', Math\INT32_MAX, - 36 + 36, ], - [ 'f', 15, - 16 - ] + 16, + ], ]; } } diff --git a/tests/unit/Option/NoneTest.php b/tests/unit/Option/NoneTest.php index bf570099..fc70ebfa 100644 --- a/tests/unit/Option/NoneTest.php +++ b/tests/unit/Option/NoneTest.php @@ -73,10 +73,10 @@ public function testOr(): void public function testOrElse(): void { - static::assertFalse(Option\none()->orElse(static fn () => Option\none())->isSome()); - static::assertTrue(Option\none()->orElse(static fn () => Option\some(4))->isSome()); - static::assertTrue(Option\none()->orElse(static fn () => Option\none())->isNone()); - static::assertFalse(Option\none()->orElse(static fn () => Option\some(4))->isNone()); + static::assertFalse(Option\none()->orElse(static fn() => Option\none())->isSome()); + static::assertTrue(Option\none()->orElse(static fn() => Option\some(4))->isSome()); + static::assertTrue(Option\none()->orElse(static fn() => Option\none())->isNone()); + static::assertFalse(Option\none()->orElse(static fn() => Option\some(4))->isNone()); } public function testFilter(): void @@ -97,8 +97,8 @@ public function testContains(): void public function testProceed(): void { $result = Option\none()->proceed( - static fn ($i) => Str\format('Value is %d', $i), - static fn () => 'There is no value', + static fn($i) => Str\format('Value is %d', $i), + static fn() => 'There is no value', ); static::assertSame('There is no value', $result); diff --git a/tests/unit/Option/SomeTest.php b/tests/unit/Option/SomeTest.php index a2439b05..86b676d3 100644 --- a/tests/unit/Option/SomeTest.php +++ b/tests/unit/Option/SomeTest.php @@ -70,10 +70,10 @@ public function testOr(): void public function testOrElse(): void { - static::assertTrue(Option\some(2)->orElse(static fn () => Option\none())->isSome()); - static::assertTrue(Option\some(2)->orElse(static fn () => Option\some(4))->isSome()); - static::assertFalse(Option\some(2)->orElse(static fn () => Option\none())->isNone()); - static::assertFalse(Option\some(2)->orElse(static fn () => Option\some(4))->isNone()); + static::assertTrue(Option\some(2)->orElse(static fn() => Option\none())->isSome()); + static::assertTrue(Option\some(2)->orElse(static fn() => Option\some(4))->isSome()); + static::assertFalse(Option\some(2)->orElse(static fn() => Option\none())->isNone()); + static::assertFalse(Option\some(2)->orElse(static fn() => Option\some(4))->isNone()); } public function testFilter(): void @@ -95,8 +95,8 @@ public function testContains(): void public function testProceed(): void { $result = Option\some(1)->proceed( - static fn ($i) => Str\format('Value is %d', $i), - static fn () => 'There is no value', + static fn($i) => Str\format('Value is %d', $i), + static fn() => 'There is no value', ); static::assertSame('Value is 1', $result); @@ -167,7 +167,7 @@ public function testEquality() public function testZip(): void { $x = Option\some(1); - $y = Option\some("hi"); + $y = Option\some('hi'); static::assertTrue(Option\some([1, 'hi'])->equals($x->zip($y))); static::assertTrue(Option\some(['hi', 1])->equals($y->zip($x))); diff --git a/tests/unit/Password/PasswordTest.php b/tests/unit/Password/PasswordTest.php index 1c1b8c14..e435f53a 100644 --- a/tests/unit/Password/PasswordTest.php +++ b/tests/unit/Password/PasswordTest.php @@ -29,7 +29,7 @@ public function testDefault(string $password): void public function testBcrypt(string $password): void { $hash = Password\hash($password, Password\Algorithm::Bcrypt, [ - 'cost' => 8 + 'cost' => 8, ]); static::assertTrue(Password\verify($password, $hash)); @@ -39,7 +39,7 @@ public function testBcrypt(string $password): void static::assertSame(8, $information['options']['cost']); static::assertFalse(Password\needs_rehash($hash, Password\Algorithm::Bcrypt, [ - 'cost' => 8 + 'cost' => 8, ])); } diff --git a/tests/unit/Range/FromRangeTest.php b/tests/unit/Range/FromRangeTest.php index 01122ed0..3c6d1e8c 100644 --- a/tests/unit/Range/FromRangeTest.php +++ b/tests/unit/Range/FromRangeTest.php @@ -32,7 +32,7 @@ public function testContains(): void static::assertFalse($range->contains(Math\INT53_MIN)); static::assertFalse($range->contains(Math\INT64_MIN)); } - + public function testLowerBound(): void { $range = Range\from(10); diff --git a/tests/unit/Range/ToRangeTest.php b/tests/unit/Range/ToRangeTest.php index 2f84d312..8ed60064 100644 --- a/tests/unit/Range/ToRangeTest.php +++ b/tests/unit/Range/ToRangeTest.php @@ -96,7 +96,7 @@ public function testContains(): void static::assertTrue($range->contains(Math\INT53_MIN)); static::assertTrue($range->contains(Math\INT64_MIN)); } - + public function testIsInclusive(): void { $range = Range\to(100, inclusive: true); diff --git a/tests/unit/Regex/EveryMatchTest.php b/tests/unit/Regex/EveryMatchTest.php index f8559cf9..57b25047 100644 --- a/tests/unit/Regex/EveryMatchTest.php +++ b/tests/unit/Regex/EveryMatchTest.php @@ -19,8 +19,8 @@ public function testMatching( array $expected, string $subject, string $pattern, - ?TypeInterface $shape = null, - int $offset = 0 + null|TypeInterface $shape = null, + int $offset = 0, ): void { static::assertSame($expected, Regex\every_match($subject, $pattern, $shape, $offset)); } @@ -52,80 +52,66 @@ public function testInvalidCaptureGroup(): void public function provideMatchingData(): iterable { yield [ - [ - [ - 0 => 'PHP', - 1 => 'PHP', - ] - ], + [[ + 0 => 'PHP', + 1 => 'PHP', + ]], 'PHP is the web scripting language of choice.', '/(php)/i', - capture_groups([1]) + capture_groups([1]), ]; yield [ - [ - [ - 0 => 'Hello world', - 1 => 'Hello', - ] - ], + [[ + 0 => 'Hello world', + 1 => 'Hello', + ]], 'Hello world is the web scripting language of choice.', '/(hello) world/i', - capture_groups([1]) + capture_groups([1]), ]; yield [ - [ - [ - 0 => 'web', - 1 => 'web', - ] - ], + [[ + 0 => 'web', + 1 => 'web', + ]], 'PHP is the web scripting language of choice.', '/(\bweb\b)/i', - capture_groups([1]) + capture_groups([1]), ]; yield [ - [ - [ - 0 => 'web', - 1 => 'web', - ] - ], + [[ + 0 => 'web', + 1 => 'web', + ]], 'PHP is the web scripting language of choice.', - '/(\bweb\b)/i' + '/(\bweb\b)/i', ]; yield [ - [ - [ - 0 => 'PHP', - 'language' => 'PHP' - ], - ], + [[ + 0 => 'PHP', + 'language' => 'PHP', + ]], 'PHP is the web scripting language of choice.', '/(?PPHP)/', - capture_groups(['language']) + capture_groups(['language']), ]; yield [ - [ - [ - 0 => 'PHP', - 'language' => 'PHP', - 1 => 'PHP', - ], - ], + [[ + 0 => 'PHP', + 'language' => 'PHP', + 1 => 'PHP', + ]], 'PHP is the web scripting language of choice.', - '/(?PPHP)/' + '/(?PPHP)/', ]; yield [ - [ - [ - 0 => 'http://www.php.net', - 1 => 'www.php.net', - ] - ], + [[ + 0 => 'http://www.php.net', + 1 => 'www.php.net', + ]], 'http://www.php.net/index.html', '@^(?:http://)?([^/]+)@i', - capture_groups([1]) + capture_groups([1]), ]; yield [ [ @@ -151,7 +137,7 @@ public function provideMatchingData(): iterable c: 3 FOO, '@(\w+): (\d+)@i', - capture_groups([1, 2]) + capture_groups([1, 2]), ]; yield [ [ @@ -177,7 +163,7 @@ public function provideMatchingData(): iterable c: 3 FOO, '@(?P\w+): (?P\d+)@i', - capture_groups(['name', 'digit']) + capture_groups(['name', 'digit']), ]; } diff --git a/tests/unit/Regex/FirstMatchTest.php b/tests/unit/Regex/FirstMatchTest.php index b0bca838..205fef8f 100644 --- a/tests/unit/Regex/FirstMatchTest.php +++ b/tests/unit/Regex/FirstMatchTest.php @@ -19,8 +19,8 @@ public function testMatching( array $expected, string $subject, string $pattern, - ?TypeInterface $shape = null, - int $offset = 0 + null|TypeInterface $shape = null, + int $offset = 0, ): void { static::assertSame($expected, Regex\first_match($subject, $pattern, $shape, $offset)); } @@ -58,7 +58,7 @@ public function provideMatchingData(): iterable ], 'PHP is the web scripting language of choice.', '/(php)/i', - capture_groups([1]) + capture_groups([1]), ]; yield [ [ @@ -67,7 +67,7 @@ public function provideMatchingData(): iterable ], 'Hello world is the web scripting language of choice.', '/(hello) world/i', - capture_groups([1]) + capture_groups([1]), ]; yield [ [ @@ -76,7 +76,7 @@ public function provideMatchingData(): iterable ], 'PHP is the web scripting language of choice.', '/(\bweb\b)/i', - capture_groups([1]) + capture_groups([1]), ]; yield [ [ @@ -84,7 +84,7 @@ public function provideMatchingData(): iterable 1 => 'web', ], 'PHP is the web scripting language of choice.', - '/(\bweb\b)/i' + '/(\bweb\b)/i', ]; yield [ [ @@ -93,16 +93,16 @@ public function provideMatchingData(): iterable ], 'PHP is the web scripting language of choice.', '/(?PPHP)/', - capture_groups(['language']) + capture_groups(['language']), ]; yield [ [ 0 => 'http://www.php.net', - 1 => 'www.php.net' + 1 => 'www.php.net', ], 'http://www.php.net/index.html', '@^(?:http://)?([^/]+)@i', - capture_groups([1]) + capture_groups([1]), ]; yield [ [ diff --git a/tests/unit/Regex/ReplaceEveryTest.php b/tests/unit/Regex/ReplaceEveryTest.php index af53220a..851602f9 100644 --- a/tests/unit/Regex/ReplaceEveryTest.php +++ b/tests/unit/Regex/ReplaceEveryTest.php @@ -19,19 +19,31 @@ public function testReplaceEvery(string $expected, string $subject, array $repla public function provideData(): iterable { - yield ['April1,2003', 'April 15, 2003', [ - '/(\w+) (\d+), (\d+)/i' => '${1}1,$3' - ]]; - - yield ['The slow black bear jumps over the lazy dog.', 'The quick brown fox jumps over the lazy dog.', [ - '/quick/' => 'slow', - '/brown/' => 'black', - '/fox/' => 'bear' - ]]; - - yield ['Hello, World!', 'Hello, World!', [ - '/foo/' => 'bar' - ]]; + yield [ + 'April1,2003', + 'April 15, 2003', + [ + '/(\w+) (\d+), (\d+)/i' => '${1}1,$3', + ], + ]; + + yield [ + 'The slow black bear jumps over the lazy dog.', + 'The quick brown fox jumps over the lazy dog.', + [ + '/quick/' => 'slow', + '/brown/' => 'black', + '/fox/' => 'bear', + ], + ]; + + yield [ + 'Hello, World!', + 'Hello, World!', + [ + '/foo/' => 'bar', + ], + ]; } public function testReplaceEveryWithInvalidPattern(): void diff --git a/tests/unit/Regex/ReplaceWithTest.php b/tests/unit/Regex/ReplaceWithTest.php index 1b26f7c1..4bf39b01 100644 --- a/tests/unit/Regex/ReplaceWithTest.php +++ b/tests/unit/Regex/ReplaceWithTest.php @@ -17,7 +17,7 @@ public function testReplaceWith( string $subject, string $pattern, callable $callback, - ?int $limit = null + null|int $limit = null, ): void { static::assertSame($expected, Regex\replace_with($subject, $pattern, $callback, $limit)); } @@ -28,7 +28,7 @@ public function provideData(): iterable 'April fools day is 04/01/2003', 'April fools day is 04/01/2002', '|(\d{2}/\d{2}/)(\d{4})|', - static fn(array $matches): string => $matches[1] . (((int)$matches[2]) + 1), + static fn(array $matches): string => $matches[1] . ((int) $matches[2]) + 1, null, ]; @@ -36,7 +36,7 @@ public function provideData(): iterable 'Last christmas was 12/24/2021', 'Last christmas was 12/24/2001', '|(\d{2}/\d{2}/)(\d{4})|', - static fn(array $matches): string => $matches[1] . (((int)$matches[2]) + 20), + static fn(array $matches): string => $matches[1] . ((int) $matches[2]) + 20, null, ]; @@ -44,7 +44,7 @@ public function provideData(): iterable 'Last christmas was 12/24/2021, April fools day is 04/01/2022', 'Last christmas was 12/24/2001, April fools day is 04/01/2002', '|(\d{2}/\d{2}/)(\d{4})|', - static fn(array $matches): string => $matches[1] . (((int)$matches[2]) + 20), + static fn(array $matches): string => $matches[1] . ((int) $matches[2]) + 20, null, ]; @@ -52,7 +52,7 @@ public function provideData(): iterable 'Last christmas was 12/24/2021, April fools day is 04/01/2002', 'Last christmas was 12/24/2001, April fools day is 04/01/2002', '|(\d{2}/\d{2}/)(\d{4})|', - static fn(array $matches): string => $matches[1] . (((int)$matches[2]) + 20), + static fn(array $matches): string => $matches[1] . ((int) $matches[2]) + 20, 1, ]; } @@ -65,7 +65,7 @@ public function testReplaceWithInvalidPattern(): void Regex\replace_with( 'April 15, 2003', '|(\d{2}/\d{2}/)(\d{4})', - static fn(array $matches): string => $matches[1] . (((int)$matches[2]) + 20) + static fn(array $matches): string => $matches[1] . ((int) $matches[2]) + 20, ); } } diff --git a/tests/unit/Regex/SplitTest.php b/tests/unit/Regex/SplitTest.php index 78af0468..85ea3130 100644 --- a/tests/unit/Regex/SplitTest.php +++ b/tests/unit/Regex/SplitTest.php @@ -12,7 +12,7 @@ final class SplitTest extends TestCase /** * @dataProvider provideData */ - public function testSplit(array $expected, string $subject, string $pattern, ?int $limit = null): void + public function testSplit(array $expected, string $subject, string $pattern, null|int $limit = null): void { static::assertSame($expected, Regex\split($subject, $pattern, $limit)); } @@ -22,26 +22,26 @@ public function provideData(): iterable yield [ ['hello'], 'hello', - "/[\s,]+/" + "/[\s,]+/", ]; yield [ ['php', 'standard', 'library'], 'php standard library', - "/[\s,]+/" + "/[\s,]+/", ]; yield [ ['p', 'h', 'p', ' ', 's', 't', 'a', 'n', 'd', 'a', 'r', 'd', ' ', 'l', 'i', 'b', 'r', 'a', 'r', 'y'], 'php standard library', - "//" + '//', ]; yield [ ['p', 'h', 'p', ' ', 'standard library'], 'php standard library', - "//", - 5 + '//', + 5, ]; } diff --git a/tests/unit/Result/FailureTest.php b/tests/unit/Result/FailureTest.php index c8104a8f..51fef31c 100644 --- a/tests/unit/Result/FailureTest.php +++ b/tests/unit/Result/FailureTest.php @@ -27,7 +27,7 @@ public function testIsFailed(): void public function testGetResult(): void { $exception = new Exception('bar'); - $wrapper = new Failure($exception); + $wrapper = new Failure($exception); $this->expectExceptionObject($exception); $wrapper->getResult(); @@ -44,18 +44,18 @@ public function testUnwrapFailure(): void public function testGetException(): void { $exception = new Exception('bar'); - $wrapper = new Failure($exception); - $e = $wrapper->getThrowable(); + $wrapper = new Failure($exception); + $e = $wrapper->getThrowable(); static::assertSame($exception, $e); } public function testProceed(): void { $exception = new Exception('bar'); - $wrapper = new Failure($exception); - $actual = $wrapper->proceed( - static fn (string $result): int => 200, - static fn (Exception $exception): int => 404 + $wrapper = new Failure($exception); + $actual = $wrapper->proceed( + static fn(string $_result): int => 200, + static fn(Exception $_exception): int => 404, ); static::assertSame(404, $actual); @@ -64,12 +64,12 @@ public function testProceed(): void public function testThenToSuccess(): void { $exception = new Exception('bar'); - $wrapper = new Failure($exception); - $actual = $wrapper->then( + $wrapper = new Failure($exception); + $actual = $wrapper->then( static function () { throw new Exception('Dont call us, we\'ll call you!'); }, - static fn (Exception $exception): string => $exception->getMessage() + static fn(Exception $exception): string => $exception->getMessage(), ); static::assertTrue($actual->isSucceeded()); @@ -79,13 +79,10 @@ static function () { public function testThenToFailure(): void { $exception = new Exception('bar'); - $wrapper = new Failure($exception); - $actual = $wrapper->then( - static function () { - throw new Exception('Dont call us, we\'ll call you!'); - }, - Fun\rethrow() - ); + $wrapper = new Failure($exception); + $actual = $wrapper->then(static function () { + throw new Exception('Dont call us, we\'ll call you!'); + }, Fun\rethrow()); static::assertFalse($actual->isSucceeded()); static::assertSame($actual->getThrowable(), $exception); @@ -94,15 +91,15 @@ static function () { public function testCatch(): void { $exception = new Exception('bar'); - $wrapper = new Failure($exception); - $actual = $wrapper->catch(Fun\rethrow()); + $wrapper = new Failure($exception); + $actual = $wrapper->catch(Fun\rethrow()); static::assertFalse($actual->isSucceeded()); static::assertSame($actual->getThrowable(), $exception); $exception = new Exception('bar'); - $wrapper = new Failure($exception); - $actual = $wrapper->catch(static fn($exception) => $exception); + $wrapper = new Failure($exception); + $actual = $wrapper->catch(static fn($exception) => $exception); static::assertTrue($actual->isSucceeded()); static::assertSame($exception, $actual->getResult()); @@ -111,8 +108,8 @@ public function testCatch(): void public function testMap(): void { $exception = new Exception('bar'); - $wrapper = new Failure($exception); - $actual = $wrapper->map(static function () { + $wrapper = new Failure($exception); + $actual = $wrapper->map(static function () { throw new Exception('Dont call us, we\'ll call you!'); }); @@ -124,8 +121,8 @@ public function testAlways(): void { $ref = new Psl\Ref(''); $exception = new Exception('bar'); - $wrapper = new Failure($exception); - $actual = $wrapper->always(static function () use ($ref) { + $wrapper = new Failure($exception); + $actual = $wrapper->always(static function () use ($ref) { $ref->value .= 'hello'; }); diff --git a/tests/unit/Result/SuccessTest.php b/tests/unit/Result/SuccessTest.php index b249817d..8860c9b8 100644 --- a/tests/unit/Result/SuccessTest.php +++ b/tests/unit/Result/SuccessTest.php @@ -52,9 +52,9 @@ public function testGetException(): void public function testProceed(): void { $wrapper = new Success('hello'); - $actual = $wrapper->proceed( - static fn (string $result): int => 200, - static fn (Exception $exception): int => 404 + $actual = $wrapper->proceed( + static fn(string $_result): int => 200, + static fn(Exception $_exception): int => 404, ); static::assertSame(200, $actual); @@ -63,10 +63,7 @@ public function testProceed(): void public function testThenToSuccess(): void { $wrapper = new Success('hello'); - $actual = $wrapper->then( - Fun\identity(), - Fun\rethrow() - ); + $actual = $wrapper->then(Fun\identity(), Fun\rethrow()); static::assertNotSame($wrapper, $actual); static::assertTrue($actual->isSucceeded()); @@ -76,12 +73,12 @@ public function testThenToSuccess(): void public function testThenToFailure(): void { $exception = new Exception('bar'); - $wrapper = new Success('hello'); - $actual = $wrapper->then( + $wrapper = new Success('hello'); + $actual = $wrapper->then( static function () use ($exception) { throw $exception; }, - Fun\rethrow() + Fun\rethrow(), ); static::assertFalse($actual->isSucceeded()); @@ -91,7 +88,7 @@ static function () use ($exception) { public function testCatch(): void { $wrapper = new Success('hello'); - $actual = $wrapper->catch(static function () { + $actual = $wrapper->catch(static function () { throw new Exception('Dont call us, we\'ll call you!'); }); @@ -103,14 +100,14 @@ public function testCatch(): void public function testMap(): void { $wrapper = new Success('hello'); - $actual = $wrapper->map(Fun\identity()); + $actual = $wrapper->map(Fun\identity()); static::assertNotSame($wrapper, $actual); static::assertTrue($actual->isSucceeded()); static::assertSame('hello', $actual->getResult()); $wrapper = new Success('hello'); - $actual = $wrapper->map(static fn() => throw new Exception('bye')); + $actual = $wrapper->map(static fn() => throw new Exception('bye')); static::assertNotSame($wrapper, $actual); static::assertFalse($actual->isSucceeded()); @@ -122,7 +119,7 @@ public function testAlways(): void { $ref = new Psl\Ref(''); $wrapper = new Success('hello'); - $actual = $wrapper->always(static function () use ($ref) { + $actual = $wrapper->always(static function () use ($ref) { $ref->value .= 'hey'; }); diff --git a/tests/unit/Result/TryCatchTest.php b/tests/unit/Result/TryCatchTest.php index 67fca230..7a69f14c 100644 --- a/tests/unit/Result/TryCatchTest.php +++ b/tests/unit/Result/TryCatchTest.php @@ -13,45 +13,29 @@ final class TryCatchTest extends TestCase { public function testTryResulting(): void { - $actual = Result\try_catch( - static fn () => true, - static fn () => false, - ); + $actual = Result\try_catch(static fn() => true, static fn() => false); static::assertTrue($actual); } public function testTryFailing(): void { - $actual = Result\try_catch( - static fn () => throw new Exception('Not my style'), - static fn () => false, - ); + $actual = Result\try_catch(static fn() => throw new Exception('Not my style'), static fn() => false); static::assertFalse($actual); } public function testTryThrowing(): void { - $this->expectExceptionObject( - $expected = new Exception('Mine either') - ); - - Result\try_catch( - static fn () => throw new Exception('Not my style'), - static fn () => throw $expected, - ); + $this->expectExceptionObject($expected = new Exception('Mine either')); + + Result\try_catch(static fn() => throw new Exception('Not my style'), static fn() => throw $expected); } public function testReThrowing(): void { - $this->expectExceptionObject( - $expected = new Exception('Not my style') - ); - - Result\try_catch( - static fn () => throw $expected, - static fn (Throwable $previous) => throw $previous, - ); + $this->expectExceptionObject($expected = new Exception('Not my style')); + + Result\try_catch(static fn() => throw $expected, static fn(Throwable $previous) => throw $previous); } } diff --git a/tests/unit/Result/WrapTest.php b/tests/unit/Result/WrapTest.php index 60fff79a..cd8ce883 100644 --- a/tests/unit/Result/WrapTest.php +++ b/tests/unit/Result/WrapTest.php @@ -14,7 +14,7 @@ final class WrapTest extends TestCase public function testWrapException(): void { $exception = new Exception('foo'); - $wrapper = Result\wrap(static function () use ($exception): void { + $wrapper = Result\wrap(static function () use ($exception): void { throw $exception; }); static::assertFalse($wrapper->isSucceeded()); diff --git a/tests/unit/Runtime/VersionTest.php b/tests/unit/Runtime/VersionTest.php index 2caf94a1..cb4a9a3e 100644 --- a/tests/unit/Runtime/VersionTest.php +++ b/tests/unit/Runtime/VersionTest.php @@ -26,12 +26,15 @@ public function testGetVersionDetails(): void static::assertArrayHasKey('release', $version_details); static::assertArrayHasKey('extra', $version_details); - static::assertSame([ - 'major' => PHP_MAJOR_VERSION, - 'minor' => PHP_MINOR_VERSION, - 'release' => PHP_RELEASE_VERSION, - 'extra' => PHP_EXTRA_VERSION ?: null, - ], $version_details); + static::assertSame( + [ + 'major' => PHP_MAJOR_VERSION, + 'minor' => PHP_MINOR_VERSION, + 'release' => PHP_RELEASE_VERSION, + 'extra' => PHP_EXTRA_VERSION ?: null, + ], + $version_details, + ); } public function testGetVersionId(): void diff --git a/tests/unit/Shell/Exception/FailedExecutionExceptionTest.php b/tests/unit/Shell/Exception/FailedExecutionExceptionTest.php index 343d94d7..b498eb80 100644 --- a/tests/unit/Shell/Exception/FailedExecutionExceptionTest.php +++ b/tests/unit/Shell/Exception/FailedExecutionExceptionTest.php @@ -14,14 +14,14 @@ public function testMethods(): void $exception = new Exception\FailedExecutionException('foo', 'bar', 'baz', 4); $message = <<getMessage()); static::assertSame('foo', $exception->getCommand()); diff --git a/tests/unit/Shell/ExecuteTest.php b/tests/unit/Shell/ExecuteTest.php index 7e0fc8f2..5429222e 100644 --- a/tests/unit/Shell/ExecuteTest.php +++ b/tests/unit/Shell/ExecuteTest.php @@ -14,10 +14,7 @@ final class ExecuteTest extends TestCase { public function testExecute(): void { - static::assertSame( - "Hello, World!", - Shell\execute(PHP_BINARY, ['-r', 'echo "Hello, World!";']) - ); + static::assertSame('Hello, World!', Shell\execute(PHP_BINARY, ['-r', 'echo "Hello, World!";'])); } public function testFailedExecution(): void @@ -44,10 +41,7 @@ public function testItThrowsForNULLByte(): void public function testEnvironmentIsPassedDownToTheProcess(): void { - static::assertSame( - 'BAR', - Shell\execute(PHP_BINARY, ['-r', 'echo getenv("FOO");'], null, ['FOO' => 'BAR']) - ); + static::assertSame('BAR', Shell\execute(PHP_BINARY, ['-r', 'echo getenv("FOO");'], null, ['FOO' => 'BAR'])); } public function testCurrentEnvironmentVariablesArePassedDownToTheProcess(): void @@ -55,10 +49,7 @@ public function testCurrentEnvironmentVariablesArePassedDownToTheProcess(): void try { Env\set_var('FOO', 'BAR'); - static::assertSame( - 'BAR', - Shell\execute(PHP_BINARY, ['-r', 'echo getenv("FOO");']) - ); + static::assertSame('BAR', Shell\execute(PHP_BINARY, ['-r', 'echo getenv("FOO");'])); } finally { Env\remove_var('FOO'); } @@ -76,10 +67,7 @@ public function testCurrentDirectoryIsUsedByDefault(): void { $dir = Env\current_dir(); - static::assertSame( - $dir, - Shell\execute(PHP_BINARY, ['-r', 'echo getcwd();']) - ); + static::assertSame($dir, Shell\execute(PHP_BINARY, ['-r', 'echo getcwd();'])); } public function testItThrowsWhenWorkingDirectoryDoesntExist(): void @@ -98,35 +86,55 @@ public function testErrorOutputIsDiscarded(): void static::assertSame('hello', $result); - $result = Shell\execute(PHP_BINARY, ['-r', 'fwrite(STDOUT, "hello"); fwrite(STDERR, " world");'], error_output_behavior: Shell\ErrorOutputBehavior::default()); + $result = Shell\execute( + PHP_BINARY, + ['-r', 'fwrite(STDOUT, "hello"); fwrite(STDERR, " world");'], + error_output_behavior: Shell\ErrorOutputBehavior::default(), + ); static::assertSame('hello', $result); } public function testErrorOutputIsAppended(): void { - $result = Shell\execute(PHP_BINARY, ['-r', 'fwrite(STDOUT, "hello"); fwrite(STDERR, " world");'], error_output_behavior: Shell\ErrorOutputBehavior::Append); + $result = Shell\execute( + PHP_BINARY, + ['-r', 'fwrite(STDOUT, "hello"); fwrite(STDERR, " world");'], + error_output_behavior: Shell\ErrorOutputBehavior::Append, + ); static::assertSame('hello world', $result); } public function testErrorOutputIsPrepended(): void { - $result = Shell\execute(PHP_BINARY, ['-r', 'fwrite(STDOUT, "hello"); fwrite(STDERR, " world");'], error_output_behavior: Shell\ErrorOutputBehavior::Prepend); + $result = Shell\execute( + PHP_BINARY, + ['-r', 'fwrite(STDOUT, "hello"); fwrite(STDERR, " world");'], + error_output_behavior: Shell\ErrorOutputBehavior::Prepend, + ); static::assertSame(' worldhello', $result); } public function testErrorOutputIsReplacingStandardOutput(): void { - $result = Shell\execute(PHP_BINARY, ['-r', 'fwrite(STDOUT, "hello"); fwrite(STDERR, " world");'], error_output_behavior: Shell\ErrorOutputBehavior::Replace); + $result = Shell\execute( + PHP_BINARY, + ['-r', 'fwrite(STDOUT, "hello"); fwrite(STDERR, " world");'], + error_output_behavior: Shell\ErrorOutputBehavior::Replace, + ); static::assertSame(' world', $result); } public function testErrorOutputIsPacked(): void { - $result = Shell\execute(PHP_BINARY, ['-r', 'fwrite(STDOUT, "hello"); fwrite(STDERR, " world");'], error_output_behavior: Shell\ErrorOutputBehavior::Packed); + $result = Shell\execute( + PHP_BINARY, + ['-r', 'fwrite(STDOUT, "hello"); fwrite(STDERR, " world");'], + error_output_behavior: Shell\ErrorOutputBehavior::Packed, + ); [$stdout, $stderr] = Shell\unpack($result); diff --git a/tests/unit/Shell/UnpackTest.php b/tests/unit/Shell/UnpackTest.php index 3fb3e5ce..6e09f243 100644 --- a/tests/unit/Shell/UnpackTest.php +++ b/tests/unit/Shell/UnpackTest.php @@ -16,7 +16,11 @@ final class UnpackTest extends TestCase { public function testUnpacking(): void { - $result = Shell\execute(PHP_BINARY, ['-r', 'fwrite(STDOUT, "hello"); fwrite(STDERR, " world");'], error_output_behavior: Shell\ErrorOutputBehavior::Packed); + $result = Shell\execute( + PHP_BINARY, + ['-r', 'fwrite(STDOUT, "hello"); fwrite(STDERR, " world");'], + error_output_behavior: Shell\ErrorOutputBehavior::Packed, + ); [$stdout, $stderr] = Shell\unpack($result); @@ -26,7 +30,11 @@ public function testUnpacking(): void public function testUnpackingStandardOutputOnly(): void { - $result = Shell\execute(PHP_BINARY, ['-r', 'fwrite(STDOUT, "hello");'], error_output_behavior: Shell\ErrorOutputBehavior::Packed); + $result = Shell\execute( + PHP_BINARY, + ['-r', 'fwrite(STDOUT, "hello");'], + error_output_behavior: Shell\ErrorOutputBehavior::Packed, + ); [$stdout, $stderr] = Shell\unpack($result); @@ -36,7 +44,11 @@ public function testUnpackingStandardOutputOnly(): void public function testUnpackingStandardErrorOutputOnly(): void { - $result = Shell\execute(PHP_BINARY, ['-r', 'fwrite(STDERR, "hello");'], error_output_behavior: Shell\ErrorOutputBehavior::Packed); + $result = Shell\execute( + PHP_BINARY, + ['-r', 'fwrite(STDERR, "hello");'], + error_output_behavior: Shell\ErrorOutputBehavior::Packed, + ); [$stdout, $stderr] = Shell\unpack($result); @@ -46,7 +58,11 @@ public function testUnpackingStandardErrorOutputOnly(): void public function testUnpackingEmpty(): void { - $result = Shell\execute(PHP_BINARY, ['-r', 'exit(0);'], error_output_behavior: Shell\ErrorOutputBehavior::Packed); + $result = Shell\execute( + PHP_BINARY, + ['-r', 'exit(0);'], + error_output_behavior: Shell\ErrorOutputBehavior::Packed, + ); [$stdout, $stderr] = Shell\unpack($result); @@ -56,7 +72,11 @@ public function testUnpackingEmpty(): void public function testUnpackingInvalidMessage(): void { - $result = Shell\execute(PHP_BINARY, ['-r', 'fwrite(STDERR, "hello");'], error_output_behavior: Shell\ErrorOutputBehavior::Packed); + $result = Shell\execute( + PHP_BINARY, + ['-r', 'fwrite(STDERR, "hello");'], + error_output_behavior: Shell\ErrorOutputBehavior::Packed, + ); $result .= ' world!'; $this->expectException(Shell\Exception\InvalidArgumentException::class); @@ -67,7 +87,11 @@ public function testUnpackingInvalidMessage(): void public function testUnpackingInvalidAdditionalHeader(): void { - $result = Shell\execute(PHP_BINARY, ['-r', 'fwrite(STDERR, "hello");'], error_output_behavior: Shell\ErrorOutputBehavior::Packed); + $result = Shell\execute( + PHP_BINARY, + ['-r', 'fwrite(STDERR, "hello");'], + error_output_behavior: Shell\ErrorOutputBehavior::Packed, + ); $result .= 'x'; $this->expectException(Shell\Exception\InvalidArgumentException::class); @@ -78,7 +102,11 @@ public function testUnpackingInvalidAdditionalHeader(): void public function testUnpackingInvalidNulHeader(): void { - $result = Shell\execute(PHP_BINARY, ['-r', 'fwrite(STDERR, "hello");'], error_output_behavior: Shell\ErrorOutputBehavior::Packed); + $result = Shell\execute( + PHP_BINARY, + ['-r', 'fwrite(STDERR, "hello");'], + error_output_behavior: Shell\ErrorOutputBehavior::Packed, + ); $result .= "\0\0\0\0\0"; $this->expectException(Shell\Exception\InvalidArgumentException::class); @@ -89,7 +117,11 @@ public function testUnpackingInvalidNulHeader(): void public function testUnpackingInvalidLength(): void { - $result = Shell\execute(PHP_BINARY, ['-r', 'fwrite(STDERR, "hello");'], error_output_behavior: Shell\ErrorOutputBehavior::Packed); + $result = Shell\execute( + PHP_BINARY, + ['-r', 'fwrite(STDERR, "hello");'], + error_output_behavior: Shell\ErrorOutputBehavior::Packed, + ); $result .= Str\slice($result, 0, 7); $this->expectException(Shell\Exception\InvalidArgumentException::class); @@ -100,7 +132,11 @@ public function testUnpackingInvalidLength(): void public function testUnpackingInvalidType(): void { - $result = Shell\execute(PHP_BINARY, ['-r', 'fwrite(STDERR, "hello");'], error_output_behavior: Shell\ErrorOutputBehavior::Packed); + $result = Shell\execute( + PHP_BINARY, + ['-r', 'fwrite(STDERR, "hello");'], + error_output_behavior: Shell\ErrorOutputBehavior::Packed, + ); $result .= pack('C1N1', 3, 1) . 'a'; $this->expectException(Shell\Exception\InvalidArgumentException::class); diff --git a/tests/unit/Str/AfterCiTest.php b/tests/unit/Str/AfterCiTest.php index 44ee754e..99ea92df 100644 --- a/tests/unit/Str/AfterCiTest.php +++ b/tests/unit/Str/AfterCiTest.php @@ -13,11 +13,11 @@ final class AfterCiTest extends TestCase * @dataProvider provideData */ public function testAfter( - ?string $expected, + null|string $expected, string $haystack, string $needle, int $offset, - Str\Encoding $encoding + Str\Encoding $encoding, ): void { static::assertSame($expected, Str\after_ci($haystack, $needle, $offset, $encoding)); } @@ -25,7 +25,7 @@ public function testAfter( public function provideData(): array { return [ - [null, '', '', 0, Str\Encoding::Utf8], + [null, '', '', 0, Str\Encoding::Utf8], ['orld!', 'Hello, World!', 'W', 0, Str\Encoding::Utf8], ['!', '🤷!', '🤷', 0, Str\Encoding::Utf8], [null, 'مرحبا بكم', '', 0, Str\Encoding::Utf8], diff --git a/tests/unit/Str/AfterLastCiTest.php b/tests/unit/Str/AfterLastCiTest.php index 87b13f89..ecec4911 100644 --- a/tests/unit/Str/AfterLastCiTest.php +++ b/tests/unit/Str/AfterLastCiTest.php @@ -12,19 +12,15 @@ final class AfterLastCiTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset, - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Str\after_last_ci($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['orld!', 'Hello, World!', 'W', 0], ['!', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/AfterLastTest.php b/tests/unit/Str/AfterLastTest.php index ef95da6d..00664ede 100644 --- a/tests/unit/Str/AfterLastTest.php +++ b/tests/unit/Str/AfterLastTest.php @@ -12,19 +12,15 @@ final class AfterLastTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset, - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Str\after_last($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['orld!', 'Hello, World!', 'W', 0], ['!', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/AfterTest.php b/tests/unit/Str/AfterTest.php index ae794e80..f9e0dc05 100644 --- a/tests/unit/Str/AfterTest.php +++ b/tests/unit/Str/AfterTest.php @@ -12,20 +12,15 @@ final class AfterTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset, - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Str\after($haystack, $needle, $offset)); } - public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['orld!', 'Hello, World!', 'W', 0], ['!', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/BeforeCiTest.php b/tests/unit/Str/BeforeCiTest.php index 1e82674f..3b9b8cc1 100644 --- a/tests/unit/Str/BeforeCiTest.php +++ b/tests/unit/Str/BeforeCiTest.php @@ -12,19 +12,15 @@ final class BeforeCiTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset, - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Str\before_ci($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['Hello, ', 'Hello, World!', 'W', 0], ['', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/BeforeLastCiTest.php b/tests/unit/Str/BeforeLastCiTest.php index 614c7cba..92ec3524 100644 --- a/tests/unit/Str/BeforeLastCiTest.php +++ b/tests/unit/Str/BeforeLastCiTest.php @@ -12,19 +12,15 @@ final class BeforeLastCiTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset, - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Str\before_last_ci($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['Hello, ', 'Hello, World!', 'W', 0], ['', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/BeforeLastTest.php b/tests/unit/Str/BeforeLastTest.php index 80264646..fbca5bef 100644 --- a/tests/unit/Str/BeforeLastTest.php +++ b/tests/unit/Str/BeforeLastTest.php @@ -12,19 +12,15 @@ final class BeforeLastTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset, - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Str\before_last($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['Hello, ', 'Hello, World!', 'W', 0], ['', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/BeforeTest.php b/tests/unit/Str/BeforeTest.php index 7caa7e78..ea7c9341 100644 --- a/tests/unit/Str/BeforeTest.php +++ b/tests/unit/Str/BeforeTest.php @@ -12,20 +12,15 @@ final class BeforeTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset, - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Str\before($haystack, $needle, $offset)); } - public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['Hello, ', 'Hello, World!', 'W', 0], ['', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/Byte/AfterCiTest.php b/tests/unit/Str/Byte/AfterCiTest.php index b6098d7b..195a06ab 100644 --- a/tests/unit/Str/Byte/AfterCiTest.php +++ b/tests/unit/Str/Byte/AfterCiTest.php @@ -12,19 +12,15 @@ final class AfterCiTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Byte\after_ci($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['orld!', 'Hello, World!', 'W', 0], ['!', '🤷!', '🤷', 0], ['', '🤷!', '!', 0], diff --git a/tests/unit/Str/Byte/AfterLastCiTest.php b/tests/unit/Str/Byte/AfterLastCiTest.php index 120e73c5..bf5c903a 100644 --- a/tests/unit/Str/Byte/AfterLastCiTest.php +++ b/tests/unit/Str/Byte/AfterLastCiTest.php @@ -12,19 +12,15 @@ final class AfterLastCiTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Byte\after_last_ci($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['orld!', 'Hello, World!', 'W', 0], ['!', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/Byte/AfterLastTest.php b/tests/unit/Str/Byte/AfterLastTest.php index db551975..a8eb7a12 100644 --- a/tests/unit/Str/Byte/AfterLastTest.php +++ b/tests/unit/Str/Byte/AfterLastTest.php @@ -12,19 +12,15 @@ final class AfterLastTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Byte\after_last($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['orld!', 'Hello, World!', 'W', 0], ['!', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/Byte/AfterTest.php b/tests/unit/Str/Byte/AfterTest.php index 06855f9c..ca36bbf4 100644 --- a/tests/unit/Str/Byte/AfterTest.php +++ b/tests/unit/Str/Byte/AfterTest.php @@ -12,20 +12,15 @@ final class AfterTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Byte\after($haystack, $needle, $offset)); } - public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['orld!', 'Hello, World!', 'W', 0], ['!', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/Byte/BeforeCiTest.php b/tests/unit/Str/Byte/BeforeCiTest.php index 80361e43..3e6ace44 100644 --- a/tests/unit/Str/Byte/BeforeCiTest.php +++ b/tests/unit/Str/Byte/BeforeCiTest.php @@ -12,19 +12,15 @@ final class BeforeCiTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Byte\before_ci($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['Hello, ', 'Hello, World!', 'W', 0], ['', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/Byte/BeforeLastCiTest.php b/tests/unit/Str/Byte/BeforeLastCiTest.php index 40e2c2d0..2870f7ac 100644 --- a/tests/unit/Str/Byte/BeforeLastCiTest.php +++ b/tests/unit/Str/Byte/BeforeLastCiTest.php @@ -12,19 +12,15 @@ final class BeforeLastCiTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Byte\before_last_ci($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['Hello, ', 'Hello, World!', 'W', 0], ['', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/Byte/BeforeLastTest.php b/tests/unit/Str/Byte/BeforeLastTest.php index 51f79c7b..5162aaf3 100644 --- a/tests/unit/Str/Byte/BeforeLastTest.php +++ b/tests/unit/Str/Byte/BeforeLastTest.php @@ -12,19 +12,15 @@ final class BeforeLastTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Byte\before_last($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['Hello, ', 'Hello, World!', 'W', 0], ['', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/Byte/BeforeTest.php b/tests/unit/Str/Byte/BeforeTest.php index 3084f575..f0f718ab 100644 --- a/tests/unit/Str/Byte/BeforeTest.php +++ b/tests/unit/Str/Byte/BeforeTest.php @@ -12,20 +12,15 @@ final class BeforeTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Byte\before($haystack, $needle, $offset)); } - public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['Hello, ', 'Hello, World!', 'W', 0], ['', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/Byte/CapitalizeTest.php b/tests/unit/Str/Byte/CapitalizeTest.php index 47ef2644..384da120 100644 --- a/tests/unit/Str/Byte/CapitalizeTest.php +++ b/tests/unit/Str/Byte/CapitalizeTest.php @@ -21,9 +21,9 @@ public function provideData(): array { return [ ['', ''], - ['Hello', 'hello', ], + ['Hello', 'hello'], ['Hello, world', 'hello, world'], - ['Alpha', 'Alpha', ], + ['Alpha', 'Alpha'], ['Héllö, wôrld!', 'héllö, wôrld!'], ['ßoo', 'ßoo'], ]; diff --git a/tests/unit/Str/Byte/CapitalizeWordsTest.php b/tests/unit/Str/Byte/CapitalizeWordsTest.php index 88b78805..cf51dca5 100644 --- a/tests/unit/Str/Byte/CapitalizeWordsTest.php +++ b/tests/unit/Str/Byte/CapitalizeWordsTest.php @@ -20,10 +20,10 @@ public function testCapitalizeWords(string $expected, string $value): void public function provideData(): array { return [ - ['Hello', 'hello', ], + ['Hello', 'hello'], ['Hello, World', 'hello, world'], - ['Alpha', 'Alpha', ], - ['Foo, Bar, And Baz', 'foo, bar, and baz'] + ['Alpha', 'Alpha'], + ['Foo, Bar, And Baz', 'foo, bar, and baz'], ]; } } diff --git a/tests/unit/Str/Byte/ChrTest.php b/tests/unit/Str/Byte/ChrTest.php index 2472e2e6..50d9f15c 100644 --- a/tests/unit/Str/Byte/ChrTest.php +++ b/tests/unit/Str/Byte/ChrTest.php @@ -24,7 +24,7 @@ public function provideData(): array ['0', 48], ['&', 38], ['\'', 1575], - ['A', 65] + ['A', 65], ]; } } diff --git a/tests/unit/Str/Byte/ChunkTest.php b/tests/unit/Str/Byte/ChunkTest.php index 6055e95f..6d7f8dc8 100644 --- a/tests/unit/Str/Byte/ChunkTest.php +++ b/tests/unit/Str/Byte/ChunkTest.php @@ -20,9 +20,9 @@ public function testCapitalize(array $expected, string $value, int $chunk_size = public function provideData(): array { return [ - [['h', 'e', 'l', 'l', 'o'], 'hello', ], - [['h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd'], 'hello, world', ], - [['Al', 'ph', 'a ', ' '], 'Alpha ', 2, ], + [['h', 'e', 'l', 'l', 'o'], 'hello'], + [['h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd'], 'hello, world'], + [['Al', 'ph', 'a ', ' '], 'Alpha ', 2], [['م', 'ر', 'ح', 'ب', 'ا'], 'مرحبا', 2], [[], ''], ]; diff --git a/tests/unit/Str/Byte/CompareCiTest.php b/tests/unit/Str/Byte/CompareCiTest.php index 6c54bcd2..0dcd3ee6 100644 --- a/tests/unit/Str/Byte/CompareCiTest.php +++ b/tests/unit/Str/Byte/CompareCiTest.php @@ -12,7 +12,7 @@ final class CompareCiTest extends TestCase /** * @dataProvider provideData */ - public function testCompareCi(int $expected, string $str1, string $str2, ?int $length = null): void + public function testCompareCi(int $expected, string $str1, string $str2, null|int $length = null): void { $diff = Byte\compare_ci($str1, $str2, $length); diff --git a/tests/unit/Str/Byte/CompareTest.php b/tests/unit/Str/Byte/CompareTest.php index b3099d0a..4555b76e 100644 --- a/tests/unit/Str/Byte/CompareTest.php +++ b/tests/unit/Str/Byte/CompareTest.php @@ -12,7 +12,7 @@ final class CompareTest extends TestCase /** * @dataProvider provideData */ - public function testCompare(int $expected, string $str1, string $str2, ?int $length = null): void + public function testCompare(int $expected, string $str1, string $str2, null|int $length = null): void { $diff = Byte\compare($str1, $str2, $length); diff --git a/tests/unit/Str/Byte/ContainsTest.php b/tests/unit/Str/Byte/ContainsTest.php index 77f6c996..d70a0f11 100644 --- a/tests/unit/Str/Byte/ContainsTest.php +++ b/tests/unit/Str/Byte/ContainsTest.php @@ -24,49 +24,44 @@ public function provideData(): array true, 'Hello, World', 'Hello', - 0 + 0, ], - [ false, 'Hello, World', 'world', - 0 + 0, ], - [ true, 'Hello, World', '', - 8 + 8, ], - [ false, 'hello, world', 'hey', - 5 + 5, ], - [ true, 'azjezz', 'az', - 0 + 0, ], [ false, 'azjezz', 'Az', - 2 + 2, ], - [ true, 'مرحبا بكم', 'بكم', - 5 - ] + 5, + ], ]; } } diff --git a/tests/unit/Str/Byte/EndsWithCiTest.php b/tests/unit/Str/Byte/EndsWithCiTest.php index ccf80afe..854ae01b 100644 --- a/tests/unit/Str/Byte/EndsWithCiTest.php +++ b/tests/unit/Str/Byte/EndsWithCiTest.php @@ -21,15 +21,15 @@ public function provideData(): array { return [ [true, 'Hello', 'Hello'], - [false, 'Hello, WorlḐ', 'worlḑ', ], - [true, 'Hello, Worlḑ', 'worlḑ', ], - [false, 'T U N I S I A', 'e', ], + [false, 'Hello, WorlḐ', 'worlḑ'], + [true, 'Hello, Worlḑ', 'worlḑ'], + [false, 'T U N I S I A', 'e'], [true, 'تونس', 'س'], - [false, 'Hello, World', '', ], - [false, 'hello, world', 'hey', ], + [false, 'Hello, World', ''], + [false, 'hello, world', 'hey'], [false, 'hello, worlḑ', 'hello cruel worḑ'], - [true, 'azjezz', 'z', ], - [true, 'مرحبا بكم', 'بكم', ], + [true, 'azjezz', 'z'], + [true, 'مرحبا بكم', 'بكم'], ]; } } diff --git a/tests/unit/Str/Byte/EndsWithTest.php b/tests/unit/Str/Byte/EndsWithTest.php index ee4459ad..a133ad93 100644 --- a/tests/unit/Str/Byte/EndsWithTest.php +++ b/tests/unit/Str/Byte/EndsWithTest.php @@ -21,15 +21,15 @@ public function provideData(): array { return [ [true, 'Hello', 'Hello'], - [false, 'Hello, WorlḐ', 'worlḑ', ], - [false, 'Hello, Worlḑ', 'worlḑ', ], - [false, 'T U N I S I A', 'e', ], + [false, 'Hello, WorlḐ', 'worlḑ'], + [false, 'Hello, Worlḑ', 'worlḑ'], + [false, 'T U N I S I A', 'e'], [true, 'تونس', 'س'], - [false, 'Hello, World', '', ], - [false, 'hello, world', 'hey', ], + [false, 'Hello, World', ''], + [false, 'hello, world', 'hey'], [false, 'hello, worlḑ', 'hello cruel worḑ'], - [true, 'azjezz', 'z', ], - [true, 'مرحبا بكم', 'بكم', ], + [true, 'azjezz', 'z'], + [true, 'مرحبا بكم', 'بكم'], ]; } } diff --git a/tests/unit/Str/Byte/LengthTest.php b/tests/unit/Str/Byte/LengthTest.php index 5c40ba23..45937bec 100644 --- a/tests/unit/Str/Byte/LengthTest.php +++ b/tests/unit/Str/Byte/LengthTest.php @@ -27,7 +27,7 @@ public function provideData(): array [12, '🥇🥈🥉'], [6, '你好'], [18, 'สวัสดี'], - [6, 'ؤخى'] + [6, 'ؤخى'], ]; } } diff --git a/tests/unit/Str/Byte/RangeTest.php b/tests/unit/Str/Byte/RangeTest.php index 5c00af2e..2e1d6fc3 100644 --- a/tests/unit/Str/Byte/RangeTest.php +++ b/tests/unit/Str/Byte/RangeTest.php @@ -31,8 +31,16 @@ public function provideData(): array ['Hello, World!', 'Hello, World!', Range\from(0)], ['World!', 'Hello, World!', Range\between(7, 12, upper_inclusive: true)], ['World', 'Hello, World!', Range\between(7, 12, upper_inclusive: false)], - ['destiny', 'People linked by destiny will always find each other.', Range\between(17, 23, upper_inclusive: true)], - ['destiny', 'People linked by destiny will always find each other.', Range\between(17, 24, upper_inclusive: false)], + [ + 'destiny', + 'People linked by destiny will always find each other.', + Range\between(17, 23, upper_inclusive: true), + ], + [ + 'destiny', + 'People linked by destiny will always find each other.', + Range\between(17, 24, upper_inclusive: false), + ], ['hel', 'hello world', Range\to(3, inclusive: false)], ['', 'lo world', Range\between(3, 3)], ['', 'foo', Range\between(3, 3)], diff --git a/tests/unit/Str/Byte/ReplaceCiTest.php b/tests/unit/Str/Byte/ReplaceCiTest.php index 68565153..4136d0ac 100644 --- a/tests/unit/Str/Byte/ReplaceCiTest.php +++ b/tests/unit/Str/Byte/ReplaceCiTest.php @@ -20,8 +20,8 @@ public function testReplaceCi(string $expected, string $haystack, string $needle public function provideData(): array { return [ - ['Hello, World!', 'Hello, you!', 'You', 'World', ], - ['Hello, World!', 'Hello, You!', 'You', 'World', ], + ['Hello, World!', 'Hello, you!', 'You', 'World'], + ['Hello, World!', 'Hello, You!', 'You', 'World'], ['مرحبا بكم', 'مرحبا سيف', 'سيف', 'بكم'], ['foo', 'foo', 'bar', 'baz'], ]; diff --git a/tests/unit/Str/Byte/ReplaceEveryCiTest.php b/tests/unit/Str/Byte/ReplaceEveryCiTest.php index cd34921e..5de052f2 100644 --- a/tests/unit/Str/Byte/ReplaceEveryCiTest.php +++ b/tests/unit/Str/Byte/ReplaceEveryCiTest.php @@ -40,14 +40,14 @@ public function provideData(): array 'مرحبا سيف', [ 'سيف' => 'بكم', - 'مرحبا' => 'اهلا' + 'مرحبا' => 'اهلا', ], ], [ 'Foo', 'Foo', - ['bar' => 'baz'] - ] + ['bar' => 'baz'], + ], ]; } } diff --git a/tests/unit/Str/Byte/ReplaceEveryTest.php b/tests/unit/Str/Byte/ReplaceEveryTest.php index 6667b622..c5275571 100644 --- a/tests/unit/Str/Byte/ReplaceEveryTest.php +++ b/tests/unit/Str/Byte/ReplaceEveryTest.php @@ -43,8 +43,8 @@ public function provideData(): array [ 'Foo', 'Foo', - ['bar' => 'baz'] - ] + ['bar' => 'baz'], + ], ]; } } diff --git a/tests/unit/Str/Byte/ReplaceTest.php b/tests/unit/Str/Byte/ReplaceTest.php index 955be714..61ab8cfb 100644 --- a/tests/unit/Str/Byte/ReplaceTest.php +++ b/tests/unit/Str/Byte/ReplaceTest.php @@ -20,8 +20,8 @@ public function testReplace(string $expected, string $haystack, string $needle, public function provideData(): array { return [ - ['Hello, you!', 'Hello, you!', 'You', 'World', ], - ['Hello, World!', 'Hello, You!', 'You', 'World', ], + ['Hello, you!', 'Hello, you!', 'You', 'World'], + ['Hello, World!', 'Hello, You!', 'You', 'World'], ['مرحبا بكم', 'مرحبا سيف', 'سيف', 'بكم'], ['foo', 'foo', 'bar', 'baz'], ]; diff --git a/tests/unit/Str/Byte/SearchCiTest.php b/tests/unit/Str/Byte/SearchCiTest.php index 79fc3fdd..e728d3a5 100644 --- a/tests/unit/Str/Byte/SearchCiTest.php +++ b/tests/unit/Str/Byte/SearchCiTest.php @@ -12,7 +12,7 @@ final class SearchCiTest extends TestCase /** * @dataProvider provideData */ - public function testSearchCi(?int $expected, string $haystack, string $needle, int $offset = 0): void + public function testSearchCi(null|int $expected, string $haystack, string $needle, int $offset = 0): void { static::assertSame($expected, Byte\search_ci($haystack, $needle, $offset)); } @@ -20,10 +20,10 @@ public function testSearchCi(?int $expected, string $haystack, string $needle, i public function provideData(): array { return [ - [7, 'Hello, you!', 'You', ], - [7, 'Hello, You!', 'You', ], - [0, 'Ho! Ho! Ho!', 'ho', ], - [0, 'Ho! Ho! Ho!', 'Ho', ], + [7, 'Hello, you!', 'You'], + [7, 'Hello, You!', 'You'], + [0, 'Ho! Ho! Ho!', 'ho'], + [0, 'Ho! Ho! Ho!', 'Ho'], [7, 'Hello, You!', 'You', 5], [null, 'Hello, World!', 'You', 5], [null, 'foo', 'bar', 2], diff --git a/tests/unit/Str/Byte/SearchLastTest.php b/tests/unit/Str/Byte/SearchLastTest.php index 945e7cb9..5d0f33c5 100644 --- a/tests/unit/Str/Byte/SearchLastTest.php +++ b/tests/unit/Str/Byte/SearchLastTest.php @@ -12,7 +12,7 @@ final class SearchLastTest extends TestCase /** * @dataProvider provideData */ - public function testSearchLast(?int $expected, string $haystack, string $needle, int $offset = 0): void + public function testSearchLast(null|int $expected, string $haystack, string $needle, int $offset = 0): void { static::assertSame($expected, Byte\search_last($haystack, $needle, $offset)); } @@ -20,10 +20,10 @@ public function testSearchLast(?int $expected, string $haystack, string $needle, public function provideData(): array { return [ - [null, 'Hello, you!', 'You', ], - [7, 'Hello, You!', 'You', ], - [null, 'Ho! Ho! Ho!', 'ho', ], - [8, 'Ho! Ho! Ho!', 'Ho', ], + [null, 'Hello, you!', 'You'], + [7, 'Hello, You!', 'You'], + [null, 'Ho! Ho! Ho!', 'ho'], + [8, 'Ho! Ho! Ho!', 'Ho'], [7, 'Hello, You!', 'You', 5], [null, 'Hello, World!', 'You', 5], [null, 'foo', 'bar', 2], diff --git a/tests/unit/Str/Byte/SearchTest.php b/tests/unit/Str/Byte/SearchTest.php index da4eab75..7d63c3d1 100644 --- a/tests/unit/Str/Byte/SearchTest.php +++ b/tests/unit/Str/Byte/SearchTest.php @@ -12,7 +12,7 @@ final class SearchTest extends TestCase /** * @dataProvider provideData */ - public function testSearch(?int $expected, string $haystack, string $needle, int $offset = 0): void + public function testSearch(null|int $expected, string $haystack, string $needle, int $offset = 0): void { static::assertSame($expected, Byte\search($haystack, $needle, $offset)); } @@ -20,10 +20,10 @@ public function testSearch(?int $expected, string $haystack, string $needle, int public function provideData(): array { return [ - [null, 'Hello, you!', 'You', ], - [7, 'Hello, You!', 'You', ], - [null, 'Ho! Ho! Ho!', 'ho', ], - [0, 'Ho! Ho! Ho!', 'Ho', ], + [null, 'Hello, you!', 'You'], + [7, 'Hello, You!', 'You'], + [null, 'Ho! Ho! Ho!', 'ho'], + [0, 'Ho! Ho! Ho!', 'Ho'], [7, 'Hello, You!', 'You', 5], [null, 'Hello, World!', 'You', 5], [null, 'foo', 'bar', 2], diff --git a/tests/unit/Str/Byte/SliceTest.php b/tests/unit/Str/Byte/SliceTest.php index 348f34c6..a3aa5c39 100644 --- a/tests/unit/Str/Byte/SliceTest.php +++ b/tests/unit/Str/Byte/SliceTest.php @@ -13,7 +13,7 @@ final class SliceTest extends TestCase /** * @dataProvider provideData */ - public function testSlice(string $expected, string $string, int $offset, ?int $length = null): void + public function testSlice(string $expected, string $string, int $offset, null|int $length = null): void { static::assertSame($expected, Byte\slice($string, $offset, $length)); } @@ -21,7 +21,7 @@ public function testSlice(string $expected, string $string, int $offset, ?int $l public function provideData(): array { return [ - ['', '', 0, 0, ], + ['', '', 0, 0], ['Hello', 'Hello, World!', 0, 5], ['Hello, World!', 'Hello, World!', 0], ['World', 'Hello, World!', 7, 5], diff --git a/tests/unit/Str/Byte/SpliceTest.php b/tests/unit/Str/Byte/SpliceTest.php index 971b83c2..6399776c 100644 --- a/tests/unit/Str/Byte/SpliceTest.php +++ b/tests/unit/Str/Byte/SpliceTest.php @@ -17,7 +17,7 @@ public function testSplice( string $string, string $replacement, int $offset, - ?int $length = null + null|int $length = null, ): void { static::assertSame($expected, Byte\splice($string, $replacement, $offset, $length)); } @@ -25,20 +25,20 @@ public function testSplice( public function provideData(): array { return [ - ['', '', '', 0, null, ], - ['hello darkness', 'hello world', 'darkness', 6, null, ], + ['', '', '', 0, null], + ['hello darkness', 'hello world', 'darkness', 6, null], ['hello cruel world', 'hello world', ' cruel ', 5, 1], - ['hello cruel world', 'hello world', ' cruel ', -6, 1, ], - ['hello cruel world', 'hello world', ' cruel', 5, 0, ], - ['hello darkness', 'hello ', 'darkness', 6, null, ], - ['hello darkness', 'hello world', 'darkness', 6, 100, ], - ['hello darkness', 'hello world', 'darkness', 6, 11, ], + ['hello cruel world', 'hello world', ' cruel ', -6, 1], + ['hello cruel world', 'hello world', ' cruel', 5, 0], + ['hello darkness', 'hello ', 'darkness', 6, null], + ['hello darkness', 'hello world', 'darkness', 6, 100], + ['hello darkness', 'hello world', 'darkness', 6, 11], [ 'People linked by destiny will always find each other.', 'People linked by destiny will find each other.', ' always ', 29, - 1 + 1, ], ]; } diff --git a/tests/unit/Str/Byte/SplitTest.php b/tests/unit/Str/Byte/SplitTest.php index ebfa4628..2b06caff 100644 --- a/tests/unit/Str/Byte/SplitTest.php +++ b/tests/unit/Str/Byte/SplitTest.php @@ -12,7 +12,7 @@ final class SplitTest extends TestCase /** * @dataProvider provideData */ - public function testSplit(array $expected, string $string, string $delimiter, ?int $length = null): void + public function testSplit(array $expected, string $string, string $delimiter, null|int $length = null): void { static::assertSame($expected, Byte\split($string, $delimiter, $length)); } diff --git a/tests/unit/Str/Byte/StartsWithCiTest.php b/tests/unit/Str/Byte/StartsWithCiTest.php index 42d1d9d6..640139fe 100644 --- a/tests/unit/Str/Byte/StartsWithCiTest.php +++ b/tests/unit/Str/Byte/StartsWithCiTest.php @@ -20,22 +20,22 @@ public function testStartsWithCi(bool $expected, string $haystack, string $prefi public function provideData(): array { return [ - [true, 'Hello, World', 'Hello', ], - [false, 'Hello, World', 'world', ], - [false, 'Hello, World', '', ], - [false, 'hello, world', 'hey', ], - [true, 'azjezz', 'az', ], - [true, 'azjezz', 'Az', ], - [false, 'مرحبا بكم', 'بكم', ], - [true, 'مرحبا بكم', 'مرحبا', ], + [true, 'Hello, World', 'Hello'], + [false, 'Hello, World', 'world'], + [false, 'Hello, World', ''], + [false, 'hello, world', 'hey'], + [true, 'azjezz', 'az'], + [true, 'azjezz', 'Az'], + [false, 'مرحبا بكم', 'بكم'], + [true, 'مرحبا بكم', 'مرحبا'], [true, 'مرحبا سيف', 'مرحبا', 3], [false, 'مرحبا سيف', 'سيف', 3], [true, 'اهلا بكم', 'اهلا', 2], - [true, 'héllö wôrld', 'héllö', ], - [false, 'héllö wôrld', 'hello', ], - [true, 'fôo', 'fôo', ], - [true, 'fôo', 'f', ], - [true, 'fôo', 'fô', ], + [true, 'héllö wôrld', 'héllö'], + [false, 'héllö wôrld', 'hello'], + [true, 'fôo', 'fôo'], + [true, 'fôo', 'f'], + [true, 'fôo', 'fô'], ]; } } diff --git a/tests/unit/Str/Byte/StartsWithTest.php b/tests/unit/Str/Byte/StartsWithTest.php index e0e9921e..7400de5e 100644 --- a/tests/unit/Str/Byte/StartsWithTest.php +++ b/tests/unit/Str/Byte/StartsWithTest.php @@ -20,22 +20,22 @@ public function testStartsWith(bool $expected, string $haystack, string $prefix) public function provideData(): array { return [ - [true, 'Hello, World', 'Hello', ], - [false, 'Hello, World', 'world', ], - [false, 'Hello, World', '', ], - [false, 'hello, world', 'hey', ], - [true, 'azjezz', 'az', ], - [false, 'azjezz', 'Az', ], - [false, 'مرحبا بكم', 'بكم', ], - [true, 'مرحبا بكم', 'مرحبا', ], + [true, 'Hello, World', 'Hello'], + [false, 'Hello, World', 'world'], + [false, 'Hello, World', ''], + [false, 'hello, world', 'hey'], + [true, 'azjezz', 'az'], + [false, 'azjezz', 'Az'], + [false, 'مرحبا بكم', 'بكم'], + [true, 'مرحبا بكم', 'مرحبا'], [true, 'مرحبا سيف', 'مرحبا', 3], [false, 'مرحبا سيف', 'سيف', 3], [true, 'اهلا بكم', 'اهلا', 2], - [true, 'héllö wôrld', 'héllö', ], - [false, 'héllö wôrld', 'hello', ], - [true, 'fôo', 'fôo', ], - [true, 'fôo', 'f', ], - [true, 'fôo', 'fô', ], + [true, 'héllö wôrld', 'héllö'], + [false, 'héllö wôrld', 'hello'], + [true, 'fôo', 'fôo'], + [true, 'fôo', 'f'], + [true, 'fôo', 'fô'], ]; } } diff --git a/tests/unit/Str/Byte/StripSuffixTest.php b/tests/unit/Str/Byte/StripSuffixTest.php index b5e523fd..0c1c1415 100644 --- a/tests/unit/Str/Byte/StripSuffixTest.php +++ b/tests/unit/Str/Byte/StripSuffixTest.php @@ -21,27 +21,27 @@ public function provideData(): array { return [ ['', 'Hello', 'Hello'], - ['Hello, World', 'Hello, World', 'world', ], - ['T U N I S I A', 'T U N I S I A', 'e', ], + ['Hello, World', 'Hello, World', 'world'], + ['T U N I S I A', 'T U N I S I A', 'e'], ['تون', 'تونس', 'س'], - ['Hello, World', 'Hello, World', '', ], - ['Hello, World', 'Hello, World', 'Hello, cruel world!', ], - ['hello, world', 'hello, world', 'hey', ], - ['azjez', 'azjezz', 'z', ], - ['مرحبا ', 'مرحبا بكم', 'بكم', ], - ['Hello', 'Hello, World', ', World', ], - ['Hello, World', 'Hello, World', 'world', ], - ['Hello, World', 'Hello, World', '', ], - ['hello, world', 'hello, world', 'universe', ], - ['azje', 'azjezz', 'zz', ], - ['azjezz', 'azjezz', 'ZZ', ], + ['Hello, World', 'Hello, World', ''], + ['Hello, World', 'Hello, World', 'Hello, cruel world!'], + ['hello, world', 'hello, world', 'hey'], + ['azjez', 'azjezz', 'z'], + ['مرحبا ', 'مرحبا بكم', 'بكم'], + ['Hello', 'Hello, World', ', World'], + ['Hello, World', 'Hello, World', 'world'], + ['Hello, World', 'Hello, World', ''], + ['hello, world', 'hello, world', 'universe'], + ['azje', 'azjezz', 'zz'], + ['azjezz', 'azjezz', 'ZZ'], ['مرحبا', 'مرحبا سيف', ' سيف', 3], ['اهلا', 'اهلا بكم', ' بكم', 3], - ['héllö', 'héllö wôrld', ' wôrld', ], - ['héllö wôrld', 'héllö wôrld', ' world', ], - ['fô', 'fôo', 'o', ], - ['fôo', 'fôo', 'ô', ], - ['f', 'fôo', 'ôo', ], + ['héllö', 'héllö wôrld', ' wôrld'], + ['héllö wôrld', 'héllö wôrld', ' world'], + ['fô', 'fôo', 'o'], + ['fôo', 'fôo', 'ô'], + ['f', 'fôo', 'ôo'], ]; } } diff --git a/tests/unit/Str/Byte/TrimLeftTest.php b/tests/unit/Str/Byte/TrimLeftTest.php index 8ebd920a..0fadaff6 100644 --- a/tests/unit/Str/Byte/TrimLeftTest.php +++ b/tests/unit/Str/Byte/TrimLeftTest.php @@ -12,7 +12,7 @@ final class TrimLeftTest extends TestCase /** * @dataProvider provideData */ - public function testTrimLeft(string $expected, string $string, ?string $chars = null): void + public function testTrimLeft(string $expected, string $string, null|string $chars = null): void { static::assertSame($expected, Byte\trim_left($string, $chars)); } diff --git a/tests/unit/Str/Byte/TrimRightTest.php b/tests/unit/Str/Byte/TrimRightTest.php index 694dceba..39f332d3 100644 --- a/tests/unit/Str/Byte/TrimRightTest.php +++ b/tests/unit/Str/Byte/TrimRightTest.php @@ -12,7 +12,7 @@ final class TrimRightTest extends TestCase /** * @dataProvider provideData */ - public function testTrimRight(string $expected, string $string, ?string $chars = null): void + public function testTrimRight(string $expected, string $string, null|string $chars = null): void { static::assertSame($expected, Byte\trim_right($string, $chars)); } diff --git a/tests/unit/Str/Byte/TrimTest.php b/tests/unit/Str/Byte/TrimTest.php index 0d185f60..b79404ed 100644 --- a/tests/unit/Str/Byte/TrimTest.php +++ b/tests/unit/Str/Byte/TrimTest.php @@ -12,7 +12,7 @@ final class TrimTest extends TestCase /** * @dataProvider provideData */ - public function testTrim(string $expected, string $string, ?string $chars = null): void + public function testTrim(string $expected, string $string, null|string $chars = null): void { static::assertSame($expected, Byte\trim($string, $chars)); } @@ -41,7 +41,7 @@ public function provideData(): array " \n!", ], [ - "Héllö World", + 'Héllö World', " Héllö World\t!!!\n", " \n!\t", ], diff --git a/tests/unit/Str/Byte/WordsTest.php b/tests/unit/Str/Byte/WordsTest.php index 007ca779..22ba749e 100644 --- a/tests/unit/Str/Byte/WordsTest.php +++ b/tests/unit/Str/Byte/WordsTest.php @@ -12,7 +12,7 @@ final class WordsTest extends TestCase /** * @dataProvider provideData */ - public function testWords(array $expected, string $string, ?string $extra_chars = null): void + public function testWords(array $expected, string $string, null|string $extra_chars = null): void { static::assertSame($expected, Byte\words($string, $extra_chars)); } diff --git a/tests/unit/Str/Byte/WrapTest.php b/tests/unit/Str/Byte/WrapTest.php index 98c16c01..d89f6d9c 100644 --- a/tests/unit/Str/Byte/WrapTest.php +++ b/tests/unit/Str/Byte/WrapTest.php @@ -17,7 +17,7 @@ public function testWrap( string $str, int $width = 75, string $break = "\n", - bool $cut = false + bool $cut = false, ): void { static::assertSame($expected, Byte\wrap($str, $width, $break, $cut)); } diff --git a/tests/unit/Str/CapitalizeTest.php b/tests/unit/Str/CapitalizeTest.php index 004ed0c7..e850b907 100644 --- a/tests/unit/Str/CapitalizeTest.php +++ b/tests/unit/Str/CapitalizeTest.php @@ -21,9 +21,9 @@ public function provideData(): array { return [ ['', ''], - ['Hello', 'hello', ], + ['Hello', 'hello'], ['Hello, world', 'hello, world'], - ['Alpha', 'Alpha', ], + ['Alpha', 'Alpha'], ['مرحبا بكم', 'مرحبا بكم'], ['Héllö, wôrld!', 'héllö, wôrld!'], ['Ḫéllö, wôrld!', 'ḫéllö, wôrld!'], @@ -34,7 +34,7 @@ public function provideData(): array ['你好', '你好'], ['こんにちは世界', 'こんにちは世界'], ['สวัสดี', 'สวัสดี'], - ['ؤخى', 'ؤخى'] + ['ؤخى', 'ؤخى'], ]; } } diff --git a/tests/unit/Str/CapitalizeWordsTest.php b/tests/unit/Str/CapitalizeWordsTest.php index ad4e1b9b..6f0d1c7f 100644 --- a/tests/unit/Str/CapitalizeWordsTest.php +++ b/tests/unit/Str/CapitalizeWordsTest.php @@ -20,12 +20,12 @@ public function testCapitalizeWords(string $expected, string $value): void public function provideData(): array { return [ - ['Hello', 'hello', ], + ['Hello', 'hello'], ['Hello, World', 'hello, world'], ['Ḫello, Ꝡorld', 'ḫello, ꝡorld'], - ['Alpha', 'Alpha', ], - ['مرحبا بكم', 'مرحبا بكم', ], - ['Foo, Bar, And Baz', 'foo, bar, and baz'] + ['Alpha', 'Alpha'], + ['مرحبا بكم', 'مرحبا بكم'], + ['Foo, Bar, And Baz', 'foo, bar, and baz'], ]; } } diff --git a/tests/unit/Str/ChrTest.php b/tests/unit/Str/ChrTest.php index c44d2728..cdf71937 100644 --- a/tests/unit/Str/ChrTest.php +++ b/tests/unit/Str/ChrTest.php @@ -24,7 +24,7 @@ public function provideData(): array ['0', 48], ['&', 38], ['ا', 1575], - ['A', 65] + ['A', 65], ]; } } diff --git a/tests/unit/Str/ChunkTest.php b/tests/unit/Str/ChunkTest.php index cbc7b499..8d19cbd2 100644 --- a/tests/unit/Str/ChunkTest.php +++ b/tests/unit/Str/ChunkTest.php @@ -20,11 +20,11 @@ public function testCapitalize(array $expected, string $value, int $chunk_size = public function provideData(): array { return [ - [['h', 'e', 'l', 'l', 'o'], 'hello', ], - [['h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd'], 'hello, world', ], - [['Al', 'ph', 'a ', ' '], 'Alpha ', 2, ], - [['م', 'ر', 'ح', 'ب', 'ا', ' ', 'ب', 'ك', 'م'], 'مرحبا بكم', ], - [['مرحبا بكم'], 'مرحبا بكم', 9, ], + [['h', 'e', 'l', 'l', 'o'], 'hello'], + [['h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd'], 'hello, world'], + [['Al', 'ph', 'a ', ' '], 'Alpha ', 2], + [['م', 'ر', 'ح', 'ب', 'ا', ' ', 'ب', 'ك', 'م'], 'مرحبا بكم'], + [['مرحبا بكم'], 'مرحبا بكم', 9], [[], ''], ]; } diff --git a/tests/unit/Str/ContainsTest.php b/tests/unit/Str/ContainsTest.php index a3329b9d..c163d3a5 100644 --- a/tests/unit/Str/ContainsTest.php +++ b/tests/unit/Str/ContainsTest.php @@ -24,49 +24,44 @@ public function provideData(): array true, 'Hello, World', 'Hello', - 0 + 0, ], - [ false, 'Hello, World', 'world', - 0 + 0, ], - [ true, 'Hello, World', '', - 8 + 8, ], - [ false, 'hello, world', 'hey', - 5 + 5, ], - [ true, 'azjezz', 'az', - 0 + 0, ], [ false, 'azjezz', 'Az', - 2 + 2, ], - [ true, 'مرحبا بكم', 'بكم', - 5 - ] + 5, + ], ]; } } diff --git a/tests/unit/Str/ConvertEncodingTest.php b/tests/unit/Str/ConvertEncodingTest.php index 9f2b3a62..73b57ae6 100644 --- a/tests/unit/Str/ConvertEncodingTest.php +++ b/tests/unit/Str/ConvertEncodingTest.php @@ -13,18 +13,16 @@ final class ConvertEncodingTest extends TestCase * @dataProvider provideData */ public function testConvertEncoding( - ?string $expected, + null|string $expected, string $string, Str\Encoding $from_encoding, - Str\Encoding $to_encoding + Str\Encoding $to_encoding, ): void { static::assertSame($expected, Str\convert_encoding($string, $from_encoding, $to_encoding)); } public function provideData(): array { - return [ - ['åäö', 'åäö', Str\Encoding::Iso88591, Str\Encoding::Utf8], - ]; + return [['åäö', 'åäö', Str\Encoding::Iso88591, Str\Encoding::Utf8]]; } } diff --git a/tests/unit/Str/DetectEncodingTest.php b/tests/unit/Str/DetectEncodingTest.php index 49391a15..0caee145 100644 --- a/tests/unit/Str/DetectEncodingTest.php +++ b/tests/unit/Str/DetectEncodingTest.php @@ -12,7 +12,7 @@ final class DetectEncodingTest extends TestCase /** * @dataProvider provideData */ - public function testDetectEncoding(?Str\Encoding $expected, string $string): void + public function testDetectEncoding(null|Str\Encoding $expected, string $string): void { static::assertSame($expected, Str\detect_encoding($string)); } @@ -23,7 +23,7 @@ public function provideData(): array [Str\Encoding::Ascii, 'hello'], [Str\Encoding::Utf8, 'سيف'], [Str\Encoding::Utf8, '🐘'], - [null, Str\Byte\chr(128)] + [null, Str\Byte\chr(128)], ]; } } diff --git a/tests/unit/Str/EndsWithCiTest.php b/tests/unit/Str/EndsWithCiTest.php index d0c67c57..ede9cc24 100644 --- a/tests/unit/Str/EndsWithCiTest.php +++ b/tests/unit/Str/EndsWithCiTest.php @@ -25,15 +25,15 @@ public function provideData(): array { return [ [true, 'Hello', 'Hello'], - [true, 'Hello, World', 'world', ], - [true, 'Hello, WorlḐ', 'worlḑ', ], - [false, 'T U N I S I A', 'e', ], + [true, 'Hello, World', 'world'], + [true, 'Hello, WorlḐ', 'worlḑ'], + [false, 'T U N I S I A', 'e'], [true, 'تونس', 'س'], - [false, 'Hello, World', '', ], - [false, 'hello, world', 'hey', ], + [false, 'Hello, World', ''], + [false, 'hello, world', 'hey'], [false, 'hello, world', 'hello cruel world'], - [true, 'azjezz', 'z', ], - [true, 'مرحبا بكم', 'بكم', ], + [true, 'azjezz', 'z'], + [true, 'مرحبا بكم', 'بكم'], ]; } } diff --git a/tests/unit/Str/EndsWithTest.php b/tests/unit/Str/EndsWithTest.php index b79448ee..54f8934d 100644 --- a/tests/unit/Str/EndsWithTest.php +++ b/tests/unit/Str/EndsWithTest.php @@ -21,14 +21,14 @@ public function provideData(): array { return [ [true, 'Hello', 'Hello'], - [false, 'Hello, World', 'world', ], - [false, 'T U N I S I A', 'e', ], + [false, 'Hello, World', 'world'], + [false, 'T U N I S I A', 'e'], [true, 'تونس', 'س'], - [false, 'Hello, World', '', ], - [false, 'Hello, World', 'Hello, cruel world!', ], - [false, 'hello, world', 'hey', ], - [true, 'azjezz', 'z', ], - [true, 'مرحبا بكم', 'بكم', ], + [false, 'Hello, World', ''], + [false, 'Hello, World', 'Hello, cruel world!'], + [false, 'hello, world', 'hey'], + [true, 'azjezz', 'z'], + [true, 'مرحبا بكم', 'بكم'], ]; } } diff --git a/tests/unit/Str/FromCodePointsTest.php b/tests/unit/Str/FromCodePointsTest.php index bd0c09cd..f26e8f83 100644 --- a/tests/unit/Str/FromCodePointsTest.php +++ b/tests/unit/Str/FromCodePointsTest.php @@ -13,7 +13,10 @@ public function testFromCodePoints(): void { static::assertSame(/* NULL = */ Str\chr(0), Str\from_code_points(0)); - static::assertSame('مرحبا بكم', Str\from_code_points(1605, 1585, 1581, 1576, 1575, 32, 1576, 1603, 1605)); + static::assertSame( + 'مرحبا بكم', + Str\from_code_points(1605, 1585, 1581, 1576, 1575, 32, 1576, 1603, 1605), + ); static::assertSame('Hello', Str\from_code_points(72, 101, 108, 108, 111)); diff --git a/tests/unit/Str/Grapheme/AfterCiTest.php b/tests/unit/Str/Grapheme/AfterCiTest.php index 1c7ed98c..2bc9fb63 100644 --- a/tests/unit/Str/Grapheme/AfterCiTest.php +++ b/tests/unit/Str/Grapheme/AfterCiTest.php @@ -12,19 +12,15 @@ final class AfterCiTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Grapheme\after_ci($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['orld!', 'Hello, World!', 'W', 0], ['!', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/Grapheme/AfterLastCiTest.php b/tests/unit/Str/Grapheme/AfterLastCiTest.php index f2de9df2..bc0072cb 100644 --- a/tests/unit/Str/Grapheme/AfterLastCiTest.php +++ b/tests/unit/Str/Grapheme/AfterLastCiTest.php @@ -12,19 +12,15 @@ final class AfterLastCiTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Grapheme\after_last_ci($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['orld!', 'Hello, World!', 'W', 0], ['!', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/Grapheme/AfterLastTest.php b/tests/unit/Str/Grapheme/AfterLastTest.php index fc6eb1c6..7dee5ebf 100644 --- a/tests/unit/Str/Grapheme/AfterLastTest.php +++ b/tests/unit/Str/Grapheme/AfterLastTest.php @@ -12,19 +12,15 @@ final class AfterLastTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Grapheme\after_last($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['orld!', 'Hello, World!', 'W', 0], ['!', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/Grapheme/AfterTest.php b/tests/unit/Str/Grapheme/AfterTest.php index f5338b42..b2c3f3a0 100644 --- a/tests/unit/Str/Grapheme/AfterTest.php +++ b/tests/unit/Str/Grapheme/AfterTest.php @@ -12,20 +12,15 @@ final class AfterTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Grapheme\after($haystack, $needle, $offset)); } - public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['orld!', 'Hello, World!', 'W', 0], ['!', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/Grapheme/BeforeCiTest.php b/tests/unit/Str/Grapheme/BeforeCiTest.php index ac57e40a..b5dc7147 100644 --- a/tests/unit/Str/Grapheme/BeforeCiTest.php +++ b/tests/unit/Str/Grapheme/BeforeCiTest.php @@ -12,19 +12,15 @@ final class BeforeCiTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Grapheme\before_ci($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['Hello, ', 'Hello, World!', 'W', 0], ['', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/Grapheme/BeforeLastCiTest.php b/tests/unit/Str/Grapheme/BeforeLastCiTest.php index 658f3d53..7c7110df 100644 --- a/tests/unit/Str/Grapheme/BeforeLastCiTest.php +++ b/tests/unit/Str/Grapheme/BeforeLastCiTest.php @@ -12,19 +12,15 @@ final class BeforeLastCiTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Grapheme\before_last_ci($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['Hello, ', 'Hello, World!', 'W', 0], ['', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/Grapheme/BeforeLastTest.php b/tests/unit/Str/Grapheme/BeforeLastTest.php index 48cfa8f0..8a9a7703 100644 --- a/tests/unit/Str/Grapheme/BeforeLastTest.php +++ b/tests/unit/Str/Grapheme/BeforeLastTest.php @@ -12,19 +12,15 @@ final class BeforeLastTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Grapheme\before_last($haystack, $needle, $offset)); } public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['Hello, ', 'Hello, World!', 'W', 0], ['', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/Grapheme/BeforeTest.php b/tests/unit/Str/Grapheme/BeforeTest.php index 72c323b7..85093e45 100644 --- a/tests/unit/Str/Grapheme/BeforeTest.php +++ b/tests/unit/Str/Grapheme/BeforeTest.php @@ -12,20 +12,15 @@ final class BeforeTest extends TestCase /** * @dataProvider provideData */ - public function testAfter( - ?string $expected, - string $haystack, - string $needle, - int $offset - ): void { + public function testAfter(null|string $expected, string $haystack, string $needle, int $offset): void + { static::assertSame($expected, Grapheme\before($haystack, $needle, $offset)); } - public function provideData(): array { return [ - [null, '', '', 0], + [null, '', '', 0], ['Hello, ', 'Hello, World!', 'W', 0], ['', '🤷!', '🤷', 0], [null, 'مرحبا بكم', '', 0], diff --git a/tests/unit/Str/Grapheme/ContainsTest.php b/tests/unit/Str/Grapheme/ContainsTest.php index 8b6789fc..92380c7f 100644 --- a/tests/unit/Str/Grapheme/ContainsTest.php +++ b/tests/unit/Str/Grapheme/ContainsTest.php @@ -24,49 +24,44 @@ public function provideData(): array true, 'Hello, World', 'Hello', - 0 + 0, ], - [ false, 'Hello, World', 'world', - 0 + 0, ], - [ true, 'Hello, World', '', - 8 + 8, ], - [ false, 'hello, world', 'hey', - 5 + 5, ], - [ true, 'azjezz', 'az', - 0 + 0, ], [ false, 'azjezz', 'Az', - 2 + 2, ], - [ true, 'مرحبا بكم', 'بكم', - 5 - ] + 5, + ], ]; } } diff --git a/tests/unit/Str/Grapheme/EndsWithCiTest.php b/tests/unit/Str/Grapheme/EndsWithCiTest.php index 7fa5605d..8e0a0772 100644 --- a/tests/unit/Str/Grapheme/EndsWithCiTest.php +++ b/tests/unit/Str/Grapheme/EndsWithCiTest.php @@ -21,15 +21,15 @@ public function provideData(): array { return [ [true, 'Hello', 'Hello'], - [true, 'Hello, World', 'world', ], - [true, 'Hello, WorlḐ', 'worlḑ', ], - [false, 'T U N I S I A', 'e', ], + [true, 'Hello, World', 'world'], + [true, 'Hello, WorlḐ', 'worlḑ'], + [false, 'T U N I S I A', 'e'], [true, 'تونس', 'س'], - [false, 'Hello, World', '', ], - [false, 'hello, world', 'hey', ], + [false, 'Hello, World', ''], + [false, 'hello, world', 'hey'], [false, 'hello, world', 'hello cruel world'], - [true, 'azjezz', 'z', ], - [true, 'مرحبا بكم', 'بكم', ], + [true, 'azjezz', 'z'], + [true, 'مرحبا بكم', 'بكم'], ]; } } diff --git a/tests/unit/Str/Grapheme/EndsWithTest.php b/tests/unit/Str/Grapheme/EndsWithTest.php index eaa7fcfb..f01c18ec 100644 --- a/tests/unit/Str/Grapheme/EndsWithTest.php +++ b/tests/unit/Str/Grapheme/EndsWithTest.php @@ -21,14 +21,14 @@ public function provideData(): array { return [ [true, 'Hello', 'Hello'], - [false, 'Hello, World', 'world', ], - [false, 'T U N I S I A', 'e', ], + [false, 'Hello, World', 'world'], + [false, 'T U N I S I A', 'e'], [true, 'تونس', 'س'], - [false, 'Hello, World', '', ], - [false, 'Hello, World', 'Hello, cruel world!', ], - [false, 'hello, world', 'hey', ], - [true, 'azjezz', 'z', ], - [true, 'مرحبا بكم', 'بكم', ], + [false, 'Hello, World', ''], + [false, 'Hello, World', 'Hello, cruel world!'], + [false, 'hello, world', 'hey'], + [true, 'azjezz', 'z'], + [true, 'مرحبا بكم', 'بكم'], ]; } } diff --git a/tests/unit/Str/Grapheme/LengthTest.php b/tests/unit/Str/Grapheme/LengthTest.php index a8ec5ddb..c391fde0 100644 --- a/tests/unit/Str/Grapheme/LengthTest.php +++ b/tests/unit/Str/Grapheme/LengthTest.php @@ -27,7 +27,7 @@ public function provideData(): array [3, '🥇🥈🥉'], [2, '你好'], [4, 'สวัสดี'], - [3, 'ؤخى'] + [3, 'ؤخى'], ]; } } diff --git a/tests/unit/Str/Grapheme/RangeTest.php b/tests/unit/Str/Grapheme/RangeTest.php index f4b44e30..ed87ed1c 100644 --- a/tests/unit/Str/Grapheme/RangeTest.php +++ b/tests/unit/Str/Grapheme/RangeTest.php @@ -34,8 +34,16 @@ public function provideData(): array ['سيف', 'مرحبا سيف', Range\between(6, 9, upper_inclusive: true)], ['اهلا', 'اهلا بكم', Range\between(0, 3, upper_inclusive: true)], ['اهلا', 'اهلا بكم', Range\between(0, 4, upper_inclusive: false)], - ['destiny', 'People linked by destiny will always find each other.', Range\between(17, 23, upper_inclusive: true)], - ['destiny', 'People linked by destiny will always find each other.', Range\between(17, 24, upper_inclusive: false)], + [ + 'destiny', + 'People linked by destiny will always find each other.', + Range\between(17, 23, upper_inclusive: true), + ], + [ + 'destiny', + 'People linked by destiny will always find each other.', + Range\between(17, 24, upper_inclusive: false), + ], ['lö ', 'héllö wôrld', Range\between(3, 5, upper_inclusive: true)], ['lö ', 'héllö wôrld', Range\between(3, 6, upper_inclusive: false)], ['lö wôrld', 'héllö wôrld', Range\from(3)], @@ -45,7 +53,11 @@ public function provideData(): array ['', 'fôo', Range\between(3, 3)], ['', 'fôo', Range\between(3, 12)], ['fôo', 'fôo', Range\full()], - ['he̡̙̬͎̿́̐̅̕͢l͕̮͕͈̜͐̈́̇̕͠ļ͚͉̗̘̽͑̿͑̚o̼̰̼͕̞̍̄̎̿̊,̻̰̻̘́̎͒̋͘͟ ̧̬̝͈̬̿͌̿̑̕ẉ̣̟͉̮͆̊̃͐̈́ờ̢̫͎͖̹͊́͐r̨̮͓͓̣̅̋͐͐͆ḻ̩̦͚̯͑̌̓̅͒d͇̯͔̼͍͛̾͛͡͝', 'he̡̙̬͎̿́̐̅̕͢l͕̮͕͈̜͐̈́̇̕͠ļ͚͉̗̘̽͑̿͑̚o̼̰̼͕̞̍̄̎̿̊,̻̰̻̘́̎͒̋͘͟ ̧̬̝͈̬̿͌̿̑̕ẉ̣̟͉̮͆̊̃͐̈́ờ̢̫͎͖̹͊́͐r̨̮͓͓̣̅̋͐͐͆ḻ̩̦͚̯͑̌̓̅͒d͇̯͔̼͍͛̾͛͡͝', Range\between(0, 11, true)], + [ + 'he̡̙̬͎̿́̐̅̕͢l͕̮͕͈̜͐̈́̇̕͠ļ͚͉̗̘̽͑̿͑̚o̼̰̼͕̞̍̄̎̿̊,̻̰̻̘́̎͒̋͘͟ ̧̬̝͈̬̿͌̿̑̕ẉ̣̟͉̮͆̊̃͐̈́ờ̢̫͎͖̹͊́͐r̨̮͓͓̣̅̋͐͐͆ḻ̩̦͚̯͑̌̓̅͒d͇̯͔̼͍͛̾͛͡͝', + 'he̡̙̬͎̿́̐̅̕͢l͕̮͕͈̜͐̈́̇̕͠ļ͚͉̗̘̽͑̿͑̚o̼̰̼͕̞̍̄̎̿̊,̻̰̻̘́̎͒̋͘͟ ̧̬̝͈̬̿͌̿̑̕ẉ̣̟͉̮͆̊̃͐̈́ờ̢̫͎͖̹͊́͐r̨̮͓͓̣̅̋͐͐͆ḻ̩̦͚̯͑̌̓̅͒d͇̯͔̼͍͛̾͛͡͝', + Range\between(0, 11, true), + ], ]; } diff --git a/tests/unit/Str/Grapheme/ReverseTest.php b/tests/unit/Str/Grapheme/ReverseTest.php index 42301f61..75bc3e71 100644 --- a/tests/unit/Str/Grapheme/ReverseTest.php +++ b/tests/unit/Str/Grapheme/ReverseTest.php @@ -15,8 +15,11 @@ public function provideData(): array { return [ ['Hello World 👩🏽‍❤️‍👨🏼', '👩🏽‍❤️‍👨🏼 dlroW olleH'], - ['👩‍👩‍👦👩🏽‍❤️‍👨🏼👩🏽‍🏫', '👩🏽‍🏫👩🏽‍❤️‍👨🏼👩‍👩‍👦'], - ['某物 🖖🏿', '🖖🏿 物某' ], + [ + '👩‍👩‍👦👩🏽‍❤️‍👨🏼👩🏽‍🏫', + '👩🏽‍🏫👩🏽‍❤️‍👨🏼👩‍👩‍👦', + ], + ['某物 🖖🏿', '🖖🏿 物某'], ['👲🏻 что-то', 'от-отч 👲🏻'], ['🙂👨🏼‍🎤😟', '😟👨🏼‍🎤🙂'], ['مرحبا👲🏻👨🏼‍🎤', '👨🏼‍🎤👲🏻ابحرم'], diff --git a/tests/unit/Str/Grapheme/SearchCiTest.php b/tests/unit/Str/Grapheme/SearchCiTest.php index c90fe590..297b410e 100644 --- a/tests/unit/Str/Grapheme/SearchCiTest.php +++ b/tests/unit/Str/Grapheme/SearchCiTest.php @@ -12,7 +12,7 @@ final class SearchCiTest extends TestCase /** * @dataProvider provideData */ - public function testSearchCi(?int $expected, string $haystack, string $needle, int $offset = 0): void + public function testSearchCi(null|int $expected, string $haystack, string $needle, int $offset = 0): void { static::assertSame($expected, Grapheme\search_ci($haystack, $needle, $offset)); } @@ -20,10 +20,10 @@ public function testSearchCi(?int $expected, string $haystack, string $needle, i public function provideData(): array { return [ - [7, 'Hello, you!', 'You', ], - [7, 'Hello, You!', 'You', ], - [0, 'Ho! Ho! Ho!', 'ho', ], - [0, 'Ho! Ho! Ho!', 'Ho', ], + [7, 'Hello, you!', 'You'], + [7, 'Hello, You!', 'You'], + [0, 'Ho! Ho! Ho!', 'ho'], + [0, 'Ho! Ho! Ho!', 'Ho'], [7, 'Hello, You!', 'You', 5], [null, 'Hello, World!', 'You', 5], [6, 'مرحبا سيف', 'سيف', 4], diff --git a/tests/unit/Str/Grapheme/SearchLastCiTest.php b/tests/unit/Str/Grapheme/SearchLastCiTest.php index 405aca89..e19465d8 100644 --- a/tests/unit/Str/Grapheme/SearchLastCiTest.php +++ b/tests/unit/Str/Grapheme/SearchLastCiTest.php @@ -12,7 +12,7 @@ final class SearchLastCiTest extends TestCase /** * @dataProvider provideData */ - public function testSearchLastCi(?int $expected, string $haystack, string $needle, int $offset = 0): void + public function testSearchLastCi(null|int $expected, string $haystack, string $needle, int $offset = 0): void { static::assertSame($expected, Grapheme\search_last_ci($haystack, $needle, $offset)); } @@ -20,10 +20,10 @@ public function testSearchLastCi(?int $expected, string $haystack, string $needl public function provideData(): array { return [ - [7, 'Hello, you!', 'You', ], - [7, 'Hello, You!', 'You', ], - [8, 'Ho! Ho! Ho!', 'ho', ], - [8, 'Ho! Ho! Ho!', 'Ho', ], + [7, 'Hello, you!', 'You'], + [7, 'Hello, You!', 'You'], + [8, 'Ho! Ho! Ho!', 'ho'], + [8, 'Ho! Ho! Ho!', 'Ho'], [7, 'Hello, You!', 'You', 5], [null, 'Hello, World!', 'You', 5], [6, 'مرحبا سيف', 'سيف', 4], diff --git a/tests/unit/Str/Grapheme/SearchLastTest.php b/tests/unit/Str/Grapheme/SearchLastTest.php index fac0544d..c9d6d0c6 100644 --- a/tests/unit/Str/Grapheme/SearchLastTest.php +++ b/tests/unit/Str/Grapheme/SearchLastTest.php @@ -12,7 +12,7 @@ final class SearchLastTest extends TestCase /** * @dataProvider provideData */ - public function testSearchLast(?int $expected, string $haystack, string $needle, int $offset = 0): void + public function testSearchLast(null|int $expected, string $haystack, string $needle, int $offset = 0): void { static::assertSame($expected, Grapheme\search_last($haystack, $needle, $offset)); } @@ -20,10 +20,10 @@ public function testSearchLast(?int $expected, string $haystack, string $needle, public function provideData(): array { return [ - [null, 'Hello, you!', 'You', ], - [7, 'Hello, You!', 'You', ], - [null, 'Ho! Ho! Ho!', 'ho', ], - [8, 'Ho! Ho! Ho!', 'Ho', ], + [null, 'Hello, you!', 'You'], + [7, 'Hello, You!', 'You'], + [null, 'Ho! Ho! Ho!', 'ho'], + [8, 'Ho! Ho! Ho!', 'Ho'], [7, 'Hello, You!', 'You', 5], [null, 'Hello, World!', 'You', 5], [6, 'مرحبا سيف', 'سيف', 4], diff --git a/tests/unit/Str/Grapheme/SearchTest.php b/tests/unit/Str/Grapheme/SearchTest.php index d52efc25..f0b31444 100644 --- a/tests/unit/Str/Grapheme/SearchTest.php +++ b/tests/unit/Str/Grapheme/SearchTest.php @@ -12,7 +12,7 @@ final class SearchTest extends TestCase /** * @dataProvider provideData */ - public function testSearch(?int $expected, string $haystack, string $needle, int $offset = 0): void + public function testSearch(null|int $expected, string $haystack, string $needle, int $offset = 0): void { static::assertSame($expected, Grapheme\search($haystack, $needle, $offset)); } @@ -20,10 +20,10 @@ public function testSearch(?int $expected, string $haystack, string $needle, int public function provideData(): array { return [ - [null, 'Hello, you!', 'You', ], - [7, 'Hello, You!', 'You', ], - [null, 'Ho! Ho! Ho!', 'ho', ], - [0, 'Ho! Ho! Ho!', 'Ho', ], + [null, 'Hello, you!', 'You'], + [7, 'Hello, You!', 'You'], + [null, 'Ho! Ho! Ho!', 'ho'], + [0, 'Ho! Ho! Ho!', 'Ho'], [7, 'Hello, You!', 'You', 5], [null, 'Hello, World!', 'You', 5], [6, 'مرحبا سيف', 'سيف', 4], diff --git a/tests/unit/Str/Grapheme/SliceTest.php b/tests/unit/Str/Grapheme/SliceTest.php index c5b1ea2b..206fb8a5 100644 --- a/tests/unit/Str/Grapheme/SliceTest.php +++ b/tests/unit/Str/Grapheme/SliceTest.php @@ -13,7 +13,7 @@ final class SliceTest extends TestCase /** * @dataProvider provideData */ - public function testSlice(string $expected, string $string, int $offset, ?int $length = null): void + public function testSlice(string $expected, string $string, int $offset, null|int $length = null): void { static::assertSame($expected, Grapheme\slice($string, $offset, $length)); } @@ -21,21 +21,21 @@ public function testSlice(string $expected, string $string, int $offset, ?int $l public function provideData(): array { return [ - ['', '', 0, 0, ], + ['', '', 0, 0], ['Hello', 'Hello, World!', 0, 5], ['Hello, World!', 'Hello, World!', 0], ['World', 'Hello, World!', 7, 5], ['سيف', 'مرحبا سيف', 6, 3], ['اهلا', 'اهلا بكم', 0, 4], ['destiny', 'People linked by destiny will always find each other.', 17, 7], - ['lö ', 'héllö wôrld', 3, 3, ], - ['lö wôrld', 'héllö wôrld', 3, null, ], + ['lö ', 'héllö wôrld', 3, 3], + ['lö wôrld', 'héllö wôrld', 3, null], ['', 'héllö wôrld', 3, 0], - ['', 'fôo', 3, null, ], - ['', 'fôo', 3, 12, ], - ['wôrld', 'héllö wôrld', -5, null, ], - ['wôrld', 'héllö wôrld', -5, 100, ], - ['wôr', 'héllö wôrld', -5, 3, ], + ['', 'fôo', 3, null], + ['', 'fôo', 3, 12], + ['wôrld', 'héllö wôrld', -5, null], + ['wôrld', 'héllö wôrld', -5, 100], + ['wôr', 'héllö wôrld', -5, 3], ]; } diff --git a/tests/unit/Str/Grapheme/StartsWithCiTest.php b/tests/unit/Str/Grapheme/StartsWithCiTest.php index 1ddfc441..5a95fdc4 100644 --- a/tests/unit/Str/Grapheme/StartsWithCiTest.php +++ b/tests/unit/Str/Grapheme/StartsWithCiTest.php @@ -20,22 +20,22 @@ public function testStartsWithCi(bool $expected, string $haystack, string $prefi public function provideData(): array { return [ - [true, 'Hello, World', 'Hello', ], - [false, 'Hello, World', 'world', ], - [false, 'Hello, World', '', ], - [false, 'hello, world', 'hey', ], - [true, 'azjezz', 'az', ], - [true, 'azjezz', 'Az', ], - [false, 'مرحبا بكم', 'بكم', ], - [true, 'مرحبا بكم', 'مرحبا', ], + [true, 'Hello, World', 'Hello'], + [false, 'Hello, World', 'world'], + [false, 'Hello, World', ''], + [false, 'hello, world', 'hey'], + [true, 'azjezz', 'az'], + [true, 'azjezz', 'Az'], + [false, 'مرحبا بكم', 'بكم'], + [true, 'مرحبا بكم', 'مرحبا'], [true, 'مرحبا سيف', 'مرحبا', 3], [false, 'مرحبا سيف', 'سيف', 3], [true, 'اهلا بكم', 'اهلا', 2], - [true, 'héllö wôrld', 'héllö', ], - [false, 'héllö wôrld', 'hello', ], - [true, 'fôo', 'fôo', ], - [true, 'fôo', 'f', ], - [true, 'fôo', 'fô', ], + [true, 'héllö wôrld', 'héllö'], + [false, 'héllö wôrld', 'hello'], + [true, 'fôo', 'fôo'], + [true, 'fôo', 'f'], + [true, 'fôo', 'fô'], ]; } } diff --git a/tests/unit/Str/Grapheme/StartsWithTest.php b/tests/unit/Str/Grapheme/StartsWithTest.php index dc122d3f..c2427d6f 100644 --- a/tests/unit/Str/Grapheme/StartsWithTest.php +++ b/tests/unit/Str/Grapheme/StartsWithTest.php @@ -20,22 +20,22 @@ public function testStartsWith(bool $expected, string $haystack, string $prefix) public function provideData(): array { return [ - [true, 'Hello, World', 'Hello', ], - [false, 'Hello, World', 'world', ], - [false, 'Hello, World', '', ], - [false, 'hello, world', 'hey', ], - [true, 'azjezz', 'az', ], - [false, 'azjezz', 'Az', ], - [false, 'مرحبا بكم', 'بكم', ], - [true, 'مرحبا بكم', 'مرحبا', ], + [true, 'Hello, World', 'Hello'], + [false, 'Hello, World', 'world'], + [false, 'Hello, World', ''], + [false, 'hello, world', 'hey'], + [true, 'azjezz', 'az'], + [false, 'azjezz', 'Az'], + [false, 'مرحبا بكم', 'بكم'], + [true, 'مرحبا بكم', 'مرحبا'], [true, 'مرحبا سيف', 'مرحبا', 3], [false, 'مرحبا سيف', 'سيف', 3], [true, 'اهلا بكم', 'اهلا', 2], - [true, 'héllö wôrld', 'héllö', ], - [false, 'héllö wôrld', 'hello', ], - [true, 'fôo', 'fôo', ], - [true, 'fôo', 'f', ], - [true, 'fôo', 'fô', ], + [true, 'héllö wôrld', 'héllö'], + [false, 'héllö wôrld', 'hello'], + [true, 'fôo', 'fôo'], + [true, 'fôo', 'f'], + [true, 'fôo', 'fô'], ]; } } diff --git a/tests/unit/Str/Grapheme/StripSuffixTest.php b/tests/unit/Str/Grapheme/StripSuffixTest.php index 0ed4326e..c62c9413 100644 --- a/tests/unit/Str/Grapheme/StripSuffixTest.php +++ b/tests/unit/Str/Grapheme/StripSuffixTest.php @@ -21,27 +21,27 @@ public function provideData(): array { return [ ['', 'Hello', 'Hello'], - ['Hello, World', 'Hello, World', 'world', ], - ['T U N I S I A', 'T U N I S I A', 'e', ], + ['Hello, World', 'Hello, World', 'world'], + ['T U N I S I A', 'T U N I S I A', 'e'], ['تون', 'تونس', 'س'], - ['Hello, World', 'Hello, World', '', ], - ['Hello, World', 'Hello, World', 'Hello, cruel world!', ], - ['hello, world', 'hello, world', 'hey', ], - ['azjez', 'azjezz', 'z', ], - ['مرحبا ', 'مرحبا بكم', 'بكم', ], - ['Hello', 'Hello, World', ', World', ], - ['Hello, World', 'Hello, World', 'world', ], - ['Hello, World', 'Hello, World', '', ], - ['hello, world', 'hello, world', 'universe', ], - ['azje', 'azjezz', 'zz', ], - ['azjezz', 'azjezz', 'ZZ', ], + ['Hello, World', 'Hello, World', ''], + ['Hello, World', 'Hello, World', 'Hello, cruel world!'], + ['hello, world', 'hello, world', 'hey'], + ['azjez', 'azjezz', 'z'], + ['مرحبا ', 'مرحبا بكم', 'بكم'], + ['Hello', 'Hello, World', ', World'], + ['Hello, World', 'Hello, World', 'world'], + ['Hello, World', 'Hello, World', ''], + ['hello, world', 'hello, world', 'universe'], + ['azje', 'azjezz', 'zz'], + ['azjezz', 'azjezz', 'ZZ'], ['مرحبا', 'مرحبا سيف', ' سيف', 3], ['اهلا', 'اهلا بكم', ' بكم', 3], - ['héllö', 'héllö wôrld', ' wôrld', ], - ['héllö wôrld', 'héllö wôrld', ' world', ], - ['fô', 'fôo', 'o', ], - ['fôo', 'fôo', 'ô', ], - ['f', 'fôo', 'ôo', ], + ['héllö', 'héllö wôrld', ' wôrld'], + ['héllö wôrld', 'héllö wôrld', ' world'], + ['fô', 'fôo', 'o'], + ['fôo', 'fôo', 'ô'], + ['f', 'fôo', 'ôo'], ]; } } diff --git a/tests/unit/Str/IsUTF8Test.php b/tests/unit/Str/IsUTF8Test.php index 77395b20..1e0ed336 100644 --- a/tests/unit/Str/IsUTF8Test.php +++ b/tests/unit/Str/IsUTF8Test.php @@ -22,21 +22,18 @@ public function provideData(): array return [ [true, 'hello'], [true, '🐘'], - - [true, "\xc3\xb1"], // valid 2 octet sequence - [true, "\xe2\x82\xa1"], // valid 3 octet sequence - [true, "\xf0\x90\x8c\xbc"], // valid 4 octet sequence - - [false, "\xc3\x28"], // invalid 2 octet sequence - [false, "\xa0\xa1"], // invalid sequence identifier - [false, "\xe2\x28\xa1"], // invalid 3 octet sequence (in 2nd octet) - [false, "\xe2\x82\x28"], // invalid 3 octet sequence (in 3rd octet) - [false, "\xf0\x28\x8c\xbc"], // invalid 4 octet sequence (in 2nd octet) - [false, "\xf0\x90\x28\xbc"], // invalid 4 octet sequence (in 3rd octet) - [false, "\xf0\x28\x8c\x28"], // invalid 4 octet sequence (in 4th octet) - - [false, "\xf8\xa1\xa1\xa1\xa1"], // valid 5 octet sequence (but not unicode!) - [false, "\xfc\xa1\xa1\xa1\xa1\xa1"], // valid 6 octet Sequence (but not unicode!) + [true, "\xc3\xb1"], // valid 2 octet sequence + [true, "\xe2\x82\xa1"], // valid 3 octet sequence + [true, "\xf0\x90\x8c\xbc"], // valid 4 octet sequence + [false, "\xc3\x28"], // invalid 2 octet sequence + [false, "\xa0\xa1"], // invalid sequence identifier + [false, "\xe2\x28\xa1"], // invalid 3 octet sequence (in 2nd octet) + [false, "\xe2\x82\x28"], // invalid 3 octet sequence (in 3rd octet) + [false, "\xf0\x28\x8c\xbc"], // invalid 4 octet sequence (in 2nd octet) + [false, "\xf0\x90\x28\xbc"], // invalid 4 octet sequence (in 3rd octet) + [false, "\xf0\x28\x8c\x28"], // invalid 4 octet sequence (in 4th octet) + [false, "\xf8\xa1\xa1\xa1\xa1"], // valid 5 octet sequence (but not unicode!) + [false, "\xfc\xa1\xa1\xa1\xa1\xa1"], // valid 6 octet Sequence (but not unicode!) ]; } } diff --git a/tests/unit/Str/LengthTest.php b/tests/unit/Str/LengthTest.php index 27a5a4b2..c185f70a 100644 --- a/tests/unit/Str/LengthTest.php +++ b/tests/unit/Str/LengthTest.php @@ -27,7 +27,7 @@ public function provideData(): array [3, '🥇🥈🥉'], [2, '你好'], [6, 'สวัสดี'], - [3, 'ؤخى'] + [3, 'ؤخى'], ]; } } diff --git a/tests/unit/Str/LevenshteinTest.php b/tests/unit/Str/LevenshteinTest.php index 38bc616a..d9d9ea4a 100644 --- a/tests/unit/Str/LevenshteinTest.php +++ b/tests/unit/Str/LevenshteinTest.php @@ -16,9 +16,9 @@ public function testLevenshtein( int $expected, string $a, string $b, - ?int $coi = null, - ?int $cor = null, - ?int $cod = null + null|int $coi = null, + null|int $cor = null, + null|int $cod = null, ): void { static::assertSame($expected, Str\levenshtein($a, $b, $coi, $cor, $cod)); } @@ -30,7 +30,7 @@ public function provideData(): array [1, 'foo', 'oo'], [1, 'oo', 'foo'], [6, 'saif', 'azjezz'], - [48, 'saif', 'azjezz', 9, 8, 5] + [48, 'saif', 'azjezz', 9, 8, 5], ]; } } diff --git a/tests/unit/Str/LowercaseTest.php b/tests/unit/Str/LowercaseTest.php index 953eebeb..6d4e4ace 100644 --- a/tests/unit/Str/LowercaseTest.php +++ b/tests/unit/Str/LowercaseTest.php @@ -34,7 +34,7 @@ public function provideData(): array ['你好', '你好'], ['こんにちは世界', 'こんにちは世界'], ['สวัสดี', 'สวัสดี'], - ['ؤخى', 'ؤخى'] + ['ؤخى', 'ؤخى'], ]; } } diff --git a/tests/unit/Str/MetaphoneTest.php b/tests/unit/Str/MetaphoneTest.php index bebeb1ac..30b4ff78 100644 --- a/tests/unit/Str/MetaphoneTest.php +++ b/tests/unit/Str/MetaphoneTest.php @@ -12,7 +12,7 @@ final class MetaphoneTest extends TestCase /** * @dataProvider provideData */ - public function testMetaphone(?string $expected, string $str, int $phonemes = 0): void + public function testMetaphone(null|string $expected, string $str, int $phonemes = 0): void { static::assertSame($expected, Str\metaphone($str, $phonemes)); } diff --git a/tests/unit/Str/RangeTest.php b/tests/unit/Str/RangeTest.php index 4382ddc9..30195290 100644 --- a/tests/unit/Str/RangeTest.php +++ b/tests/unit/Str/RangeTest.php @@ -34,8 +34,16 @@ public function provideData(): array ['سيف', 'مرحبا سيف', Range\between(6, 9, upper_inclusive: true)], ['اهلا', 'اهلا بكم', Range\between(0, 3, upper_inclusive: true)], ['اهلا', 'اهلا بكم', Range\between(0, 4, upper_inclusive: false)], - ['destiny', 'People linked by destiny will always find each other.', Range\between(17, 23, upper_inclusive: true)], - ['destiny', 'People linked by destiny will always find each other.', Range\between(17, 24, upper_inclusive: false)], + [ + 'destiny', + 'People linked by destiny will always find each other.', + Range\between(17, 23, upper_inclusive: true), + ], + [ + 'destiny', + 'People linked by destiny will always find each other.', + Range\between(17, 24, upper_inclusive: false), + ], ['lö ', 'héllö wôrld', Range\between(3, 5, upper_inclusive: true)], ['lö ', 'héllö wôrld', Range\between(3, 6, upper_inclusive: false)], ['lö wôrld', 'héllö wôrld', Range\from(3)], @@ -45,7 +53,11 @@ public function provideData(): array ['', 'fôo', Range\between(3, 3)], ['', 'fôo', Range\between(3, 12)], ['fôo', 'fôo', Range\full()], - ['he̡̙̬͎̿́̐̅̕͢', 'he̡̙̬͎̿́̐̅̕͢l͕̮͕͈̜͐̈́̇̕͠ļ͚͉̗̘̽͑̿͑̚o̼̰̼͕̞̍̄̎̿̊,̻̰̻̘́̎͒̋͘͟ ̧̬̝͈̬̿͌̿̑̕ẉ̣̟͉̮͆̊̃͐̈́ờ̢̫͎͖̹͊́͐r̨̮͓͓̣̅̋͐͐͆ḻ̩̦͚̯͑̌̓̅͒d͇̯͔̼͍͛̾͛͡͝', Range\between(0, 11, true)], + [ + 'he̡̙̬͎̿́̐̅̕͢', + 'he̡̙̬͎̿́̐̅̕͢l͕̮͕͈̜͐̈́̇̕͠ļ͚͉̗̘̽͑̿͑̚o̼̰̼͕̞̍̄̎̿̊,̻̰̻̘́̎͒̋͘͟ ̧̬̝͈̬̿͌̿̑̕ẉ̣̟͉̮͆̊̃͐̈́ờ̢̫͎͖̹͊́͐r̨̮͓͓̣̅̋͐͐͆ḻ̩̦͚̯͑̌̓̅͒d͇̯͔̼͍͛̾͛͡͝', + Range\between(0, 11, true), + ], ]; } diff --git a/tests/unit/Str/ReplaceCiTest.php b/tests/unit/Str/ReplaceCiTest.php index 852f67c3..a05c53ac 100644 --- a/tests/unit/Str/ReplaceCiTest.php +++ b/tests/unit/Str/ReplaceCiTest.php @@ -20,8 +20,8 @@ public function testReplaceCi(string $expected, string $haystack, string $needle public function provideData(): array { return [ - ['Hello, World!', 'Hello, you!', 'You', 'World', ], - ['Hello, World!', 'Hello, You!', 'You', 'World', ], + ['Hello, World!', 'Hello, you!', 'You', 'World'], + ['Hello, World!', 'Hello, You!', 'You', 'World'], ['مرحبا بكم', 'مرحبا سيف', 'سيف', 'بكم'], ['foo', 'foo', 'bar', 'baz'], ]; diff --git a/tests/unit/Str/ReplaceEveryCiTest.php b/tests/unit/Str/ReplaceEveryCiTest.php index e900c242..53a37938 100644 --- a/tests/unit/Str/ReplaceEveryCiTest.php +++ b/tests/unit/Str/ReplaceEveryCiTest.php @@ -40,14 +40,14 @@ public function provideData(): array 'مرحبا سيف', [ 'سيف' => 'بكم', - 'مرحبا' => 'اهلا' + 'مرحبا' => 'اهلا', ], ], [ 'Foo', 'Foo', - ['bar' => 'baz'] - ] + ['bar' => 'baz'], + ], ]; } } diff --git a/tests/unit/Str/ReplaceEveryTest.php b/tests/unit/Str/ReplaceEveryTest.php index 7048500c..6a0d68ed 100644 --- a/tests/unit/Str/ReplaceEveryTest.php +++ b/tests/unit/Str/ReplaceEveryTest.php @@ -43,8 +43,8 @@ public function provideData(): array [ 'Foo', 'Foo', - ['bar' => 'baz'] - ] + ['bar' => 'baz'], + ], ]; } } diff --git a/tests/unit/Str/ReplaceTest.php b/tests/unit/Str/ReplaceTest.php index 96c266cd..1dd8f28f 100644 --- a/tests/unit/Str/ReplaceTest.php +++ b/tests/unit/Str/ReplaceTest.php @@ -20,8 +20,8 @@ public function testReplace(string $expected, string $haystack, string $needle, public function provideData(): array { return [ - ['Hello, you!', 'Hello, you!', 'You', 'World', ], - ['Hello, World!', 'Hello, You!', 'You', 'World', ], + ['Hello, you!', 'Hello, you!', 'You', 'World'], + ['Hello, World!', 'Hello, You!', 'You', 'World'], ['مرحبا بكم', 'مرحبا سيف', 'سيف', 'بكم'], ['foo', 'foo', 'bar', 'baz'], ]; diff --git a/tests/unit/Str/ReverseTest.php b/tests/unit/Str/ReverseTest.php index 9ec1e978..58d885e0 100644 --- a/tests/unit/Str/ReverseTest.php +++ b/tests/unit/Str/ReverseTest.php @@ -15,7 +15,7 @@ public function provideData(): array ['Hello World', 'dlroW olleH'], ['héllö wôrld', 'dlrôw ölléh'], ['Iñigo Montoya', 'ayotnoM ogiñI'], - ['某物', '物某' ], + ['某物', '物某'], ['что-то', 'от-отч'], ['🙂😟', '😟🙂'], ['مرحبا', 'ابحرم'], diff --git a/tests/unit/Str/SearchCiTest.php b/tests/unit/Str/SearchCiTest.php index 606832a5..f98a7664 100644 --- a/tests/unit/Str/SearchCiTest.php +++ b/tests/unit/Str/SearchCiTest.php @@ -12,7 +12,7 @@ final class SearchCiTest extends TestCase /** * @dataProvider provideData */ - public function testSearchCi(?int $expected, string $haystack, string $needle, int $offset = 0): void + public function testSearchCi(null|int $expected, string $haystack, string $needle, int $offset = 0): void { static::assertSame($expected, Str\search_ci($haystack, $needle, $offset)); } @@ -20,10 +20,10 @@ public function testSearchCi(?int $expected, string $haystack, string $needle, i public function provideData(): array { return [ - [7, 'Hello, you!', 'You', ], - [7, 'Hello, You!', 'You', ], - [0, 'Ho! Ho! Ho!', 'ho', ], - [0, 'Ho! Ho! Ho!', 'Ho', ], + [7, 'Hello, you!', 'You'], + [7, 'Hello, You!', 'You'], + [0, 'Ho! Ho! Ho!', 'ho'], + [0, 'Ho! Ho! Ho!', 'Ho'], [7, 'Hello, You!', 'You', 5], [null, 'Hello, World!', 'You', 5], [6, 'مرحبا سيف', 'سيف', 4], diff --git a/tests/unit/Str/SearchLastCiTest.php b/tests/unit/Str/SearchLastCiTest.php index 601b6122..1d059c00 100644 --- a/tests/unit/Str/SearchLastCiTest.php +++ b/tests/unit/Str/SearchLastCiTest.php @@ -12,7 +12,7 @@ final class SearchLastCiTest extends TestCase /** * @dataProvider provideData */ - public function testSearchLastCi(?int $expected, string $haystack, string $needle, int $offset = 0): void + public function testSearchLastCi(null|int $expected, string $haystack, string $needle, int $offset = 0): void { static::assertSame($expected, Str\search_last_ci($haystack, $needle, $offset)); } @@ -20,10 +20,10 @@ public function testSearchLastCi(?int $expected, string $haystack, string $needl public function provideData(): array { return [ - [7, 'Hello, you!', 'You', ], - [7, 'Hello, You!', 'You', ], - [8, 'Ho! Ho! Ho!', 'ho', ], - [8, 'Ho! Ho! Ho!', 'Ho', ], + [7, 'Hello, you!', 'You'], + [7, 'Hello, You!', 'You'], + [8, 'Ho! Ho! Ho!', 'ho'], + [8, 'Ho! Ho! Ho!', 'Ho'], [7, 'Hello, You!', 'You', 5], [null, 'Hello, World!', 'You', 5], [6, 'مرحبا سيف', 'سيف', 4], diff --git a/tests/unit/Str/SearchLastTest.php b/tests/unit/Str/SearchLastTest.php index 22a9888e..2d7e5d36 100644 --- a/tests/unit/Str/SearchLastTest.php +++ b/tests/unit/Str/SearchLastTest.php @@ -12,7 +12,7 @@ final class SearchLastTest extends TestCase /** * @dataProvider provideData */ - public function testSearchLast(?int $expected, string $haystack, string $needle, int $offset = 0): void + public function testSearchLast(null|int $expected, string $haystack, string $needle, int $offset = 0): void { static::assertSame($expected, Str\search_last($haystack, $needle, $offset)); } @@ -20,10 +20,10 @@ public function testSearchLast(?int $expected, string $haystack, string $needle, public function provideData(): array { return [ - [null, 'Hello, you!', 'You', ], - [7, 'Hello, You!', 'You', ], - [null, 'Ho! Ho! Ho!', 'ho', ], - [8, 'Ho! Ho! Ho!', 'Ho', ], + [null, 'Hello, you!', 'You'], + [7, 'Hello, You!', 'You'], + [null, 'Ho! Ho! Ho!', 'ho'], + [8, 'Ho! Ho! Ho!', 'Ho'], [7, 'Hello, You!', 'You', 5], [null, 'Hello, World!', 'You', 5], [6, 'مرحبا سيف', 'سيف', 4], diff --git a/tests/unit/Str/SearchTest.php b/tests/unit/Str/SearchTest.php index d7d07136..d886c1c0 100644 --- a/tests/unit/Str/SearchTest.php +++ b/tests/unit/Str/SearchTest.php @@ -12,7 +12,7 @@ final class SearchTest extends TestCase /** * @dataProvider provideData */ - public function testSearch(?int $expected, string $haystack, string $needle, int $offset = 0): void + public function testSearch(null|int $expected, string $haystack, string $needle, int $offset = 0): void { static::assertSame($expected, Str\search($haystack, $needle, $offset)); } @@ -20,10 +20,10 @@ public function testSearch(?int $expected, string $haystack, string $needle, int public function provideData(): array { return [ - [null, 'Hello, you!', 'You', ], - [7, 'Hello, You!', 'You', ], - [null, 'Ho! Ho! Ho!', 'ho', ], - [0, 'Ho! Ho! Ho!', 'Ho', ], + [null, 'Hello, you!', 'You'], + [7, 'Hello, You!', 'You'], + [null, 'Ho! Ho! Ho!', 'ho'], + [0, 'Ho! Ho! Ho!', 'Ho'], [7, 'Hello, You!', 'You', 5], [null, 'Hello, World!', 'You', 5], [6, 'مرحبا سيف', 'سيف', 4], diff --git a/tests/unit/Str/SliceTest.php b/tests/unit/Str/SliceTest.php index 9316217b..e02f371b 100644 --- a/tests/unit/Str/SliceTest.php +++ b/tests/unit/Str/SliceTest.php @@ -13,7 +13,7 @@ final class SliceTest extends TestCase /** * @dataProvider provideData */ - public function testSlice(string $expected, string $string, int $offset, ?int $length = null): void + public function testSlice(string $expected, string $string, int $offset, null|int $length = null): void { static::assertSame($expected, Str\slice($string, $offset, $length)); } @@ -21,21 +21,21 @@ public function testSlice(string $expected, string $string, int $offset, ?int $l public function provideData(): array { return [ - ['', '', 0, 0, ], + ['', '', 0, 0], ['Hello', 'Hello, World!', 0, 5], ['Hello, World!', 'Hello, World!', 0], ['World', 'Hello, World!', 7, 5], ['سيف', 'مرحبا سيف', 6, 3], ['اهلا', 'اهلا بكم', 0, 4], ['destiny', 'People linked by destiny will always find each other.', 17, 7], - ['lö ', 'héllö wôrld', 3, 3, ], - ['lö wôrld', 'héllö wôrld', 3, null, ], + ['lö ', 'héllö wôrld', 3, 3], + ['lö wôrld', 'héllö wôrld', 3, null], ['', 'héllö wôrld', 3, 0], - ['', 'fôo', 3, null, ], - ['', 'fôo', 3, 12, ], - ['wôrld', 'héllö wôrld', -5, null, ], - ['wôrld', 'héllö wôrld', -5, 100, ], - ['wôr', 'héllö wôrld', -5, 3, ], + ['', 'fôo', 3, null], + ['', 'fôo', 3, 12], + ['wôrld', 'héllö wôrld', -5, null], + ['wôrld', 'héllö wôrld', -5, 100], + ['wôr', 'héllö wôrld', -5, 3], ]; } diff --git a/tests/unit/Str/SpliceTest.php b/tests/unit/Str/SpliceTest.php index 7bac15a9..41db55a7 100644 --- a/tests/unit/Str/SpliceTest.php +++ b/tests/unit/Str/SpliceTest.php @@ -17,7 +17,7 @@ public function testSplice( string $string, string $replacement, int $offset, - ?int $length = null + null|int $length = null, ): void { static::assertSame($expected, Str\splice($string, $replacement, $offset, $length)); } @@ -25,20 +25,20 @@ public function testSplice( public function provideData(): array { return [ - ['', '', '', 0, null, ], - ['héllö darkness', 'héllö wôrld', 'darkness', 6, null, ], + ['', '', '', 0, null], + ['héllö darkness', 'héllö wôrld', 'darkness', 6, null], ['héllö crüel wôrld', 'héllö wôrld', ' crüel ', 5, 1], - ['héllö crüel wôrld', 'héllö wôrld', ' crüel ', -6, 1, ], - ['héllö crüel wôrld', 'héllö wôrld', ' crüel', 5, 0, ], - ['héllö darkness', 'héllö ', 'darkness', 6, null, ], - ['héllö darkness', 'héllö wôrld', 'darkness', 6, 100, ], - ['héllö darkness', 'héllö wôrld', 'darkness', 6, 11, ], + ['héllö crüel wôrld', 'héllö wôrld', ' crüel ', -6, 1], + ['héllö crüel wôrld', 'héllö wôrld', ' crüel', 5, 0], + ['héllö darkness', 'héllö ', 'darkness', 6, null], + ['héllö darkness', 'héllö wôrld', 'darkness', 6, 100], + ['héllö darkness', 'héllö wôrld', 'darkness', 6, 11], [ 'Peôple linkéd by déstiny wȋll ȃlways find each öther.', 'Peôple linkéd by déstiny wȋll find each öther.', ' ȃlways ', 29, - 1 + 1, ], ]; } diff --git a/tests/unit/Str/SplitTest.php b/tests/unit/Str/SplitTest.php index 494e12bc..d73ca6cc 100644 --- a/tests/unit/Str/SplitTest.php +++ b/tests/unit/Str/SplitTest.php @@ -12,7 +12,7 @@ final class SplitTest extends TestCase /** * @dataProvider provideData */ - public function testSplit(array $expected, string $string, string $delimiter, ?int $length = null): void + public function testSplit(array $expected, string $string, string $delimiter, null|int $length = null): void { static::assertSame($expected, Str\split($string, $delimiter, $length)); } @@ -23,16 +23,16 @@ public function provideData(): array [[], '', '', 1], [['Hello, World!'], 'Hello, World!', ' ', 1], [['Hello,', 'World!'], 'Hello, World!', ' ', 2], - [['مرحبا', 'سيف', ], 'مرحبا سيف', ' ', 3], + [['مرحبا', 'سيف'], 'مرحبا سيف', ' ', 3], [['اهلا', 'بكم'], 'اهلا بكم', ' ', 2], [['اهلا بكم'], 'اهلا بكم', '', 1], [['اهلا', 'بكم'], 'اهلا بكم', ' ', null], [['اهلا', 'بكم'], 'اهلا بكم', ' ', 100], - [['h', 'é', 'l', 'l', 'ö', ' ', 'w', 'ôrld'], 'héllö wôrld', '', 8, ], + [['h', 'é', 'l', 'l', 'ö', ' ', 'w', 'ôrld'], 'héllö wôrld', '', 8], [['h', 'é', 'l', 'l', 'ö', ' ', 'w', 'ô', 'r', 'l', 'd'], 'héllö wôrld', ''], [['fôo'], 'fôo', 'bar', null], - [['héll', ' w', 'rld'], 'héllô wôrld', 'ô', 3, ], - [['héllö w', 'rld'], 'héllö wôrld', 'ô', 3, ], + [['héll', ' w', 'rld'], 'héllô wôrld', 'ô', 3], + [['héllö w', 'rld'], 'héllö wôrld', 'ô', 3], ]; } } diff --git a/tests/unit/Str/StartsWithCiTest.php b/tests/unit/Str/StartsWithCiTest.php index 6b55896c..fcf2dc41 100644 --- a/tests/unit/Str/StartsWithCiTest.php +++ b/tests/unit/Str/StartsWithCiTest.php @@ -20,22 +20,22 @@ public function testStartsWithCi(bool $expected, string $haystack, string $prefi public function provideData(): array { return [ - [true, 'Hello, World', 'Hello', ], - [false, 'Hello, World', 'world', ], - [false, 'Hello, World', '', ], - [false, 'hello, world', 'hey', ], - [true, 'azjezz', 'az', ], - [true, 'azjezz', 'Az', ], - [false, 'مرحبا بكم', 'بكم', ], - [true, 'مرحبا بكم', 'مرحبا', ], + [true, 'Hello, World', 'Hello'], + [false, 'Hello, World', 'world'], + [false, 'Hello, World', ''], + [false, 'hello, world', 'hey'], + [true, 'azjezz', 'az'], + [true, 'azjezz', 'Az'], + [false, 'مرحبا بكم', 'بكم'], + [true, 'مرحبا بكم', 'مرحبا'], [true, 'مرحبا سيف', 'مرحبا', 3], [false, 'مرحبا سيف', 'سيف', 3], [true, 'اهلا بكم', 'اهلا', 2], - [true, 'héllö wôrld', 'héllö', ], - [false, 'héllö wôrld', 'hello', ], - [true, 'fôo', 'fôo', ], - [true, 'fôo', 'f', ], - [true, 'fôo', 'fô', ], + [true, 'héllö wôrld', 'héllö'], + [false, 'héllö wôrld', 'hello'], + [true, 'fôo', 'fôo'], + [true, 'fôo', 'f'], + [true, 'fôo', 'fô'], ]; } } diff --git a/tests/unit/Str/StartsWithTest.php b/tests/unit/Str/StartsWithTest.php index c2e93598..10ebf982 100644 --- a/tests/unit/Str/StartsWithTest.php +++ b/tests/unit/Str/StartsWithTest.php @@ -20,22 +20,22 @@ public function testStartsWith(bool $expected, string $haystack, string $prefix) public function provideData(): array { return [ - [true, 'Hello, World', 'Hello', ], - [false, 'Hello, World', 'world', ], - [false, 'Hello, World', '', ], - [false, 'hello, world', 'hey', ], - [true, 'azjezz', 'az', ], - [false, 'azjezz', 'Az', ], - [false, 'مرحبا بكم', 'بكم', ], - [true, 'مرحبا بكم', 'مرحبا', ], + [true, 'Hello, World', 'Hello'], + [false, 'Hello, World', 'world'], + [false, 'Hello, World', ''], + [false, 'hello, world', 'hey'], + [true, 'azjezz', 'az'], + [false, 'azjezz', 'Az'], + [false, 'مرحبا بكم', 'بكم'], + [true, 'مرحبا بكم', 'مرحبا'], [true, 'مرحبا سيف', 'مرحبا', 3], [false, 'مرحبا سيف', 'سيف', 3], [true, 'اهلا بكم', 'اهلا', 2], - [true, 'héllö wôrld', 'héllö', ], - [false, 'héllö wôrld', 'hello', ], - [true, 'fôo', 'fôo', ], - [true, 'fôo', 'f', ], - [true, 'fôo', 'fô', ], + [true, 'héllö wôrld', 'héllö'], + [false, 'héllö wôrld', 'hello'], + [true, 'fôo', 'fôo'], + [true, 'fôo', 'f'], + [true, 'fôo', 'fô'], ]; } } diff --git a/tests/unit/Str/StripSuffixTest.php b/tests/unit/Str/StripSuffixTest.php index b5cdc59e..673d0f0a 100644 --- a/tests/unit/Str/StripSuffixTest.php +++ b/tests/unit/Str/StripSuffixTest.php @@ -21,27 +21,27 @@ public function provideData(): array { return [ ['', 'Hello', 'Hello'], - ['Hello, World', 'Hello, World', 'world', ], - ['T U N I S I A', 'T U N I S I A', 'e', ], + ['Hello, World', 'Hello, World', 'world'], + ['T U N I S I A', 'T U N I S I A', 'e'], ['تون', 'تونس', 'س'], - ['Hello, World', 'Hello, World', '', ], - ['Hello, World', 'Hello, World', 'Hello, cruel world!', ], - ['hello, world', 'hello, world', 'hey', ], - ['azjez', 'azjezz', 'z', ], - ['مرحبا ', 'مرحبا بكم', 'بكم', ], - ['Hello', 'Hello, World', ', World', ], - ['Hello, World', 'Hello, World', 'world', ], - ['Hello, World', 'Hello, World', '', ], - ['hello, world', 'hello, world', 'universe', ], - ['azje', 'azjezz', 'zz', ], - ['azjezz', 'azjezz', 'ZZ', ], + ['Hello, World', 'Hello, World', ''], + ['Hello, World', 'Hello, World', 'Hello, cruel world!'], + ['hello, world', 'hello, world', 'hey'], + ['azjez', 'azjezz', 'z'], + ['مرحبا ', 'مرحبا بكم', 'بكم'], + ['Hello', 'Hello, World', ', World'], + ['Hello, World', 'Hello, World', 'world'], + ['Hello, World', 'Hello, World', ''], + ['hello, world', 'hello, world', 'universe'], + ['azje', 'azjezz', 'zz'], + ['azjezz', 'azjezz', 'ZZ'], ['مرحبا', 'مرحبا سيف', ' سيف', 3], ['اهلا', 'اهلا بكم', ' بكم', 3], - ['héllö', 'héllö wôrld', ' wôrld', ], - ['héllö wôrld', 'héllö wôrld', ' world', ], - ['fô', 'fôo', 'o', ], - ['fôo', 'fôo', 'ô', ], - ['f', 'fôo', 'ôo', ], + ['héllö', 'héllö wôrld', ' wôrld'], + ['héllö wôrld', 'héllö wôrld', ' world'], + ['fô', 'fôo', 'o'], + ['fôo', 'fôo', 'ô'], + ['f', 'fôo', 'ôo'], ]; } } diff --git a/tests/unit/Str/ToIntTest.php b/tests/unit/Str/ToIntTest.php index 9f0fadd8..5b1e147f 100644 --- a/tests/unit/Str/ToIntTest.php +++ b/tests/unit/Str/ToIntTest.php @@ -12,7 +12,7 @@ final class ToIntTest extends TestCase /** * @dataProvider provideData */ - public function testToInt(?int $expected, string $string): void + public function testToInt(null|int $expected, string $string): void { static::assertSame($expected, Str\to_int($string)); } diff --git a/tests/unit/Str/TrimLeftTest.php b/tests/unit/Str/TrimLeftTest.php index 45790842..d8c7930e 100644 --- a/tests/unit/Str/TrimLeftTest.php +++ b/tests/unit/Str/TrimLeftTest.php @@ -12,7 +12,7 @@ final class TrimLeftTest extends TestCase /** * @dataProvider provideData */ - public function testTrimLeft(string $expected, string $string, ?string $chars = null): void + public function testTrimLeft(string $expected, string $string, null|string $chars = null): void { static::assertSame($expected, Str\trim_left($string, $chars)); } diff --git a/tests/unit/Str/TrimRightTest.php b/tests/unit/Str/TrimRightTest.php index c2269283..5d82871c 100644 --- a/tests/unit/Str/TrimRightTest.php +++ b/tests/unit/Str/TrimRightTest.php @@ -12,7 +12,7 @@ final class TrimRightTest extends TestCase /** * @dataProvider provideData */ - public function testTrimRight(string $expected, string $string, ?string $chars = null): void + public function testTrimRight(string $expected, string $string, null|string $chars = null): void { static::assertSame($expected, Str\trim_right($string, $chars)); } diff --git a/tests/unit/Str/TrimTest.php b/tests/unit/Str/TrimTest.php index 03369a46..e69d7ae0 100644 --- a/tests/unit/Str/TrimTest.php +++ b/tests/unit/Str/TrimTest.php @@ -12,7 +12,7 @@ final class TrimTest extends TestCase /** * @dataProvider provideData */ - public function testTrim(string $expected, string $string, ?string $chars = null): void + public function testTrim(string $expected, string $string, null|string $chars = null): void { static::assertSame($expected, Str\trim($string, $chars)); } @@ -41,7 +41,7 @@ public function provideData(): array " \n!", ], [ - "Héllö World", + 'Héllö World', " Héllö World\t!!!\n", " \n!\t", ], diff --git a/tests/unit/Str/TruncateTest.php b/tests/unit/Str/TruncateTest.php index 5c3d13cc..d9f5f235 100644 --- a/tests/unit/Str/TruncateTest.php +++ b/tests/unit/Str/TruncateTest.php @@ -17,7 +17,7 @@ public function testTruncate( string $str, int $offset, int $width, - ?string $trim_marker = null + null|string $trim_marker = null, ): void { static::assertSame($expected, Str\truncate($str, $offset, $width, $trim_marker)); } diff --git a/tests/unit/Str/UppercaseTest.php b/tests/unit/Str/UppercaseTest.php index e71979a4..1e787247 100644 --- a/tests/unit/Str/UppercaseTest.php +++ b/tests/unit/Str/UppercaseTest.php @@ -32,7 +32,7 @@ public function provideData(): array ['你好', '你好'], ['こんにちは世界', 'こんにちは世界'], ['สวัสดี', 'สวัสดี'], - ['ؤخى', 'ؤخى'] + ['ؤخى', 'ؤخى'], ]; } } diff --git a/tests/unit/Str/WidthTest.php b/tests/unit/Str/WidthTest.php index f6b492c6..0a1e3d8f 100644 --- a/tests/unit/Str/WidthTest.php +++ b/tests/unit/Str/WidthTest.php @@ -36,7 +36,7 @@ public function provideData(): array [6, '🥇🥈🥉'], [4, '你好'], [6, 'สวัสดี'], - [3, 'ؤخى'] + [3, 'ؤخى'], ]; } } diff --git a/tests/unit/Str/WrapTest.php b/tests/unit/Str/WrapTest.php index b18176a1..bc6e17b5 100644 --- a/tests/unit/Str/WrapTest.php +++ b/tests/unit/Str/WrapTest.php @@ -17,7 +17,7 @@ public function testWrap( string $str, int $width = 75, string $break = "\n", - bool $cut = false + bool $cut = false, ): void { static::assertSame($expected, Str\wrap($str, $width, $break, $cut)); } @@ -35,7 +35,13 @@ public function provideData(): array ["こんに\nちは世\n界", 'こんにちは世界', 3, "\n", true], ['こんにちは世界', 'こんにちは世界', 3, "\n", false], ['こんにちは世界', 'こんにちは世界', 7, "\n", true], - [Str\concat('ส', '-', 'ว', '-', 'ั', '-', 'ส', '-', 'ด', '-', 'ี'), 'สวัสดี', 1, '-', true], + [ + Str\concat('ส', '-', 'ว', '-', 'ั', '-', 'ส', '-', 'ด', '-', 'ี'), + 'สวัสดี', + 1, + '-', + true, + ], ['สวัสดี', 'สวัสดี', 1, '-', false], ]; } diff --git a/tests/unit/TCP/ConnectTest.php b/tests/unit/TCP/ConnectTest.php index 6555b19f..1245721e 100644 --- a/tests/unit/TCP/ConnectTest.php +++ b/tests/unit/TCP/ConnectTest.php @@ -25,12 +25,7 @@ public function testConnect(): void $server->close(); }, 'client' => static function (): void { - $client = TCP\connect( - '127.0.0.1', - 8089, - TCP\ConnectOptions::create() - ->withNoDelay(false) - ); + $client = TCP\connect('127.0.0.1', 8089, TCP\ConnectOptions::create()->withNoDelay(false)); self::assertSame('tcp://127.0.0.1:8089', $client->getPeerAddress()->toString()); $client->writeAll('Hello, World!'); diff --git a/tests/unit/TCP/ServerOptionsTest.php b/tests/unit/TCP/ServerOptionsTest.php index 8347bc8b..0c8a8f1f 100644 --- a/tests/unit/TCP/ServerOptionsTest.php +++ b/tests/unit/TCP/ServerOptionsTest.php @@ -15,7 +15,7 @@ public function testDefaultOptions(): void $options = ServerOptions::default(); static::assertFalse($options->noDelay); - static::assertEquals(ServerOptions::DEFAULT_IDLE_CONNECTIONS, $options->idleConnections); + static::assertSame(ServerOptions::DEFAULT_IDLE_CONNECTIONS, $options->idleConnections); static::assertEquals(SocketOptions::default(), $options->socketOptions); } public function testNoDelay(): void diff --git a/tests/unit/TCP/ServerTest.php b/tests/unit/TCP/ServerTest.php index b62084bf..5b3d6bc5 100644 --- a/tests/unit/TCP/ServerTest.php +++ b/tests/unit/TCP/ServerTest.php @@ -18,14 +18,11 @@ public function testNextConnectionOnStoppedServer(): void $server = TCP\Server::create( '127.0.0.1', 0, - TCP\ServerOptions::create() - ->withNoDelay(true) - ->withSocketOptions( - Network\SocketOptions::create() - ->withAddressReuse(false) - ->withPortReuse(false) - ->withBroadcast(true) - ) + TCP\ServerOptions::create()->withNoDelay( + true, + )->withSocketOptions(Network\SocketOptions::create()->withAddressReuse(false)->withPortReuse( + false, + )->withBroadcast(true)), ); $server->close(); diff --git a/tests/unit/Trait/TraitTest.php b/tests/unit/Trait/TraitTest.php index c5da5aa3..a7ec0018 100644 --- a/tests/unit/Trait/TraitTest.php +++ b/tests/unit/Trait/TraitTest.php @@ -13,11 +13,8 @@ final class TraitTest extends TestCase /** * @dataProvider provideData */ - public function test( - string $trait_name, - bool $defined, - bool $exists, - ): void { + public function test(string $trait_name, bool $defined, bool $exists): void + { static::assertSame($defined, Trait\defined($trait_name)); static::assertSame($exists, Trait\exists($trait_name)); diff --git a/tests/unit/Type/ConvertedTypeTest.php b/tests/unit/Type/ConvertedTypeTest.php index f7fa5302..b850f7f5 100644 --- a/tests/unit/Type/ConvertedTypeTest.php +++ b/tests/unit/Type/ConvertedTypeTest.php @@ -18,16 +18,20 @@ public function getType(): Type\TypeInterface return Type\converted( Type\string(), Type\instance_of(DateTimeImmutable::class), - static fn (string $value): DateTimeImmutable => - DateTimeImmutable::createFromFormat(self::DATE_FORMAT, $value) - ?: throw new RuntimeException('Unable to parse date format'), + static fn(string $value): DateTimeImmutable => DateTimeImmutable::createFromFormat( + self::DATE_FORMAT, + $value, + ) ?: throw new RuntimeException('Unable to parse date format'), ); } public function getValidCoercions(): iterable { yield ['2023-04-27 08:28:00', DateTimeImmutable::createFromFormat(self::DATE_FORMAT, '2023-04-27 08:28:00')]; - yield [$this->stringable('2023-04-27 08:28:00'), DateTimeImmutable::createFromFormat(self::DATE_FORMAT, '2023-04-27 08:28:00')]; + yield [ + $this->stringable('2023-04-27 08:28:00'), + DateTimeImmutable::createFromFormat(self::DATE_FORMAT, '2023-04-27 08:28:00'), + ]; } public function getInvalidCoercions(): iterable @@ -66,41 +70,40 @@ public function getToStringExamples(): iterable public static function provideCoerceExceptionExpectations(): iterable { yield 'Coerce input error' => [ - Type\converted( - Type\int(), - Type\string(), - static fn (int $i): string => (string) $i - ), - new class () { + Type\converted(Type\int(), Type\string(), static fn(int $i): string => (string) $i), + new class() { }, - 'Could not coerce "class@anonymous" to type "int" at path "coerce_input(class@anonymous): int".' + 'Could not coerce "class@anonymous" to type "int" at path "coerce_input(class@anonymous): int".', ]; yield 'Convert exception error' => [ Type\converted( Type\int(), Type\string(), - static fn (int $i): string => throw new RuntimeException('not possible') + static fn(int $_i): string => throw new RuntimeException('not possible'), ), 1, - 'Could not coerce "int" to type "string" at path "convert(int): string": not possible.' + 'Could not coerce "int" to type "string" at path "convert(int): string": not possible.', ]; yield 'Coerce output error' => [ Type\converted( Type\int(), Type\string(), - static fn (int $i): object => new class () { - } + static fn(int $_i): object => new class() { + }, ), 1, - 'Could not coerce "class@anonymous" to type "string" at path "coerce_output(class@anonymous): string".' + 'Could not coerce "class@anonymous" to type "string" at path "coerce_output(class@anonymous): string".', ]; } /** * @dataProvider provideCoerceExceptionExpectations */ - public function testInvalidCoercionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidCoercionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->coerce($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\CoercionException::class)); diff --git a/tests/unit/Type/DictTypeTest.php b/tests/unit/Type/DictTypeTest.php index a9e3bb00..bfabd689 100644 --- a/tests/unit/Type/DictTypeTest.php +++ b/tests/unit/Type/DictTypeTest.php @@ -26,12 +26,12 @@ public function getValidCoercions(): iterable { yield [ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'], - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ @@ -55,27 +55,21 @@ public function getValidCoercions(): iterable ]; yield [ - Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string)$key), - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string) $key), + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ - Dict\map( - Vec\range(1, 10), - static fn(int $value): string => Str\format('00%d', $value) - ), - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + Dict\map(Vec\range(1, 10), static fn(int $value): string => Str\format('00%d', $value)), + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ Dict\map_keys( - Dict\map( - Vec\range(1, 10), - static fn(int $value): string => Str\format('00%d', $value) - ), - static fn(int $key): string => Str\format('00%d', $key) + Dict\map(Vec\range(1, 10), static fn(int $value): string => Str\format('00%d', $value)), + static fn(int $key): string => Str\format('00%d', $key), ), - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; } @@ -97,7 +91,7 @@ public function getToStringExamples(): iterable yield [Type\dict(Type\array_key(), Type\string()), 'dict']; yield [ Type\dict(Type\array_key(), Type\instance_of(Iter\Iterator::class)), - 'dict' + 'dict', ]; } @@ -106,16 +100,16 @@ public static function provideAssertExceptionExpectations(): iterable yield 'invalid assertion key' => [ Type\dict(Type\int(), Type\int()), ['nope' => 1], - 'Expected "dict", got "string" at path "key(nope)".' + 'Expected "dict", got "string" at path "key(nope)".', ]; yield 'invalid assertion value' => [ Type\dict(Type\int(), Type\int()), [0 => 'nope'], - 'Expected "dict", got "string" at path "0".' + 'Expected "dict", got "string" at path "0".', ]; yield 'nested' => [ Type\dict(Type\int(), Type\dict(Type\int(), Type\int())), - [0 => ['nope' => 'nope'],], + [0 => ['nope' => 'nope']], 'Expected "dict>", got "string" at path "0.key(nope)".', ]; } @@ -125,19 +119,19 @@ public static function provideCoerceExceptionExpectations(): iterable yield 'invalid coercion key' => [ Type\dict(Type\int(), Type\int()), ['nope' => 1], - 'Could not coerce "string" to type "dict" at path "key(nope)".' + 'Could not coerce "string" to type "dict" at path "key(nope)".', ]; yield 'invalid coercion value' => [ Type\dict(Type\int(), Type\int()), [0 => 'nope'], - 'Could not coerce "string" to type "dict" at path "0".' + 'Could not coerce "string" to type "dict" at path "0".', ]; yield 'invalid iterator first item' => [ Type\dict(Type\int(), Type\int()), (static function () { yield 0 => Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "dict" at path "first()".' + 'Could not coerce "string" to type "dict" at path "first()".', ]; yield 'invalid iterator second item' => [ Type\dict(Type\int(), Type\int()), @@ -145,7 +139,7 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0 => 0; yield 1 => Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "dict" at path "0.next()".' + 'Could not coerce "string" to type "dict" at path "0.next()".', ]; yield 'iterator throwing exception' => [ Type\dict(Type\int(), Type\int()), @@ -153,30 +147,33 @@ public static function provideCoerceExceptionExpectations(): iterable throw new RuntimeException('whoops'); yield; })(), - 'Could not coerce "null" to type "dict" at path "first()": whoops.' + 'Could not coerce "null" to type "dict" at path "first()": whoops.', ]; yield 'iterator yielding null key' => [ Type\dict(Type\int(), Type\int()), (static function () { yield null => 'nope'; })(), - 'Could not coerce "null" to type "dict" at path "key(null)".' + 'Could not coerce "null" to type "dict" at path "key(null)".', ]; yield 'iterator yielding object key' => [ Type\dict(Type\int(), Type\int()), (static function () { - yield (new class () { - }) => 'nope'; + yield new class() { + } => 'nope'; })(), - 'Could not coerce "class@anonymous" to type "dict" at path "key(class@anonymous)".' + 'Could not coerce "class@anonymous" to type "dict" at path "key(class@anonymous)".', ]; } /** * @dataProvider provideAssertExceptionExpectations */ - public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidAssertionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->assert($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\AssertException::class)); @@ -188,8 +185,11 @@ public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mix /** * @dataProvider provideCoerceExceptionExpectations */ - public function testInvalidCoercionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidCoercionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->coerce($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\CoercionException::class)); diff --git a/tests/unit/Type/Exception/TypeAssertExceptionTest.php b/tests/unit/Type/Exception/TypeAssertExceptionTest.php index 79eb7288..ad20b6f4 100644 --- a/tests/unit/Type/Exception/TypeAssertExceptionTest.php +++ b/tests/unit/Type/Exception/TypeAssertExceptionTest.php @@ -29,11 +29,7 @@ public function testIncorrectResourceType(): void public function testIncorrectNestedType() { - $type = Type\shape([ - 'child' => Type\shape([ - 'name' => Type\string(), - ]) - ]); + $type = Type\shape(['child' => Type\shape(['name' => Type\string()])]); try { $type->assert(['child' => ['name' => 123]]); @@ -43,13 +39,19 @@ public function testIncorrectNestedType() static::assertSame('array{\'child\': array{\'name\': string}}', $e->getExpectedType()); static::assertSame('array', $e->getActualType()); static::assertSame('int', $e->getFirstFailingActualType()); - static::assertSame('Expected "array{\'child\': array{\'name\': string}}", got "int" at path "child.name".', $e->getMessage()); + static::assertSame( + 'Expected "array{\'child\': array{\'name\': string}}", got "int" at path "child.name".', + $e->getMessage(), + ); static::assertSame(0, $e->getCode()); static::assertSame(['child', 'name'], $e->getPaths()); $previous = $e->getPrevious(); static::assertInstanceOf(Type\Exception\AssertException::class, $previous); - static::assertSame('Expected "array{\'name\': string}", got "int" at path "name".', $previous->getMessage()); + static::assertSame( + 'Expected "array{\'name\': string}", got "int" at path "name".', + $previous->getMessage(), + ); static::assertSame('int', $previous->getActualType()); static::assertSame('int', $previous->getFirstFailingActualType()); static::assertSame(0, $previous->getCode()); diff --git a/tests/unit/Type/Exception/TypeCoercionExceptionTest.php b/tests/unit/Type/Exception/TypeCoercionExceptionTest.php index 5c85186c..d9dc553c 100644 --- a/tests/unit/Type/Exception/TypeCoercionExceptionTest.php +++ b/tests/unit/Type/Exception/TypeCoercionExceptionTest.php @@ -18,32 +18,25 @@ public function testIncorrectResourceType(): void try { $type->coerce(new Collection\Map(['hello' => 'foo'])); - static::fail(Str\format( - 'Expected "%s" exception to be thrown.', - Type\Exception\CoercionException::class - )); + static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\CoercionException::class)); } catch (Type\Exception\CoercionException $e) { static::assertSame('resource (curl)', $e->getTargetType()); static::assertSame(Collection\Map::class, $e->getActualType()); static::assertSame(0, $e->getCode()); - static::assertSame(Str\format( - 'Could not coerce "%s" to type "resource (curl)".', - Collection\Map::class - ), $e->getMessage()); + static::assertSame( + Str\format('Could not coerce "%s" to type "resource (curl)".', Collection\Map::class), + $e->getMessage(), + ); static::assertSame([], $e->getPaths()); } } public function testIncorrectNestedType() { - $type = Type\shape([ - 'child' => Type\shape([ - 'name' => Type\string(), - ]) - ]); + $type = Type\shape(['child' => Type\shape(['name' => Type\string()])]); try { - $type->coerce(['child' => ['name' => new class () { + $type->coerce(['child' => ['name' => new class() { }]]); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\CoercionException::class)); @@ -51,13 +44,19 @@ public function testIncorrectNestedType() static::assertSame('array{\'child\': array{\'name\': string}}', $e->getTargetType()); static::assertSame('array', $e->getActualType()); static::assertSame('class@anonymous', $e->getFirstFailingActualType()); - static::assertSame('Could not coerce "class@anonymous" to type "array{\'child\': array{\'name\': string}}" at path "child.name".', $e->getMessage()); + static::assertSame( + 'Could not coerce "class@anonymous" to type "array{\'child\': array{\'name\': string}}" at path "child.name".', + $e->getMessage(), + ); static::assertSame(0, $e->getCode()); static::assertSame(['child', 'name'], $e->getPaths()); $previous = $e->getPrevious(); static::assertInstanceOf(Type\Exception\CoercionException::class, $previous); - static::assertSame('Could not coerce "class@anonymous" to type "array{\'name\': string}" at path "name".', $previous->getMessage()); + static::assertSame( + 'Could not coerce "class@anonymous" to type "array{\'name\': string}" at path "name".', + $previous->getMessage(), + ); static::assertSame('class@anonymous', $previous->getActualType()); static::assertSame('class@anonymous', $previous->getFirstFailingActualType()); static::assertSame(0, $previous->getCode()); diff --git a/tests/unit/Type/F32TypeTest.php b/tests/unit/Type/F32TypeTest.php index 2c2399a6..566db263 100644 --- a/tests/unit/Type/F32TypeTest.php +++ b/tests/unit/Type/F32TypeTest.php @@ -29,8 +29,8 @@ public function getValidCoercions(): iterable yield ['3.', 3.0]; yield [$this->stringable('1.23'), 1.23]; yield [Math\UINT32_MAX, (float) Math\UINT32_MAX]; - yield [(string)Math\UINT32_MAX, (float) Math\UINT32_MAX]; - yield [$this->stringable((string)Math\UINT32_MAX), (float) Math\UINT32_MAX]; + yield [(string) Math\UINT32_MAX, (float) Math\UINT32_MAX]; + yield [$this->stringable((string) Math\UINT32_MAX), (float) Math\UINT32_MAX]; yield ['9223372036854775808', 9223372036854775808.0]; yield ['3.40282347E+38', Math\FLOAT32_MAX]; yield ['-3.40282347E+38', Math\FLOAT32_MIN]; @@ -47,7 +47,7 @@ public function getInvalidCoercions(): iterable yield ['foo']; yield [null]; yield [false]; - yield [new class () { + yield [new class() { }]; yield [$this->stringable('foo')]; yield ['0xFF']; diff --git a/tests/unit/Type/F64TypeTest.php b/tests/unit/Type/F64TypeTest.php index 206cc898..f8ef59e4 100644 --- a/tests/unit/Type/F64TypeTest.php +++ b/tests/unit/Type/F64TypeTest.php @@ -32,8 +32,8 @@ public function getValidCoercions(): iterable yield ['3.', 3.0]; yield [$this->stringable('1.23'), 1.23]; yield [Math\UINT32_MAX, (float) Math\UINT32_MAX]; - yield [(string)Math\UINT32_MAX, (float) Math\UINT32_MAX]; - yield [$this->stringable((string)Math\UINT32_MAX), (float) Math\UINT32_MAX]; + yield [(string) Math\UINT32_MAX, (float) Math\UINT32_MAX]; + yield [$this->stringable((string) Math\UINT32_MAX), (float) Math\UINT32_MAX]; yield ['9223372036854775808', 9223372036854775808.0]; yield ['3.40282347E+38', Math\FLOAT32_MAX]; yield ['-3.40282347E+38', Math\FLOAT32_MIN]; @@ -55,7 +55,7 @@ public function getInvalidCoercions(): iterable yield ['foo']; yield [null]; yield [false]; - yield [new class () { + yield [new class() { }]; yield [$this->stringable('foo')]; yield ['0xFF']; diff --git a/tests/unit/Type/FloatTypeTest.php b/tests/unit/Type/FloatTypeTest.php index 3df2d5f3..4cfd3db4 100644 --- a/tests/unit/Type/FloatTypeTest.php +++ b/tests/unit/Type/FloatTypeTest.php @@ -32,8 +32,8 @@ public function getValidCoercions(): iterable yield ['3.', 3.0]; yield [$this->stringable('1.23'), 1.23]; yield [Math\INT64_MAX, (float) Math\INT64_MAX]; - yield [(string)Math\INT64_MAX, (float) Math\INT64_MAX]; - yield [$this->stringable((string)Math\INT64_MAX), (float) Math\INT64_MAX]; + yield [(string) Math\INT64_MAX, (float) Math\INT64_MAX]; + yield [$this->stringable((string) Math\INT64_MAX), (float) Math\INT64_MAX]; yield ['9223372036854775808', 9223372036854775808.0]; yield ['007', 7.0]; yield ['-0.1', -0.1]; @@ -51,7 +51,7 @@ public function getInvalidCoercions(): iterable yield ['foo']; yield [null]; yield [false]; - yield [new class () { + yield [new class() { }]; yield [$this->stringable('foo')]; yield ['0xFF']; diff --git a/tests/unit/Type/IntegerBackedEnumTypeTest.php b/tests/unit/Type/IntegerBackedEnumTypeTest.php index 11ad860a..2b2eada6 100644 --- a/tests/unit/Type/IntegerBackedEnumTypeTest.php +++ b/tests/unit/Type/IntegerBackedEnumTypeTest.php @@ -17,7 +17,7 @@ public function getType(): Type\TypeInterface { return Type\backed_enum(IntegerEnum::class); } - + /** * @return iterable */ diff --git a/tests/unit/Type/Internal/PathExpressionTest.php b/tests/unit/Type/Internal/PathExpressionTest.php index b9e08af2..10608b97 100644 --- a/tests/unit/Type/Internal/PathExpressionTest.php +++ b/tests/unit/Type/Internal/PathExpressionTest.php @@ -18,8 +18,11 @@ public function testPath(): void static::assertSame('false', PathExpression::path(false)); static::assertSame('null', PathExpression::path(null)); static::assertSame('array', PathExpression::path([])); - static::assertSame('class@anonymous', PathExpression::path(new class () { - })); + static::assertSame( + 'class@anonymous', + PathExpression::path(new class() { + }), + ); } public function testExpression(): void diff --git a/tests/unit/Type/IntersectionTypeTest.php b/tests/unit/Type/IntersectionTypeTest.php index 4369ce4f..7b6e87c1 100644 --- a/tests/unit/Type/IntersectionTypeTest.php +++ b/tests/unit/Type/IntersectionTypeTest.php @@ -48,31 +48,25 @@ public function getToStringExamples(): iterable yield [ Type\intersection( Type\instance_of(IndexAccessInterface::class), - Type\instance_of(CollectionInterface::class) + Type\instance_of(CollectionInterface::class), ), - 'Psl\Collection\IndexAccessInterface&Psl\Collection\CollectionInterface' + 'Psl\Collection\IndexAccessInterface&Psl\Collection\CollectionInterface', ]; yield [ Type\intersection( Type\instance_of(IndexAccessInterface::class), - Type\union( - Type\instance_of(CollectionInterface::class), - Type\instance_of(Iterator::class) - ) + Type\union(Type\instance_of(CollectionInterface::class), Type\instance_of(Iterator::class)), ), - 'Psl\Collection\IndexAccessInterface&(Psl\Collection\CollectionInterface|Iterator)' + 'Psl\Collection\IndexAccessInterface&(Psl\Collection\CollectionInterface|Iterator)', ]; yield [ Type\intersection( - Type\union( - Type\instance_of(CollectionInterface::class), - Type\instance_of(Iterator::class) - ), - Type\instance_of(IndexAccessInterface::class) + Type\union(Type\instance_of(CollectionInterface::class), Type\instance_of(Iterator::class)), + Type\instance_of(IndexAccessInterface::class), ), - '(Psl\Collection\CollectionInterface|Iterator)&Psl\Collection\IndexAccessInterface' + '(Psl\Collection\CollectionInterface|Iterator)&Psl\Collection\IndexAccessInterface', ]; yield [ @@ -82,7 +76,7 @@ public function getToStringExamples(): iterable Type\instance_of(Iterator::class), Type\shape(['id' => Type\string()]), ), - 'Psl\Collection\IndexAccessInterface&Psl\Collection\CollectionInterface&Iterator&array{\'id\': string}' + 'Psl\Collection\IndexAccessInterface&Psl\Collection\CollectionInterface&Iterator&array{\'id\': string}', ]; } } diff --git a/tests/unit/Type/IterableTypeTest.php b/tests/unit/Type/IterableTypeTest.php index a6d0385c..8aec025b 100644 --- a/tests/unit/Type/IterableTypeTest.php +++ b/tests/unit/Type/IterableTypeTest.php @@ -28,18 +28,18 @@ public function getValidCoercions(): iterable yield [Vec\range(1, 10), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]; yield [ - Dict\map(Vec\range(1, 10), static fn (int $value): string => (string) $value), - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + Dict\map(Vec\range(1, 10), static fn(int $value): string => (string) $value), + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ - Dict\map_keys(Vec\range(1, 10), static fn (int $key): string => (string) $key), - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string) $key), + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ - Dict\map(Vec\range(1, 10), static fn (int $value): string => Str\format('00%d', $value)), - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + Dict\map(Vec\range(1, 10), static fn(int $value): string => Str\format('00%d', $value)), + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; } @@ -61,7 +61,7 @@ public function getToStringExamples(): iterable yield [Type\iterable(Type\array_key(), Type\string()), 'iterable']; yield [ Type\iterable(Type\array_key(), Type\instance_of(Iter\Iterator::class)), - 'iterable' + 'iterable', ]; } @@ -82,16 +82,16 @@ public static function provideAssertExceptionExpectations(): iterable yield 'invalid assertion key' => [ Type\iterable(Type\int(), Type\int()), ['nope' => 1], - 'Expected "iterable", got "string" at path "key(nope)".' + 'Expected "iterable", got "string" at path "key(nope)".', ]; yield 'invalid assertion value' => [ Type\iterable(Type\int(), Type\int()), [0 => 'nope'], - 'Expected "iterable", got "string" at path "0".' + 'Expected "iterable", got "string" at path "0".', ]; yield 'nested' => [ Type\iterable(Type\int(), Type\iterable(Type\int(), Type\int())), - [0 => ['nope' => 'nope'],], + [0 => ['nope' => 'nope']], 'Expected "iterable>", got "string" at path "0.key(nope)".', ]; } @@ -101,19 +101,19 @@ public static function provideCoerceExceptionExpectations(): iterable yield 'invalid coercion key' => [ Type\iterable(Type\int(), Type\int()), ['nope' => 1], - 'Could not coerce "string" to type "iterable" at path "key(nope)".' + 'Could not coerce "string" to type "iterable" at path "key(nope)".', ]; yield 'invalid coercion value' => [ Type\iterable(Type\int(), Type\int()), [0 => 'nope'], - 'Could not coerce "string" to type "iterable" at path "0".' + 'Could not coerce "string" to type "iterable" at path "0".', ]; yield 'invalid iterator first item' => [ Type\iterable(Type\int(), Type\int()), (static function () { yield 0 => Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "iterable" at path "first()".' + 'Could not coerce "string" to type "iterable" at path "first()".', ]; yield 'invalid iterator second item' => [ Type\iterable(Type\int(), Type\int()), @@ -121,7 +121,7 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0 => 0; yield 1 => Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "iterable" at path "0.next()".' + 'Could not coerce "string" to type "iterable" at path "0.next()".', ]; yield 'iterator throwing exception' => [ Type\iterable(Type\int(), Type\int()), @@ -129,30 +129,33 @@ public static function provideCoerceExceptionExpectations(): iterable throw new RuntimeException('whoops'); yield; })(), - 'Could not coerce "null" to type "iterable" at path "first()": whoops.' + 'Could not coerce "null" to type "iterable" at path "first()": whoops.', ]; yield 'iterator yielding null key' => [ Type\iterable(Type\int(), Type\int()), (static function () { yield null => 'nope'; })(), - 'Could not coerce "null" to type "iterable" at path "key(null)".' + 'Could not coerce "null" to type "iterable" at path "key(null)".', ]; yield 'iterator yielding object key' => [ Type\iterable(Type\int(), Type\int()), (static function () { - yield (new class () { - }) => 'nope'; + yield new class() { + } => 'nope'; })(), - 'Could not coerce "class@anonymous" to type "iterable" at path "key(class@anonymous)".' + 'Could not coerce "class@anonymous" to type "iterable" at path "key(class@anonymous)".', ]; } /** * @dataProvider provideAssertExceptionExpectations */ - public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidAssertionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->assert($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\AssertException::class)); @@ -164,8 +167,11 @@ public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mix /** * @dataProvider provideCoerceExceptionExpectations */ - public function testInvalidCoercionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidCoercionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->coerce($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\CoercionException::class)); diff --git a/tests/unit/Type/MapTypeTest.php b/tests/unit/Type/MapTypeTest.php index 3cdc7326..6e9ecb45 100644 --- a/tests/unit/Type/MapTypeTest.php +++ b/tests/unit/Type/MapTypeTest.php @@ -27,32 +27,32 @@ public function getValidCoercions(): iterable { yield [ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - new Collection\Map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\Map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ Vec\range(1, 10), - new Collection\Map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\Map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ Vec\range(1, 10), - new Collection\Map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\Map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ - Dict\map(Vec\range(1, 10), static fn(int $value): string => (string)$value), - new Collection\Map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + Dict\map(Vec\range(1, 10), static fn(int $value): string => (string) $value), + new Collection\Map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ - Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string)$key), - new Collection\Map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string) $key), + new Collection\Map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ Dict\map(Vec\range(1, 10), static fn(int $value): string => Str\format('00%d', $value)), - new Collection\Map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\Map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; } @@ -74,7 +74,7 @@ public function getToStringExamples(): iterable yield [Type\map(Type\array_key(), Type\string()), 'Psl\Collection\MapInterface']; yield [ Type\map(Type\array_key(), Type\instance_of(Iter\Iterator::class)), - 'Psl\Collection\MapInterface' + 'Psl\Collection\MapInterface', ]; } @@ -100,17 +100,21 @@ public static function provideAssertExceptionExpectations(): iterable yield 'invalid assertion key' => [ Type\map(Type\int(), Type\int()), new Collection\Map(['nope' => 1]), - 'Expected "' . MapInterface::class . '", got "string" at path "key(nope)".' + 'Expected "' . MapInterface::class . '", got "string" at path "key(nope)".', ]; yield 'invalid assertion value' => [ Type\map(Type\int(), Type\int()), new Collection\Map([0 => 'nope']), - 'Expected "' . MapInterface::class . '", got "string" at path "0".' + 'Expected "' . MapInterface::class . '", got "string" at path "0".', ]; yield 'nested' => [ Type\map(Type\int(), Type\map(Type\int(), Type\int())), new Collection\Map([0 => new Collection\Map(['nope' => 'nope'])]), - 'Expected "' . MapInterface::class . '>", got "string" at path "0.key(nope)".', + 'Expected "' . + MapInterface::class . + '>", got "string" at path "0.key(nope)".', ]; } @@ -119,19 +123,19 @@ public static function provideCoerceExceptionExpectations(): iterable yield 'invalid coercion key' => [ Type\map(Type\int(), Type\int()), ['nope' => 1], - 'Could not coerce "string" to type "' . MapInterface::class . '" at path "key(nope)".' + 'Could not coerce "string" to type "' . MapInterface::class . '" at path "key(nope)".', ]; yield 'invalid coercion value' => [ Type\map(Type\int(), Type\int()), [0 => 'nope'], - 'Could not coerce "string" to type "' . MapInterface::class . '" at path "0".' + 'Could not coerce "string" to type "' . MapInterface::class . '" at path "0".', ]; yield 'invalid iterator first item' => [ Type\map(Type\int(), Type\int()), (static function () { yield 0 => Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "' . MapInterface::class . '" at path "first()".' + 'Could not coerce "string" to type "' . MapInterface::class . '" at path "first()".', ]; yield 'invalid iterator second item' => [ Type\map(Type\int(), Type\int()), @@ -139,7 +143,7 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0 => 0; yield 1 => Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "' . MapInterface::class . '" at path "0.next()".' + 'Could not coerce "string" to type "' . MapInterface::class . '" at path "0.next()".', ]; yield 'iterator throwing exception' => [ Type\map(Type\int(), Type\int()), @@ -147,30 +151,35 @@ public static function provideCoerceExceptionExpectations(): iterable throw new RuntimeException('whoops'); yield; })(), - 'Could not coerce "null" to type "' . MapInterface::class . '" at path "first()": whoops.' + 'Could not coerce "null" to type "' . MapInterface::class . '" at path "first()": whoops.', ]; yield 'iterator yielding null key' => [ Type\map(Type\int(), Type\int()), (static function () { yield null => 'nope'; })(), - 'Could not coerce "null" to type "' . MapInterface::class . '" at path "key(null)".' + 'Could not coerce "null" to type "' . MapInterface::class . '" at path "key(null)".', ]; yield 'iterator yielding object key' => [ Type\map(Type\int(), Type\int()), (static function () { - yield (new class () { - }) => 'nope'; + yield new class() { + } => 'nope'; })(), - 'Could not coerce "class@anonymous" to type "' . MapInterface::class . '" at path "key(class@anonymous)".' + 'Could not coerce "class@anonymous" to type "' . + MapInterface::class . + '" at path "key(class@anonymous)".', ]; } /** * @dataProvider provideAssertExceptionExpectations */ - public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidAssertionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->assert($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\AssertException::class)); @@ -182,8 +191,11 @@ public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mix /** * @dataProvider provideCoerceExceptionExpectations */ - public function testInvalidCoercionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidCoercionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->coerce($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\CoercionException::class)); diff --git a/tests/unit/Type/MixedDictTypeTest.php b/tests/unit/Type/MixedDictTypeTest.php index b29f28ae..eae65ee3 100644 --- a/tests/unit/Type/MixedDictTypeTest.php +++ b/tests/unit/Type/MixedDictTypeTest.php @@ -25,23 +25,23 @@ public function getValidCoercions(): iterable { yield [ [], - [] + [], ]; yield [ ['foo' => 'bar'], - ['foo' => 'bar'] + ['foo' => 'bar'], ]; $object = new stdClass(); - yield [[0,1,2, 'foo' => 'bar', [], $object], [0,1,2, 'foo' => 'bar', [], $object]]; + yield [[0, 1, 2, 'foo' => 'bar', [], $object], [0, 1, 2, 'foo' => 'bar', [], $object]]; $gen = $this->generator(); - yield [$gen, [1,2, 'asdf' => 'key']]; + yield [$gen, [1, 2, 'asdf' => 'key']]; yield [ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ @@ -55,11 +55,8 @@ public function getValidCoercions(): iterable ]; yield [ - Dict\map( - Vec\range(1, 10), - static fn(int $value): string => Str\format('00%d', $value) - ), - ['001', '002', '003', '004', '005', '006', '007', '008', '009', '0010'] + Dict\map(Vec\range(1, 10), static fn(int $value): string => Str\format('00%d', $value)), + ['001', '002', '003', '004', '005', '006', '007', '008', '009', '0010'], ]; $spl = new SplObjectStorage(); @@ -88,7 +85,6 @@ public function getToStringExamples(): iterable yield [$this->getType(), 'dict']; } - public static function provideCoerceExceptionExpectations(): iterable { yield 'invalid iterator first item' => [ @@ -96,7 +92,7 @@ public static function provideCoerceExceptionExpectations(): iterable (static function () { yield 0 => Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "dict" at path "first()".' + 'Could not coerce "string" to type "dict" at path "first()".', ]; yield 'invalid iterator second item' => [ Type\mixed_dict(), @@ -104,7 +100,7 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0 => 0; yield 1 => Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "dict" at path "0.next()".' + 'Could not coerce "string" to type "dict" at path "0.next()".', ]; yield 'iterator throwing exception' => [ Type\mixed_dict(), @@ -112,30 +108,33 @@ public static function provideCoerceExceptionExpectations(): iterable throw new RuntimeException('whoops'); yield; })(), - 'Could not coerce "null" to type "dict" at path "first()": whoops.' + 'Could not coerce "null" to type "dict" at path "first()": whoops.', ]; yield 'iterator yielding null key' => [ Type\mixed_dict(), (static function () { yield null => 'nope'; })(), - 'Could not coerce "null" to type "dict" at path "key(null)".' + 'Could not coerce "null" to type "dict" at path "key(null)".', ]; yield 'iterator yielding object key' => [ Type\mixed_dict(), (static function () { - yield (new class () { - }) => 'nope'; + yield new class() { + } => 'nope'; })(), - 'Could not coerce "class@anonymous" to type "dict" at path "key(class@anonymous)".' + 'Could not coerce "class@anonymous" to type "dict" at path "key(class@anonymous)".', ]; } /** * @dataProvider provideCoerceExceptionExpectations */ - public function testInvalidCoercionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidCoercionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->coerce($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\CoercionException::class)); diff --git a/tests/unit/Type/MixedTypeTest.php b/tests/unit/Type/MixedTypeTest.php index 95cb3ca8..cbdb4cb0 100644 --- a/tests/unit/Type/MixedTypeTest.php +++ b/tests/unit/Type/MixedTypeTest.php @@ -47,8 +47,11 @@ public function getValidCoercions(): iterable yield [1, 1]; yield [true, true]; yield [[], []]; - yield [$_ = new class { - }, $_]; + yield [ + $_ = new class { + }, + $_, + ]; yield [null, null]; yield [STDIN, STDIN]; } diff --git a/tests/unit/Type/MixedVecTypeTest.php b/tests/unit/Type/MixedVecTypeTest.php index e378f517..6f009a5c 100644 --- a/tests/unit/Type/MixedVecTypeTest.php +++ b/tests/unit/Type/MixedVecTypeTest.php @@ -21,21 +21,21 @@ public function getValidCoercions(): iterable { yield [ [], - [] + [], ]; yield [ ['foo' => 'bar'], - ['bar'] + ['bar'], ]; yield [ - [1,2,3], - [1,2,3] + [1, 2, 3], + [1, 2, 3], ]; yield [ [16 => ['arr'], 'foo', 'bar', 45 => 1, 44 => 2], - [['arr'], 'foo', 'bar', 1,2] + [['arr'], 'foo', 'bar', 1, 2], ]; yield [ @@ -59,18 +59,18 @@ public function getValidCoercions(): iterable ]; yield [ - Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string)$key), - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string) $key), + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ Dict\map(Vec\range(1, 10), static fn(int $value): string => Str\format('00%d', $value)), - ['001', '002', '003', '004', '005', '006', '007', '008', '009', '0010'] + ['001', '002', '003', '004', '005', '006', '007', '008', '009', '0010'], ]; yield [ ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5], - [1, 2, 3, 4, 5] + [1, 2, 3, 4, 5], ]; } diff --git a/tests/unit/Type/MutableMapTypeTest.php b/tests/unit/Type/MutableMapTypeTest.php index 71a228fa..a1d977bd 100644 --- a/tests/unit/Type/MutableMapTypeTest.php +++ b/tests/unit/Type/MutableMapTypeTest.php @@ -27,37 +27,37 @@ public function getValidCoercions(): iterable { yield [ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - new Collection\MutableMap([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableMap([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ Vec\range(1, 10), - new Collection\MutableMap([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableMap([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ Vec\range(1, 10), - new Collection\MutableMap([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableMap([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ - Dict\map(Vec\range(1, 10), static fn(int $value): string => (string)$value), - new Collection\MutableMap([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + Dict\map(Vec\range(1, 10), static fn(int $value): string => (string) $value), + new Collection\MutableMap([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ - Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string)$key), - new Collection\MutableMap([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string) $key), + new Collection\MutableMap([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ Dict\map(Vec\range(1, 10), static fn(int $value): string => Str\format('00%d', $value)), - new Collection\MutableMap([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableMap([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ new Collection\Map([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), - new Collection\MutableMap([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableMap([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; } @@ -76,22 +76,22 @@ public function getToStringExamples(): iterable { yield [ $this->getType(), - 'Psl\Collection\MutableMapInterface' + 'Psl\Collection\MutableMapInterface', ]; yield [ Type\mutable_map(Type\array_key(), Type\int()), - 'Psl\Collection\MutableMapInterface' + 'Psl\Collection\MutableMapInterface', ]; yield [ Type\mutable_map(Type\array_key(), Type\string()), - 'Psl\Collection\MutableMapInterface' + 'Psl\Collection\MutableMapInterface', ]; yield [ Type\mutable_map(Type\array_key(), Type\instance_of(Iter\Iterator::class)), - 'Psl\Collection\MutableMapInterface' + 'Psl\Collection\MutableMapInterface', ]; } @@ -117,17 +117,21 @@ public static function provideAssertExceptionExpectations(): iterable yield 'invalid assertion key' => [ Type\mutable_map(Type\int(), Type\int()), new Collection\MutableMap(['nope' => 1]), - 'Expected "' . MutableMapInterface::class . '", got "string" at path "key(nope)".' + 'Expected "' . MutableMapInterface::class . '", got "string" at path "key(nope)".', ]; yield 'invalid assertion value' => [ Type\mutable_map(Type\int(), Type\int()), new Collection\MutableMap([0 => 'nope']), - 'Expected "' . MutableMapInterface::class . '", got "string" at path "0".' + 'Expected "' . MutableMapInterface::class . '", got "string" at path "0".', ]; yield 'nested' => [ Type\mutable_map(Type\int(), Type\mutable_map(Type\int(), Type\int())), new Collection\MutableMap([0 => new Collection\MutableMap(['nope' => 'nope'])]), - 'Expected "' . MutableMapInterface::class . '>", got "string" at path "0.key(nope)".', + 'Expected "' . + MutableMapInterface::class . + '>", got "string" at path "0.key(nope)".', ]; } @@ -136,19 +140,19 @@ public static function provideCoerceExceptionExpectations(): iterable yield 'invalid coercion key' => [ Type\mutable_map(Type\int(), Type\int()), ['nope' => 1], - 'Could not coerce "string" to type "' . MutableMapInterface::class . '" at path "key(nope)".' + 'Could not coerce "string" to type "' . MutableMapInterface::class . '" at path "key(nope)".', ]; yield 'invalid coercion value' => [ Type\mutable_map(Type\int(), Type\int()), [0 => 'nope'], - 'Could not coerce "string" to type "' . MutableMapInterface::class . '" at path "0".' + 'Could not coerce "string" to type "' . MutableMapInterface::class . '" at path "0".', ]; yield 'invalid iterator first item' => [ Type\mutable_map(Type\int(), Type\int()), (static function () { yield 0 => Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "' . MutableMapInterface::class . '" at path "first()".' + 'Could not coerce "string" to type "' . MutableMapInterface::class . '" at path "first()".', ]; yield 'invalid iterator second item' => [ Type\mutable_map(Type\int(), Type\int()), @@ -156,7 +160,7 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0 => 0; yield 1 => Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "' . MutableMapInterface::class . '" at path "0.next()".' + 'Could not coerce "string" to type "' . MutableMapInterface::class . '" at path "0.next()".', ]; yield 'iterator throwing exception' => [ Type\mutable_map(Type\int(), Type\int()), @@ -164,30 +168,35 @@ public static function provideCoerceExceptionExpectations(): iterable throw new RuntimeException('whoops'); yield; })(), - 'Could not coerce "null" to type "' . MutableMapInterface::class . '" at path "first()": whoops.' + 'Could not coerce "null" to type "' . MutableMapInterface::class . '" at path "first()": whoops.', ]; yield 'iterator yielding null key' => [ Type\mutable_map(Type\int(), Type\int()), (static function () { yield null => 'nope'; })(), - 'Could not coerce "null" to type "' . MutableMapInterface::class . '" at path "key(null)".' + 'Could not coerce "null" to type "' . MutableMapInterface::class . '" at path "key(null)".', ]; yield 'iterator yielding object key' => [ Type\mutable_map(Type\int(), Type\int()), (static function () { - yield (new class () { - }) => 'nope'; + yield new class() { + } => 'nope'; })(), - 'Could not coerce "class@anonymous" to type "' . MutableMapInterface::class . '" at path "key(class@anonymous)".' + 'Could not coerce "class@anonymous" to type "' . + MutableMapInterface::class . + '" at path "key(class@anonymous)".', ]; } /** * @dataProvider provideAssertExceptionExpectations */ - public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidAssertionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->assert($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\AssertException::class)); @@ -199,8 +208,11 @@ public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mix /** * @dataProvider provideCoerceExceptionExpectations */ - public function testInvalidCoercionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidCoercionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->coerce($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\CoercionException::class)); diff --git a/tests/unit/Type/MutableSetTypeTest.php b/tests/unit/Type/MutableSetTypeTest.php index 1cca9dc1..162f6cad 100644 --- a/tests/unit/Type/MutableSetTypeTest.php +++ b/tests/unit/Type/MutableSetTypeTest.php @@ -26,42 +26,42 @@ public function getValidCoercions(): iterable { yield [ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - new Collection\MutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], - new Collection\MutableSet([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) + new Collection\MutableSet([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), ]; yield [ Vec\range(1, 10), - new Collection\MutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ - Dict\map(Vec\range(1, 10), static fn(int $key): string => (string)$key), - new Collection\MutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + Dict\map(Vec\range(1, 10), static fn(int $key): string => (string) $key), + new Collection\MutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ new Collection\MutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), - new Collection\MutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ new Collection\Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), - new Collection\MutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), - new Collection\MutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), - new Collection\MutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; } @@ -104,12 +104,12 @@ public static function provideAssertExceptionExpectations(): iterable yield 'invalid assertion value' => [ Type\mutable_set(Type\int()), new Collection\MutableSet(['nope' => 'nope']), - 'Expected "' . MutableSetInterface::class . '", got "string" at path "nope".' + 'Expected "' . MutableSetInterface::class . '", got "string" at path "nope".', ]; yield 'nested' => [ Type\mutable_set(Type\string()), new Collection\MutableSet([123 => 123]), - 'Expected "' . MutableSetInterface::class . '", got "int" at path "123".' + 'Expected "' . MutableSetInterface::class . '", got "int" at path "123".', ]; } @@ -118,14 +118,14 @@ public static function provideCoerceExceptionExpectations(): iterable yield 'invalid coercion value' => [ Type\mutable_set(Type\int()), ['nope' => 'nope'], - 'Could not coerce "string" to type "' . MutableSetInterface::class . '" at path "nope".' + 'Could not coerce "string" to type "' . MutableSetInterface::class . '" at path "nope".', ]; yield 'invalid iterator first item' => [ Type\mutable_set(Type\int()), (static function () { yield Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "' . MutableSetInterface::class . '" at path "first()".' + 'Could not coerce "string" to type "' . MutableSetInterface::class . '" at path "first()".', ]; yield 'invalid iterator second item' => [ Type\mutable_set(Type\int()), @@ -133,7 +133,7 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0; yield Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "' . MutableSetInterface::class . '" at path "0.next()".' + 'Could not coerce "string" to type "' . MutableSetInterface::class . '" at path "0.next()".', ]; yield 'iterator throwing exception' => [ Type\mutable_set(Type\int()), @@ -141,37 +141,40 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0; throw new RuntimeException('whoops'); })(), - 'Could not coerce "null" to type "' . MutableSetInterface::class . '" at path "0.next()": whoops.' + 'Could not coerce "null" to type "' . MutableSetInterface::class . '" at path "0.next()": whoops.', ]; yield 'iterator yielding null key' => [ Type\mutable_set(Type\int()), (static function () { yield null => 'nope'; })(), - 'Could not coerce "string" to type "' . MutableSetInterface::class . '" at path "null".' + 'Could not coerce "string" to type "' . MutableSetInterface::class . '" at path "null".', ]; yield 'iterator yielding string key, null value' => [ Type\mutable_set(Type\int()), (static function () { yield 'nope' => null; })(), - 'Could not coerce "null" to type "' . MutableSetInterface::class . '" at path "nope".' + 'Could not coerce "null" to type "' . MutableSetInterface::class . '" at path "nope".', ]; yield 'iterator yielding object key' => [ Type\mutable_set(Type\int()), (static function () { - yield 'nope' => (new class () { - }); + yield 'nope' => new class() { + }; })(), - 'Could not coerce "class@anonymous" to type "' . MutableSetInterface::class . '" at path "nope".' + 'Could not coerce "class@anonymous" to type "' . MutableSetInterface::class . '" at path "nope".', ]; } /** * @dataProvider provideAssertExceptionExpectations */ - public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidAssertionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->assert($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\AssertException::class)); @@ -183,8 +186,11 @@ public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mix /** * @dataProvider provideCoerceExceptionExpectations */ - public function testInvalidCoercionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidCoercionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->coerce($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\CoercionException::class)); diff --git a/tests/unit/Type/MutableVectorTypeTest.php b/tests/unit/Type/MutableVectorTypeTest.php index bd519432..4977489f 100644 --- a/tests/unit/Type/MutableVectorTypeTest.php +++ b/tests/unit/Type/MutableVectorTypeTest.php @@ -27,42 +27,42 @@ public function getValidCoercions(): iterable { yield [ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'], - new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ Vec\range(1, 10), - new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ Vec\range(1, 10), - new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ - Dict\map(Vec\range(1, 10), static fn(int $value): string => (string)$value), - new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + Dict\map(Vec\range(1, 10), static fn(int $value): string => (string) $value), + new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ - Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string)$key), - new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string) $key), + new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ Dict\map(Vec\range(1, 10), static fn(int $value): string => Str\format('00%d', $value)), - new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), - new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; } @@ -83,7 +83,7 @@ public function getToStringExamples(): iterable yield [Type\mutable_vector(Type\string()), 'Psl\Collection\MutableVectorInterface']; yield [ Type\mutable_vector(Type\instance_of(Iter\Iterator::class)), - 'Psl\Collection\MutableVectorInterface' + 'Psl\Collection\MutableVectorInterface', ]; } @@ -109,12 +109,16 @@ public static function provideAssertExceptionExpectations(): iterable yield 'invalid assertion value' => [ Type\mutable_vector(Type\int()), new Collection\MutableVector(['nope']), - 'Expected "' . MutableVectorInterface::class . '", got "string" at path "0".' + 'Expected "' . MutableVectorInterface::class . '", got "string" at path "0".', ]; yield 'nested' => [ Type\mutable_vector(Type\mutable_vector(Type\int())), new Collection\MutableVector([new Collection\MutableVector(['nope'])]), - 'Expected "' . MutableVectorInterface::class . '<' . MutableVectorInterface::class . '>", got "string" at path "0.0".', + 'Expected "' . + MutableVectorInterface::class . + '<' . + MutableVectorInterface::class . + '>", got "string" at path "0.0".', ]; } @@ -123,14 +127,14 @@ public static function provideCoerceExceptionExpectations(): iterable yield 'invalid coercion value' => [ Type\mutable_vector(Type\int()), ['nope'], - 'Could not coerce "string" to type "' . MutableVectorInterface::class . '" at path "0".' + 'Could not coerce "string" to type "' . MutableVectorInterface::class . '" at path "0".', ]; yield 'invalid iterator first item' => [ Type\mutable_vector(Type\int()), (static function () { yield Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "' . MutableVectorInterface::class . '" at path "first()".' + 'Could not coerce "string" to type "' . MutableVectorInterface::class . '" at path "first()".', ]; yield 'invalid iterator second item' => [ Type\mutable_vector(Type\int()), @@ -138,7 +142,7 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0; yield Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "' . MutableVectorInterface::class . '" at path "0.next()".' + 'Could not coerce "string" to type "' . MutableVectorInterface::class . '" at path "0.next()".', ]; yield 'iterator throwing exception' => [ Type\mutable_vector(Type\int()), @@ -146,30 +150,33 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0; throw new RuntimeException('whoops'); })(), - 'Could not coerce "null" to type "' . MutableVectorInterface::class . '" at path "0.next()": whoops.' + 'Could not coerce "null" to type "' . MutableVectorInterface::class . '" at path "0.next()": whoops.', ]; yield 'iterator yielding null key' => [ Type\mutable_vector(Type\int()), (static function () { yield null => 'nope'; })(), - 'Could not coerce "string" to type "' . MutableVectorInterface::class . '" at path "null".' + 'Could not coerce "string" to type "' . MutableVectorInterface::class . '" at path "null".', ]; yield 'iterator yielding object key' => [ Type\mutable_vector(Type\int()), (static function () { - yield (new class () { - }) => 'nope'; + yield new class() { + } => 'nope'; })(), - 'Could not coerce "string" to type "' . MutableVectorInterface::class . '" at path "class@anonymous".' + 'Could not coerce "string" to type "' . MutableVectorInterface::class . '" at path "class@anonymous".', ]; } /** * @dataProvider provideAssertExceptionExpectations */ - public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidAssertionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->assert($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\AssertException::class)); @@ -181,8 +188,11 @@ public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mix /** * @dataProvider provideCoerceExceptionExpectations */ - public function testInvalidCoercionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidCoercionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->coerce($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\CoercionException::class)); diff --git a/tests/unit/Type/NonEmptyDictTypeTest.php b/tests/unit/Type/NonEmptyDictTypeTest.php index f7b535a1..116058aa 100644 --- a/tests/unit/Type/NonEmptyDictTypeTest.php +++ b/tests/unit/Type/NonEmptyDictTypeTest.php @@ -26,12 +26,12 @@ public function getValidCoercions(): iterable { yield [ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'], - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ @@ -55,27 +55,21 @@ public function getValidCoercions(): iterable ]; yield [ - Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string)$key), - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string) $key), + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ - Dict\map( - Vec\range(1, 10), - static fn(int $value): string => Str\format('00%d', $value) - ), - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + Dict\map(Vec\range(1, 10), static fn(int $value): string => Str\format('00%d', $value)), + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ Dict\map_keys( - Dict\map( - Vec\range(1, 10), - static fn(int $value): string => Str\format('00%d', $value) - ), - static fn(int $key): string => Str\format('00%d', $key) + Dict\map(Vec\range(1, 10), static fn(int $value): string => Str\format('00%d', $value)), + static fn(int $key): string => Str\format('00%d', $key), ), - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; } @@ -98,7 +92,7 @@ public function getToStringExamples(): iterable yield [Type\non_empty_dict(Type\array_key(), Type\string()), 'non-empty-dict']; yield [ Type\non_empty_dict(Type\array_key(), Type\instance_of(Iter\Iterator::class)), - 'non-empty-dict' + 'non-empty-dict', ]; } @@ -107,16 +101,16 @@ public static function provideAssertExceptionExpectations(): iterable yield 'invalid assertion key' => [ Type\non_empty_dict(Type\int(), Type\int()), ['nope' => 1], - 'Expected "non-empty-dict", got "string" at path "key(nope)".' + 'Expected "non-empty-dict", got "string" at path "key(nope)".', ]; yield 'invalid assertion value' => [ Type\non_empty_dict(Type\int(), Type\int()), [0 => 'nope'], - 'Expected "non-empty-dict", got "string" at path "0".' + 'Expected "non-empty-dict", got "string" at path "0".', ]; yield 'nested' => [ Type\non_empty_dict(Type\int(), Type\non_empty_dict(Type\int(), Type\int())), - [0 => ['nope' => 'nope'],], + [0 => ['nope' => 'nope']], 'Expected "non-empty-dict>", got "string" at path "0.key(nope)".', ]; } @@ -126,19 +120,19 @@ public static function provideCoerceExceptionExpectations(): iterable yield 'invalid coercion key' => [ Type\non_empty_dict(Type\int(), Type\int()), ['nope' => 1], - 'Could not coerce "string" to type "non-empty-dict" at path "key(nope)".' + 'Could not coerce "string" to type "non-empty-dict" at path "key(nope)".', ]; yield 'invalid coercion value' => [ Type\non_empty_dict(Type\int(), Type\int()), [0 => 'nope'], - 'Could not coerce "string" to type "non-empty-dict" at path "0".' + 'Could not coerce "string" to type "non-empty-dict" at path "0".', ]; yield 'invalid iterator first item' => [ Type\non_empty_dict(Type\int(), Type\int()), (static function () { yield 0 => Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "non-empty-dict" at path "first()".' + 'Could not coerce "string" to type "non-empty-dict" at path "first()".', ]; yield 'invalid iterator second item' => [ Type\non_empty_dict(Type\int(), Type\int()), @@ -146,7 +140,7 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0 => 0; yield 1 => Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "non-empty-dict" at path "0.next()".' + 'Could not coerce "string" to type "non-empty-dict" at path "0.next()".', ]; yield 'iterator throwing exception' => [ Type\non_empty_dict(Type\int(), Type\int()), @@ -154,30 +148,33 @@ public static function provideCoerceExceptionExpectations(): iterable throw new RuntimeException('whoops'); yield; })(), - 'Could not coerce "null" to type "non-empty-dict" at path "first()": whoops.' + 'Could not coerce "null" to type "non-empty-dict" at path "first()": whoops.', ]; yield 'iterator yielding null key' => [ Type\non_empty_dict(Type\int(), Type\int()), (static function () { yield null => 'nope'; })(), - 'Could not coerce "null" to type "non-empty-dict" at path "key(null)".' + 'Could not coerce "null" to type "non-empty-dict" at path "key(null)".', ]; yield 'iterator yielding object key' => [ Type\non_empty_dict(Type\int(), Type\int()), (static function () { - yield (new class () { - }) => 'nope'; + yield new class() { + } => 'nope'; })(), - 'Could not coerce "class@anonymous" to type "non-empty-dict" at path "key(class@anonymous)".' + 'Could not coerce "class@anonymous" to type "non-empty-dict" at path "key(class@anonymous)".', ]; } /** * @dataProvider provideAssertExceptionExpectations */ - public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidAssertionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->assert($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\AssertException::class)); @@ -189,8 +186,11 @@ public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mix /** * @dataProvider provideCoerceExceptionExpectations */ - public function testInvalidCoercionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidCoercionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->coerce($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\CoercionException::class)); diff --git a/tests/unit/Type/NonEmptyVecTypeTest.php b/tests/unit/Type/NonEmptyVecTypeTest.php index 5022d444..4295cb3a 100644 --- a/tests/unit/Type/NonEmptyVecTypeTest.php +++ b/tests/unit/Type/NonEmptyVecTypeTest.php @@ -26,12 +26,12 @@ public function getValidCoercions(): iterable { yield [ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'], - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ @@ -55,18 +55,18 @@ public function getValidCoercions(): iterable ]; yield [ - Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string)$key), - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string) $key), + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ Dict\map(Vec\range(1, 10), static fn(int $value): string => Str\format('00%d', $value)), - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5], - [1, 2, 3, 4, 5] + [1, 2, 3, 4, 5], ]; } @@ -88,7 +88,7 @@ public function getToStringExamples(): iterable yield [Type\non_empty_vec(Type\string()), 'non-empty-vec']; yield [ Type\non_empty_vec(Type\instance_of(Iter\Iterator::class)), - 'non-empty-vec' + 'non-empty-vec', ]; } @@ -97,7 +97,7 @@ public static function provideAssertExceptionExpectations(): iterable yield 'invalid assertion value' => [ Type\vec(Type\int()), ['nope'], - 'Expected "vec", got "string" at path "0".' + 'Expected "vec", got "string" at path "0".', ]; yield 'nested' => [ Type\vec(Type\vec(Type\int())), @@ -111,14 +111,14 @@ public static function provideCoerceExceptionExpectations(): iterable yield 'invalid coercion value' => [ Type\vec(Type\int()), ['nope'], - 'Could not coerce "string" to type "vec" at path "0".' + 'Could not coerce "string" to type "vec" at path "0".', ]; yield 'invalid iterator first item' => [ Type\vec(Type\int()), (static function () { yield Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "vec" at path "first()".' + 'Could not coerce "string" to type "vec" at path "first()".', ]; yield 'invalid iterator second item' => [ Type\vec(Type\int()), @@ -126,7 +126,7 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0; yield Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "vec" at path "0.next()".' + 'Could not coerce "string" to type "vec" at path "0.next()".', ]; yield 'iterator throwing exception' => [ Type\vec(Type\int()), @@ -134,30 +134,33 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0; throw new RuntimeException('whoops'); })(), - 'Could not coerce "null" to type "vec" at path "0.next()": whoops.' + 'Could not coerce "null" to type "vec" at path "0.next()": whoops.', ]; yield 'iterator yielding null key' => [ Type\vec(Type\int()), (static function () { yield null => 'nope'; })(), - 'Could not coerce "string" to type "vec" at path "null".' + 'Could not coerce "string" to type "vec" at path "null".', ]; yield 'iterator yielding object key' => [ Type\vec(Type\int()), (static function () { - yield (new class () { - }) => 'nope'; + yield new class() { + } => 'nope'; })(), - 'Could not coerce "string" to type "vec" at path "class@anonymous".' + 'Could not coerce "string" to type "vec" at path "class@anonymous".', ]; } /** * @dataProvider provideAssertExceptionExpectations */ - public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidAssertionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->assert($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\AssertException::class)); @@ -169,8 +172,11 @@ public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mix /** * @dataProvider provideCoerceExceptionExpectations */ - public function testInvalidCoercionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidCoercionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->coerce($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\CoercionException::class)); diff --git a/tests/unit/Type/NumTypeTest.php b/tests/unit/Type/NumTypeTest.php index 92c6bf32..7d9cb4f4 100644 --- a/tests/unit/Type/NumTypeTest.php +++ b/tests/unit/Type/NumTypeTest.php @@ -44,8 +44,8 @@ public function getValidCoercions(): iterable yield ['3.', 3.0]; yield [$this->stringable('1.23'), 1.23]; yield [Math\INT64_MAX, Math\INT64_MAX]; - yield [(string)Math\INT64_MAX, Math\INT64_MAX]; - yield [$this->stringable((string)Math\INT64_MAX), Math\INT64_MAX]; + yield [(string) Math\INT64_MAX, Math\INT64_MAX]; + yield [$this->stringable((string) Math\INT64_MAX), Math\INT64_MAX]; yield ['9223372036854775808', 9223372036854775808.0]; yield ['007', 7]; yield ['-0.1', -0.1]; @@ -62,7 +62,7 @@ public function getInvalidCoercions(): iterable yield ['foo']; yield [null]; yield [false]; - yield [new class () { + yield [new class() { }]; yield [$this->stringable('foo')]; yield ['0xFF']; diff --git a/tests/unit/Type/ObjectTypeTest.php b/tests/unit/Type/ObjectTypeTest.php index b92fc84f..49ea9153 100644 --- a/tests/unit/Type/ObjectTypeTest.php +++ b/tests/unit/Type/ObjectTypeTest.php @@ -22,8 +22,11 @@ public function getValidCoercions(): iterable yield [$_ = new Collection\Map([1 => 'hey', 2 => 'hello']), $_]; yield [$_ = new Collection\MutableMap([1 => 'hey', 2 => 'hello']), $_]; yield [$_ = $this->createStub(CollectionInterface::class), $_]; - yield [$_ = new class { - }, $_]; + yield [ + $_ = new class { + }, + $_, + ]; } public function getInvalidCoercions(): iterable diff --git a/tests/unit/Type/PositiveIntTypeTest.php b/tests/unit/Type/PositiveIntTypeTest.php index e7e1b427..19ab6409 100644 --- a/tests/unit/Type/PositiveIntTypeTest.php +++ b/tests/unit/Type/PositiveIntTypeTest.php @@ -34,7 +34,6 @@ public function getValidCoercions(): iterable public function getInvalidCoercions(): iterable { - yield [0]; yield ['0']; yield ['-321']; diff --git a/tests/unit/Type/ScalarTypeTest.php b/tests/unit/Type/ScalarTypeTest.php index dd2c1cc6..008c64ff 100644 --- a/tests/unit/Type/ScalarTypeTest.php +++ b/tests/unit/Type/ScalarTypeTest.php @@ -55,7 +55,7 @@ public function getInvalidCoercions(): iterable }]; yield [STDIN]; yield [[]]; - yield [(static fn () => yield 'hello')()]; + yield [(static fn() => yield 'hello')()]; } public function getToStringExamples(): iterable diff --git a/tests/unit/Type/SetTypeTest.php b/tests/unit/Type/SetTypeTest.php index 520857df..13218cc6 100644 --- a/tests/unit/Type/SetTypeTest.php +++ b/tests/unit/Type/SetTypeTest.php @@ -24,40 +24,39 @@ public function getType(): Type\TypeInterface public function getValidCoercions(): iterable { - yield [ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - new Collection\Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], - new Collection\Set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) + new Collection\Set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), ]; yield [ Vec\range(1, 10), - new Collection\Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ - Dict\map(Vec\range(1, 10), static fn(int $key): string => (string)$key), - new Collection\Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + Dict\map(Vec\range(1, 10), static fn(int $key): string => (string) $key), + new Collection\Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ new Collection\Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), - new Collection\Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ new Collection\MutableSet([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), - new Collection\Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ new Collection\MutableVector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), - new Collection\Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\Set([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; } @@ -100,12 +99,12 @@ public static function provideAssertExceptionExpectations(): iterable yield 'invalid assertion value' => [ Type\set(Type\int()), new Collection\MutableSet(['foo' => 'nope']), - 'Expected "' . SetInterface::class . '", got "string" at path "nope".' + 'Expected "' . SetInterface::class . '", got "string" at path "nope".', ]; yield 'nested' => [ Type\set(Type\string()), new Collection\MutableSet([1 => 123]), - 'Expected "' . SetInterface::class . '", got "int" at path "123".' + 'Expected "' . SetInterface::class . '", got "int" at path "123".', ]; } @@ -114,14 +113,14 @@ public static function provideCoerceExceptionExpectations(): iterable yield 'invalid coercion value' => [ Type\set(Type\int()), ['nope' => 'nope'], - 'Could not coerce "string" to type "' . SetInterface::class . '" at path "nope".' + 'Could not coerce "string" to type "' . SetInterface::class . '" at path "nope".', ]; yield 'invalid iterator first item' => [ Type\set(Type\int()), (static function () { yield Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "' . SetInterface::class . '" at path "first()".' + 'Could not coerce "string" to type "' . SetInterface::class . '" at path "first()".', ]; yield 'invalid iterator second item' => [ Type\set(Type\int()), @@ -129,7 +128,7 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0; yield Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "' . SetInterface::class . '" at path "0.next()".' + 'Could not coerce "string" to type "' . SetInterface::class . '" at path "0.next()".', ]; yield 'iterator throwing exception' => [ Type\set(Type\int()), @@ -137,37 +136,40 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0; throw new RuntimeException('whoops'); })(), - 'Could not coerce "null" to type "' . SetInterface::class . '" at path "0.next()": whoops.' + 'Could not coerce "null" to type "' . SetInterface::class . '" at path "0.next()": whoops.', ]; yield 'iterator yielding null key' => [ Type\set(Type\int()), (static function () { yield null => 'nope'; })(), - 'Could not coerce "string" to type "' . SetInterface::class . '" at path "null".' + 'Could not coerce "string" to type "' . SetInterface::class . '" at path "null".', ]; yield 'iterator yielding string key, null value' => [ Type\set(Type\int()), (static function () { yield 'nope' => 'bar'; })(), - 'Could not coerce "string" to type "' . SetInterface::class . '" at path "nope".' + 'Could not coerce "string" to type "' . SetInterface::class . '" at path "nope".', ]; yield 'iterator yielding object key' => [ Type\set(Type\int()), (static function () { - yield 'nope' => (new class () { - }); + yield 'nope' => new class() { + }; })(), - 'Could not coerce "class@anonymous" to type "' . SetInterface::class . '" at path "nope".' + 'Could not coerce "class@anonymous" to type "' . SetInterface::class . '" at path "nope".', ]; } /** * @dataProvider provideAssertExceptionExpectations */ - public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidAssertionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->assert($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\AssertException::class)); @@ -179,8 +181,11 @@ public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mix /** * @dataProvider provideCoerceExceptionExpectations */ - public function testInvalidCoercionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidCoercionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->coerce($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\CoercionException::class)); diff --git a/tests/unit/Type/ShapeAllowUnknownFieldsTypeTest.php b/tests/unit/Type/ShapeAllowUnknownFieldsTypeTest.php index 29310011..0b84c33f 100644 --- a/tests/unit/Type/ShapeAllowUnknownFieldsTypeTest.php +++ b/tests/unit/Type/ShapeAllowUnknownFieldsTypeTest.php @@ -15,75 +15,102 @@ final class ShapeAllowUnknownFieldsTypeTest extends TypeTest { public function getType(): Type\TypeInterface { - return Type\shape([ - 'name' => Type\string(), - 'articles' => Type\vec(Type\shape([ - 'title' => Type\string(), - 'content' => Type\string(), - 'likes' => Type\int(), - 'comments' => Type\optional(Type\vec(Type\shape([ - 'user' => Type\string(), - 'comment' => Type\string() - ]))), - ])) - ], true); + return Type\shape( + [ + 'name' => Type\string(), + 'articles' => Type\vec(Type\shape([ + 'title' => Type\string(), + 'content' => Type\string(), + 'likes' => Type\int(), + 'comments' => Type\optional(Type\vec(Type\shape([ + 'user' => Type\string(), + 'comment' => Type\string(), + ]))), + ])), + ], + true, + ); } public function getValidCoercions(): iterable { yield [ ['name' => 'saif', 'articles' => new Collection\Vector([])], - ['name' => 'saif', 'articles' => []] + ['name' => 'saif', 'articles' => []], ]; yield [ - ['name' => 'saif', 'email' => 'azjezz@example.com', 'articles' => new Collection\Vector([ - ['title' => 'Foo', 'content' => 'Baz', 'likes' => 0], - ])], - + [ + 'name' => 'saif', + 'email' => 'azjezz@example.com', + 'articles' => new Collection\Vector([['title' => 'Foo', 'content' => 'Baz', 'likes' => 0]]), + ], // unknown fields are always last. - ['name' => 'saif', 'articles' => [ - ['title' => 'Foo', 'content' => 'Baz', 'likes' => 0], - ], 'email' => 'azjezz@example.com'] + [ + 'name' => 'saif', + 'articles' => [['title' => 'Foo', 'content' => 'Baz', 'likes' => 0]], + 'email' => 'azjezz@example.com', + ], ]; yield [ - ['name' => 'saif', 'articles' => new Collection\Vector([ - ['title' => 'Foo', 'content' => 'Baz', 'likes' => 0], - ])], - ['name' => 'saif', 'articles' => [ - ['title' => 'Foo', 'content' => 'Baz', 'likes' => 0], - ]] + [ + 'name' => 'saif', + 'articles' => new Collection\Vector([['title' => 'Foo', 'content' => 'Baz', 'likes' => 0]]), + ], + ['name' => 'saif', 'articles' => [['title' => 'Foo', 'content' => 'Baz', 'likes' => 0]]], ]; yield [ - ['name' => 'saif', 'articles' => new Collection\Vector([ - ['title' => 'Foo', 'content' => 'Baz', 'likes' => 0], - ['title' => 'Bar', 'content' => 'Qux', 'likes' => 0, 'comments' => [ - ['user' => 'a', 'comment' => 'hello'], - ['user' => 'b', 'comment' => 'hey'], - ['user' => 'c', 'comment' => 'hi'], - ]], - ])], - ['name' => 'saif', 'articles' => [ - ['title' => 'Foo', 'content' => 'Baz', 'likes' => 0], - ['title' => 'Bar', 'content' => 'Qux', 'likes' => 0, 'comments' => [ - ['user' => 'a', 'comment' => 'hello'], - ['user' => 'b', 'comment' => 'hey'], - ['user' => 'c', 'comment' => 'hi'], - ]], - ]], + [ + 'name' => 'saif', + 'articles' => new Collection\Vector([ + ['title' => 'Foo', 'content' => 'Baz', 'likes' => 0], + [ + 'title' => 'Bar', + 'content' => 'Qux', + 'likes' => 0, + 'comments' => [ + ['user' => 'a', 'comment' => 'hello'], + ['user' => 'b', 'comment' => 'hey'], + ['user' => 'c', 'comment' => 'hi'], + ], + ], + ]), + ], + [ + 'name' => 'saif', + 'articles' => [ + ['title' => 'Foo', 'content' => 'Baz', 'likes' => 0], + [ + 'title' => 'Bar', + 'content' => 'Qux', + 'likes' => 0, + 'comments' => [ + ['user' => 'a', 'comment' => 'hello'], + ['user' => 'b', 'comment' => 'hey'], + ['user' => 'c', 'comment' => 'hi'], + ], + ], + ], + ], ]; yield [ - ['name' => 'saif', 'articles' => new Collection\Vector([ - ['title' => 'Foo', 'content' => 'Bar', 'likes' => 0], - ['title' => 'Baz', 'content' => 'Qux', 'likes' => 13], - ])], - ['name' => 'saif', 'articles' => [ - ['title' => 'Foo', 'content' => 'Bar', 'likes' => 0], - ['title' => 'Baz', 'content' => 'Qux', 'likes' => 13], - ]], + [ + 'name' => 'saif', + 'articles' => new Collection\Vector([ + ['title' => 'Foo', 'content' => 'Bar', 'likes' => 0], + ['title' => 'Baz', 'content' => 'Qux', 'likes' => 13], + ]), + ], + [ + 'name' => 'saif', + 'articles' => [ + ['title' => 'Foo', 'content' => 'Bar', 'likes' => 0], + ['title' => 'Baz', 'content' => 'Qux', 'likes' => 13], + ], + ], ]; } @@ -99,12 +126,18 @@ public function getInvalidCoercions(): iterable yield [['name' => 'saif', 'articles' => 5]]; yield [['name' => 'saif', 'baz' => []]]; yield [['name' => 'saif', 'baz' => []]]; - yield [['name' => 'saif', 'articles' => [ - ['title' => 'biz'] // missing 'content' and 'likes' - ]]]; - yield [['name' => 'saif', 'articles' => [ - ['title' => 'biz', 'content' => 'foo', 'upvotes'] // 'likes' replaced by 'upvotes' - ]]]; + yield [[ + 'name' => 'saif', + 'articles' => [ + ['title' => 'biz'], // missing 'content' and 'likes' + ], + ]]; + yield [[ + 'name' => 'saif', + 'articles' => [ + ['title' => 'biz', 'content' => 'foo', 'upvotes'], // 'likes' replaced by 'upvotes' + ], + ]]; } public function getToStringExamples(): iterable @@ -116,11 +149,11 @@ public function getToStringExamples(): iterable "'content': string, " . "'likes': int, " . "'comments'?: vec" . - "}>}" + '}>}', ]; yield [ Type\shape([Type\int(), Type\string()]), - 'array{0: int, 1: string}' + 'array{0: int, 1: string}', ]; } diff --git a/tests/unit/Type/ShapeTypeTest.php b/tests/unit/Type/ShapeTypeTest.php index ac6a2339..e344d7ce 100644 --- a/tests/unit/Type/ShapeTypeTest.php +++ b/tests/unit/Type/ShapeTypeTest.php @@ -26,26 +26,25 @@ public function getType(): Type\TypeInterface 'likes' => Type\int(), 'comments' => Type\optional(Type\vec(Type\shape([ 'user' => Type\string(), - 'comment' => Type\string() + 'comment' => Type\string(), ]))), - ])) + ])), ]); } public function testWillConsiderUnknownIterableFieldsWhenCoercing(): void { - static::assertEquals( + static::assertSame( [ 'defined_key' => 'value', 'additional_key' => 'value', ], - Type\shape([ - 'defined_key' => Type\mixed(), - ], true) - ->coerce(new ArrayIterator([ + Type\shape(['defined_key' => Type\mixed()], true)->coerce( + new ArrayIterator([ 'defined_key' => 'value', 'additional_key' => 'value', - ])) + ]), + ), ); } @@ -55,7 +54,7 @@ public function getValidCoercions(): iterable yield $row; yield [ new ArrayIterator($row[0]), - $row[1] + $row[1], ]; } } @@ -67,68 +66,101 @@ private function validCoercions(): iterable { yield [ ['name' => 'saif', 'articles' => new Collection\Vector([])], - ['name' => 'saif', 'articles' => []] + ['name' => 'saif', 'articles' => []], ]; yield [ - ['name' => 'saif', 'articles' => new Collection\Vector([ - ['title' => 'Foo', 'content' => 'Baz', 'likes' => 0], - ])], - ['name' => 'saif', 'articles' => [ - ['title' => 'Foo', 'content' => 'Baz', 'likes' => 0], - ]] + [ + 'name' => 'saif', + 'articles' => new Collection\Vector([['title' => 'Foo', 'content' => 'Baz', 'likes' => 0]]), + ], + ['name' => 'saif', 'articles' => [['title' => 'Foo', 'content' => 'Baz', 'likes' => 0]]], ]; yield [ - ['name' => 'saif', 'articles' => new Collection\Vector([ - ['title' => 'Foo', 'content' => 'Baz', 'likes' => 0], - ['title' => 'Bar', 'content' => 'Qux', 'likes' => 0, 'comments' => [ - ['user' => 'a', 'comment' => 'hello'], - ['user' => 'b', 'comment' => 'hey'], - ['user' => 'c', 'comment' => 'hi'], - ]], - ])], - ['name' => 'saif', 'articles' => [ - ['title' => 'Foo', 'content' => 'Baz', 'likes' => 0], - ['title' => 'Bar', 'content' => 'Qux', 'likes' => 0, 'comments' => [ - ['user' => 'a', 'comment' => 'hello'], - ['user' => 'b', 'comment' => 'hey'], - ['user' => 'c', 'comment' => 'hi'], - ]], - ]], + [ + 'name' => 'saif', + 'articles' => new Collection\Vector([ + ['title' => 'Foo', 'content' => 'Baz', 'likes' => 0], + [ + 'title' => 'Bar', + 'content' => 'Qux', + 'likes' => 0, + 'comments' => [ + ['user' => 'a', 'comment' => 'hello'], + ['user' => 'b', 'comment' => 'hey'], + ['user' => 'c', 'comment' => 'hi'], + ], + ], + ]), + ], + [ + 'name' => 'saif', + 'articles' => [ + ['title' => 'Foo', 'content' => 'Baz', 'likes' => 0], + [ + 'title' => 'Bar', + 'content' => 'Qux', + 'likes' => 0, + 'comments' => [ + ['user' => 'a', 'comment' => 'hello'], + ['user' => 'b', 'comment' => 'hey'], + ['user' => 'c', 'comment' => 'hi'], + ], + ], + ], + ], ]; yield [ - ['name' => 'saif', 'articles' => new Collection\Vector([ - ['title' => 'Foo', 'content' => 'Bar', 'likes' => 0], - ['title' => 'Baz', 'content' => 'Qux', 'likes' => 13], - ])], - ['name' => 'saif', 'articles' => [ - ['title' => 'Foo', 'content' => 'Bar', 'likes' => 0], - ['title' => 'Baz', 'content' => 'Qux', 'likes' => 13], - ]], + [ + 'name' => 'saif', + 'articles' => new Collection\Vector([ + ['title' => 'Foo', 'content' => 'Bar', 'likes' => 0], + ['title' => 'Baz', 'content' => 'Qux', 'likes' => 13], + ]), + ], + [ + 'name' => 'saif', + 'articles' => [ + ['title' => 'Foo', 'content' => 'Bar', 'likes' => 0], + ['title' => 'Baz', 'content' => 'Qux', 'likes' => 13], + ], + ], ]; yield 'stdClass containing a valid shape' => [ - (object) ['name' => 'saif', 'articles' => new Collection\Vector([ - ['title' => 'Foo', 'content' => 'Bar', 'likes' => 0, 'dislikes' => 5], - ['title' => 'Baz', 'content' => 'Qux', 'likes' => 13, 'dislikes' => 3], - ])], - ['name' => 'saif', 'articles' => [ - ['title' => 'Foo', 'content' => 'Bar', 'likes' => 0], - ['title' => 'Baz', 'content' => 'Qux', 'likes' => 13], - ]], + (object) [ + 'name' => 'saif', + 'articles' => new Collection\Vector([ + ['title' => 'Foo', 'content' => 'Bar', 'likes' => 0, 'dislikes' => 5], + ['title' => 'Baz', 'content' => 'Qux', 'likes' => 13, 'dislikes' => 3], + ]), + ], + [ + 'name' => 'saif', + 'articles' => [ + ['title' => 'Foo', 'content' => 'Bar', 'likes' => 0], + ['title' => 'Baz', 'content' => 'Qux', 'likes' => 13], + ], + ], ]; yield [ - ['name' => 'saif', 'articles' => new Collection\Vector([ - ['title' => 'Foo', 'content' => 'Bar', 'likes' => 0, 'dislikes' => 5], - ['title' => 'Baz', 'content' => 'Qux', 'likes' => 13, 'dislikes' => 3], - ])], - ['name' => 'saif', 'articles' => [ - ['title' => 'Foo', 'content' => 'Bar', 'likes' => 0], - ['title' => 'Baz', 'content' => 'Qux', 'likes' => 13], - ]], + [ + 'name' => 'saif', + 'articles' => new Collection\Vector([ + ['title' => 'Foo', 'content' => 'Bar', 'likes' => 0, 'dislikes' => 5], + ['title' => 'Baz', 'content' => 'Qux', 'likes' => 13, 'dislikes' => 3], + ]), + ], + [ + 'name' => 'saif', + 'articles' => [ + ['title' => 'Foo', 'content' => 'Bar', 'likes' => 0], + ['title' => 'Baz', 'content' => 'Qux', 'likes' => 13], + ], + ], ]; } @@ -144,15 +176,24 @@ public function getInvalidCoercions(): iterable yield [['name' => 'saif', 'articles' => 5]]; yield [['name' => 'saif', 'baz' => []]]; yield [['name' => 'saif', 'baz' => []]]; - yield [['name' => 'saif', 'articles' => [ - ['title' => 'biz'] // missing 'content' and 'likes' - ]]]; - yield [['name' => 'saif', 'articles' => [ - ['title' => 'biz', 'content' => 'foo', 'upvotes' => 4] // 'likes' replaced by 'upvotes' - ]]]; - yield [(object) ['name' => 'saif', 'articles' => [ - ['title' => 'biz', 'content' => 'foo', 'upvotes' => 4] // 'likes' replaced by 'upvotes' - ]]]; + yield [[ + 'name' => 'saif', + 'articles' => [ + ['title' => 'biz'], // missing 'content' and 'likes' + ], + ]]; + yield [[ + 'name' => 'saif', + 'articles' => [ + ['title' => 'biz', 'content' => 'foo', 'upvotes' => 4], // 'likes' replaced by 'upvotes' + ], + ]]; + yield [(object) [ + 'name' => 'saif', + 'articles' => [ + ['title' => 'biz', 'content' => 'foo', 'upvotes' => 4], // 'likes' replaced by 'upvotes' + ], + ]]; } public function getToStringExamples(): iterable @@ -160,15 +201,15 @@ public function getToStringExamples(): iterable yield [ $this->getType(), "array{'name': string, 'articles': vec" . - "}>}" + "'title': string, " . + "'content': string, " . + "'likes': int, " . + "'comments'?: vec" . + '}>}', ]; yield [ Type\shape([Type\int(), Type\string()]), - 'array{0: int, 1: string}' + 'array{0: int, 1: string}', ]; } @@ -202,40 +243,28 @@ protected function equals($a, $b): bool public static function provideAssertExceptionExpectations(): iterable { yield 'extra key' => [ - Type\shape([ - 'name' => Type\string(), - ]), + Type\shape(['name' => Type\string()]), [ 'name' => 'saif', 'extra' => 123, ], - 'Expected "array{\'name\': string}", got "int" at path "extra".' + 'Expected "array{\'name\': string}", got "int" at path "extra".', ]; yield 'missing key' => [ - Type\shape([ - 'name' => Type\string(), - ]), + Type\shape(['name' => Type\string()]), [], - 'Expected "array{\'name\': string}", got "null" at path "name".' + 'Expected "array{\'name\': string}", got "null" at path "name".', ]; yield 'invalid key' => [ - Type\shape([ - 'name' => Type\string(), - ]), + Type\shape(['name' => Type\string()]), ['name' => 123], - 'Expected "array{\'name\': string}", got "int" at path "name".' + 'Expected "array{\'name\': string}", got "int" at path "name".', ]; yield 'nested' => [ - Type\shape([ - 'item' => Type\shape([ - 'name' => Type\string(), - ]), - ]), - [ - 'item' => [ - 'name' => 123, - ] - ], + Type\shape(['item' => Type\shape(['name' => Type\string()])]), + ['item' => [ + 'name' => 123, + ]], 'Expected "array{\'item\': array{\'name\': string}}", got "int" at path "item.name".', ]; } @@ -243,77 +272,64 @@ public static function provideAssertExceptionExpectations(): iterable public static function provideCoerceExceptionExpectations(): iterable { yield 'missing key' => [ - Type\shape([ - 'name' => Type\string(), - ]), + Type\shape(['name' => Type\string()]), [], - 'Could not coerce "null" to type "array{\'name\': string}" at path "name".' + 'Could not coerce "null" to type "array{\'name\': string}" at path "name".', ]; yield 'invalid key' => [ - Type\shape([ - 'name' => Type\string(), - ]), - [ - 'name' => new class () { - }, - ], + Type\shape(['name' => Type\string()]), + ['name' => new class() { + }], 'Could not coerce "class@anonymous" to type "array{\'name\': string}" at path "name".', ]; yield 'invalid iterator first item' => [ - Type\shape([ - 'id' => Type\int(), - ]), + Type\shape(['id' => Type\int()]), (static function () { yield 'id' => Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "array{\'id\': int}" at path "first()".' + 'Could not coerce "string" to type "array{\'id\': int}" at path "first()".', ]; yield 'invalid iterator second item' => [ - Type\shape([ - 'id' => Type\int(), - ]), + Type\shape(['id' => Type\int()]), (static function () { yield 'id' => 1; yield 'next' => Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "array{\'id\': int}" at path "id.next()".' + 'Could not coerce "string" to type "array{\'id\': int}" at path "id.next()".', ]; yield 'iterator throwing exception' => [ - Type\shape([ - 'id' => Type\int(), - ]), + Type\shape(['id' => Type\int()]), (static function () { throw new RuntimeException('whoops'); yield; })(), - 'Could not coerce "null" to type "array{\'id\': int}" at path "first()": whoops.' + 'Could not coerce "null" to type "array{\'id\': int}" at path "first()": whoops.', ]; yield 'iterator yielding null key' => [ - Type\shape([ - 'id' => Type\int(), - ]), + Type\shape(['id' => Type\int()]), (static function () { yield null => 'nope'; })(), - 'Could not coerce "null" to type "array{\'id\': int}" at path "id".' + 'Could not coerce "null" to type "array{\'id\': int}" at path "id".', ]; yield 'iterator yielding object key' => [ - Type\shape([ - 'id' => Type\int(), - ]), + Type\shape(['id' => Type\int()]), (static function () { - yield (new class () { - }) => 'nope'; + yield new class() { + } => 'nope'; })(), - 'Could not coerce "null" to type "array{\'id\': int}" at path "id".' + 'Could not coerce "null" to type "array{\'id\': int}" at path "id".', ]; } /** * @dataProvider provideAssertExceptionExpectations */ - public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidAssertionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->assert($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\AssertException::class)); @@ -325,8 +341,11 @@ public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mix /** * @dataProvider provideCoerceExceptionExpectations */ - public function testInvalidCoercionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidCoercionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->coerce($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\CoercionException::class)); diff --git a/tests/unit/Type/StringBackedEnumTypeTest.php b/tests/unit/Type/StringBackedEnumTypeTest.php index f78e88ae..b7c7d57f 100644 --- a/tests/unit/Type/StringBackedEnumTypeTest.php +++ b/tests/unit/Type/StringBackedEnumTypeTest.php @@ -17,7 +17,7 @@ public function getType(): Type\TypeInterface { return Type\backed_enum(StringEnum::class); } - + /** * @return iterable */ diff --git a/tests/unit/Type/TypeTest.php b/tests/unit/Type/TypeTest.php index 4a0a1e33..f6c0e5e1 100644 --- a/tests/unit/Type/TypeTest.php +++ b/tests/unit/Type/TypeTest.php @@ -43,7 +43,7 @@ abstract public function getToStringExamples(): iterable; public function getValidValues(): array { $non_unique = $this->getValidCoercions(); - $non_unique = Dict\map($non_unique, static fn ($tuple) => $tuple[1]); + $non_unique = Dict\map($non_unique, static fn($tuple) => $tuple[1]); $out = []; foreach ($non_unique as $v) { @@ -120,7 +120,7 @@ public function testInvalidCoercion($value): void $this->expectException(CoercionException::class); try { - $ret = $this->getType()->coerce($value); + $ret = $this->getType()->coerce($value); } catch (CoercionException $e) { throw $e; } @@ -165,7 +165,7 @@ protected function equals($a, $b): bool protected function stringable(string $value): object { - return new class ($value) { + return new class($value) { private string $value; public function __construct(string $value) diff --git a/tests/unit/Type/UnionTypeTest.php b/tests/unit/Type/UnionTypeTest.php index 4791ba7e..7840c554 100644 --- a/tests/unit/Type/UnionTypeTest.php +++ b/tests/unit/Type/UnionTypeTest.php @@ -47,21 +47,21 @@ public function getToStringExamples(): iterable Type\bool(), Type\intersection( Type\instance_of(IndexAccessInterface::class), - Type\instance_of(CollectionInterface::class) - ) + Type\instance_of(CollectionInterface::class), + ), ), - 'bool|(Psl\Collection\IndexAccessInterface&Psl\Collection\CollectionInterface)' + 'bool|(Psl\Collection\IndexAccessInterface&Psl\Collection\CollectionInterface)', ]; yield [ Type\union( Type\intersection( Type\instance_of(IndexAccessInterface::class), - Type\instance_of(CollectionInterface::class) + Type\instance_of(CollectionInterface::class), ), Type\bool(), - Type\non_empty_string() + Type\non_empty_string(), ), - '((Psl\Collection\IndexAccessInterface&Psl\Collection\CollectionInterface)|bool)|non-empty-string' + '((Psl\Collection\IndexAccessInterface&Psl\Collection\CollectionInterface)|bool)|non-empty-string', ]; yield [ Type\union( @@ -71,7 +71,7 @@ public function getToStringExamples(): iterable Type\literal_scalar('still'), Type\literal_scalar('alive'), ), - 'null|vec|"php"|"still"|"alive"' + 'null|vec|"php"|"still"|"alive"', ]; } diff --git a/tests/unit/Type/VecTypeTest.php b/tests/unit/Type/VecTypeTest.php index d316ab15..18cf08d0 100644 --- a/tests/unit/Type/VecTypeTest.php +++ b/tests/unit/Type/VecTypeTest.php @@ -21,17 +21,17 @@ public function getValidCoercions(): iterable { yield [ [], - [] + [], ]; yield [ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'], - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ @@ -55,18 +55,18 @@ public function getValidCoercions(): iterable ]; yield [ - Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string)$key), - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string) $key), + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ Dict\map(Vec\range(1, 10), static fn(int $value): string => Str\format('00%d', $value)), - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]; yield [ ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5], - [1, 2, 3, 4, 5] + [1, 2, 3, 4, 5], ]; } @@ -87,7 +87,7 @@ public function getToStringExamples(): iterable yield [Type\vec(Type\string()), 'vec']; yield [ Type\vec(Type\instance_of(Iter\Iterator::class)), - 'vec' + 'vec', ]; } @@ -101,7 +101,7 @@ public static function provideAssertExceptionExpectations(): iterable yield 'invalid assertion value' => [ Type\vec(Type\int()), ['nope'], - 'Expected "vec", got "string" at path "0".' + 'Expected "vec", got "string" at path "0".', ]; yield 'nested' => [ Type\vec(Type\vec(Type\int())), @@ -115,14 +115,14 @@ public static function provideCoerceExceptionExpectations(): iterable yield 'invalid coercion value' => [ Type\vec(Type\int()), ['nope'], - 'Could not coerce "string" to type "vec" at path "0".' + 'Could not coerce "string" to type "vec" at path "0".', ]; yield 'invalid iterator first item' => [ Type\vec(Type\int()), (static function () { yield Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "vec" at path "first()".' + 'Could not coerce "string" to type "vec" at path "first()".', ]; yield 'invalid iterator second item' => [ Type\vec(Type\int()), @@ -130,7 +130,7 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0; yield Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "vec" at path "0.next()".' + 'Could not coerce "string" to type "vec" at path "0.next()".', ]; yield 'iterator throwing exception' => [ Type\vec(Type\int()), @@ -138,30 +138,33 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0; throw new RuntimeException('whoops'); })(), - 'Could not coerce "null" to type "vec" at path "0.next()": whoops.' + 'Could not coerce "null" to type "vec" at path "0.next()": whoops.', ]; yield 'iterator yielding null key' => [ Type\vec(Type\int()), (static function () { yield null => 'nope'; })(), - 'Could not coerce "string" to type "vec" at path "null".' + 'Could not coerce "string" to type "vec" at path "null".', ]; yield 'iterator yielding object key' => [ Type\vec(Type\int()), (static function () { - yield (new class () { - }) => 'nope'; + yield new class() { + } => 'nope'; })(), - 'Could not coerce "string" to type "vec" at path "class@anonymous".' + 'Could not coerce "string" to type "vec" at path "class@anonymous".', ]; } /** * @dataProvider provideAssertExceptionExpectations */ - public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidAssertionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->assert($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\AssertException::class)); @@ -173,8 +176,11 @@ public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mix /** * @dataProvider provideCoerceExceptionExpectations */ - public function testInvalidCoercionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidCoercionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->coerce($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\CoercionException::class)); diff --git a/tests/unit/Type/VectorTypeTest.php b/tests/unit/Type/VectorTypeTest.php index 9cf15945..800fefa3 100644 --- a/tests/unit/Type/VectorTypeTest.php +++ b/tests/unit/Type/VectorTypeTest.php @@ -27,42 +27,42 @@ public function getValidCoercions(): iterable { yield [ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'], - new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ Vec\range(1, 10), - new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ Vec\range(1, 10), - new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ - Dict\map(Vec\range(1, 10), static fn(int $value): string => (string)$value), - new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + Dict\map(Vec\range(1, 10), static fn(int $value): string => (string) $value), + new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ - Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string)$key), - new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + Dict\map_keys(Vec\range(1, 10), static fn(int $key): string => (string) $key), + new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ Dict\map(Vec\range(1, 10), static fn(int $value): string => Str\format('00%d', $value)), - new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; yield [ new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), - new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + new Collection\Vector([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ]; } @@ -83,7 +83,7 @@ public function getToStringExamples(): iterable yield [Type\vector(Type\string()), 'Psl\Collection\VectorInterface']; yield [ Type\vector(Type\instance_of(Iter\Iterator::class)), - 'Psl\Collection\VectorInterface' + 'Psl\Collection\VectorInterface', ]; } @@ -109,12 +109,16 @@ public static function provideAssertExceptionExpectations(): iterable yield 'invalid assertion value' => [ Type\vector(Type\int()), new Collection\MutableVector(['nope']), - 'Expected "' . VectorInterface::class . '", got "string" at path "0".' + 'Expected "' . VectorInterface::class . '", got "string" at path "0".', ]; yield 'nested' => [ Type\vector(Type\vector(Type\int())), new Collection\MutableVector([new Collection\MutableVector(['nope'])]), - 'Expected "' . VectorInterface::class . '<' . VectorInterface::class . '>", got "string" at path "0.0".', + 'Expected "' . + VectorInterface::class . + '<' . + VectorInterface::class . + '>", got "string" at path "0.0".', ]; } @@ -123,14 +127,14 @@ public static function provideCoerceExceptionExpectations(): iterable yield 'invalid coercion value' => [ Type\vector(Type\int()), ['nope'], - 'Could not coerce "string" to type "' . VectorInterface::class . '" at path "0".' + 'Could not coerce "string" to type "' . VectorInterface::class . '" at path "0".', ]; yield 'invalid iterator first item' => [ Type\vector(Type\int()), (static function () { yield Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "' . VectorInterface::class . '" at path "first()".' + 'Could not coerce "string" to type "' . VectorInterface::class . '" at path "first()".', ]; yield 'invalid iterator second item' => [ Type\vector(Type\int()), @@ -138,7 +142,7 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0; yield Type\int()->coerce('nope'); })(), - 'Could not coerce "string" to type "' . VectorInterface::class . '" at path "0.next()".' + 'Could not coerce "string" to type "' . VectorInterface::class . '" at path "0.next()".', ]; yield 'iterator throwing exception' => [ Type\vector(Type\int()), @@ -146,30 +150,33 @@ public static function provideCoerceExceptionExpectations(): iterable yield 0; throw new RuntimeException('whoops'); })(), - 'Could not coerce "null" to type "' . VectorInterface::class . '" at path "0.next()": whoops.' + 'Could not coerce "null" to type "' . VectorInterface::class . '" at path "0.next()": whoops.', ]; yield 'iterator yielding null key' => [ Type\vector(Type\int()), (static function () { yield null => 'nope'; })(), - 'Could not coerce "string" to type "' . VectorInterface::class . '" at path "null".' + 'Could not coerce "string" to type "' . VectorInterface::class . '" at path "null".', ]; yield 'iterator yielding object key' => [ Type\vector(Type\int()), (static function () { - yield (new class () { - }) => 'nope'; + yield new class() { + } => 'nope'; })(), - 'Could not coerce "string" to type "' . VectorInterface::class . '" at path "class@anonymous".' + 'Could not coerce "string" to type "' . VectorInterface::class . '" at path "class@anonymous".', ]; } /** * @dataProvider provideAssertExceptionExpectations */ - public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidAssertionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->assert($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\AssertException::class)); @@ -181,8 +188,11 @@ public function testInvalidAssertionTypeExceptions(Type\TypeInterface $type, mix /** * @dataProvider provideCoerceExceptionExpectations */ - public function testInvalidCoercionTypeExceptions(Type\TypeInterface $type, mixed $data, string $expectedMessage): void - { + public function testInvalidCoercionTypeExceptions( + Type\TypeInterface $type, + mixed $data, + string $expectedMessage, + ): void { try { $type->coerce($data); static::fail(Str\format('Expected "%s" exception to be thrown.', Type\Exception\CoercionException::class)); diff --git a/tests/unit/Unix/ConnectTest.php b/tests/unit/Unix/ConnectTest.php index 8235b7e3..cb9a7498 100644 --- a/tests/unit/Unix/ConnectTest.php +++ b/tests/unit/Unix/ConnectTest.php @@ -19,7 +19,7 @@ public function testConnect(): void static::markTestSkipped('Unix Server is not supported on Windows platform.'); } - $sock = Filesystem\create_temporary_file(prefix: 'psl-examples') . ".sock"; + $sock = Filesystem\create_temporary_file(prefix: 'psl-examples') . '.sock'; Async\concurrently([ 'server' => static function () use ($sock): void { @@ -34,7 +34,7 @@ public function testConnect(): void }, 'client' => static function () use ($sock): void { $client = Unix\connect($sock); - self::assertSame("unix://" . $sock, $client->getPeerAddress()->toString()); + self::assertSame('unix://' . $sock, $client->getPeerAddress()->toString()); $client->writeAll('Hello, World!'); $response = $client->readAll(); self::assertSame('!dlroW ,olleH', $response); diff --git a/tests/unit/Unix/ServerTest.php b/tests/unit/Unix/ServerTest.php index 2b3b8efd..03acb781 100644 --- a/tests/unit/Unix/ServerTest.php +++ b/tests/unit/Unix/ServerTest.php @@ -19,7 +19,7 @@ public function testNextConnectionOnStoppedServer(): void static::markTestSkipped('Unix Server is not supported on Windows platform.'); } - $sock = Filesystem\create_temporary_file(prefix: 'psl-examples') . ".sock"; + $sock = Filesystem\create_temporary_file(prefix: 'psl-examples') . '.sock'; $server = Unix\Server::create($sock); $server->close(); @@ -35,7 +35,7 @@ public function testGetLocalAddressOnStoppedServer(): void static::markTestSkipped('Unix Server is not supported on Windows platform.'); } - $sock = Filesystem\create_temporary_file(prefix: 'psl-examples') . ".sock"; + $sock = Filesystem\create_temporary_file(prefix: 'psl-examples') . '.sock'; $server = Unix\Server::create($sock); $server->close(); @@ -51,7 +51,7 @@ public function testWaitsForPendingOperation(): void static::markTestSkipped('Unix Server is not supported on Windows platform.'); } - $sock = Filesystem\create_temporary_file(prefix: 'psl-examples') . ".sock"; + $sock = Filesystem\create_temporary_file(prefix: 'psl-examples') . '.sock'; $server = Unix\Server::create($sock); $first = Async\run(static fn() => $server->nextConnection()); @@ -84,7 +84,7 @@ public function testAccessUnderlyingStream(): void static::markTestSkipped('Unix Server is not supported on Windows platform.'); } - $sock = Filesystem\create_temporary_file(prefix: 'psl-examples') . ".sock"; + $sock = Filesystem\create_temporary_file(prefix: 'psl-examples') . '.sock'; $server = Unix\Server::create($sock); $stream = $server->getStream(); $deferred = new Async\Deferred(); diff --git a/tests/unit/Vec/EnumerateTest.php b/tests/unit/Vec/EnumerateTest.php index 9dabac35..8a58921b 100644 --- a/tests/unit/Vec/EnumerateTest.php +++ b/tests/unit/Vec/EnumerateTest.php @@ -21,11 +21,14 @@ public function provideData(): iterable { yield [[], []]; yield [[['a', 'b'], ['c', 'd']], ['a' => 'b', 'c' => 'd']]; - yield [[['a', 'b'], ['a', 'b'], ['a', 'b']], (static function () { - yield 'a' => 'b'; - yield 'a' => 'b'; - yield 'a' => 'b'; - })()]; + yield [ + [['a', 'b'], ['a', 'b'], ['a', 'b']], + (static function () { + yield 'a' => 'b'; + yield 'a' => 'b'; + yield 'a' => 'b'; + })(), + ]; yield [[['a', null], ['b', 0]], ['a' => null, 'b' => 0]]; } } diff --git a/tests/unit/Vec/FilterKeysTest.php b/tests/unit/Vec/FilterKeysTest.php index e5020d73..039c9e39 100644 --- a/tests/unit/Vec/FilterKeysTest.php +++ b/tests/unit/Vec/FilterKeysTest.php @@ -13,7 +13,7 @@ final class FilterKeysTest extends TestCase /** * @dataProvider provideData */ - public function testFilter(array $expected, iterable $iterable, ?callable $predicate = null): void + public function testFilter(array $expected, iterable $iterable, null|callable $predicate = null): void { $result = Vec\filter_keys($iterable, $predicate); @@ -22,14 +22,14 @@ public function testFilter(array $expected, iterable $iterable, ?callable $predi public function provideData(): iterable { - yield [[], []]; - yield [['b'], ['a', 'b']]; - yield [['a'], ['a', 'b'], static fn (int $k): bool => $k !== 1]; - yield [['b'], ['a', 'b'], static fn (int $k): bool => $k !== 0]; - yield [['b'], Collection\Vector::fromArray(['a', 'b']), static fn (int $k): bool => $k !== 0]; - yield [[], Collection\Vector::fromArray(['a', 'b']), static fn (int $k): bool => false]; - yield [[], Collection\Vector::fromArray([]), static fn (int $k): bool => false]; - yield [[], ['a', 'b'], static fn (int $_) => false]; - yield [['a', 'b'], ['a', 'b'], static fn (int $_): bool => true]; + yield [[], []]; + yield [['b'], ['a', 'b']]; + yield [['a'], ['a', 'b'], static fn(int $k): bool => $k !== 1]; + yield [['b'], ['a', 'b'], static fn(int $k): bool => $k !== 0]; + yield [['b'], Collection\Vector::fromArray(['a', 'b']), static fn(int $k): bool => $k !== 0]; + yield [[], Collection\Vector::fromArray(['a', 'b']), static fn(int $_k): bool => false]; + yield [[], Collection\Vector::fromArray([]), static fn(int $_k): bool => false]; + yield [[], ['a', 'b'], static fn(int $_) => false]; + yield [['a', 'b'], ['a', 'b'], static fn(int $_): bool => true]; } } diff --git a/tests/unit/Vec/FilterNullsTest.php b/tests/unit/Vec/FilterNullsTest.php index 0be1777a..f80fdb5f 100644 --- a/tests/unit/Vec/FilterNullsTest.php +++ b/tests/unit/Vec/FilterNullsTest.php @@ -24,12 +24,15 @@ public function testFilterNulls(): void static::assertCount(3, Vec\filter_nulls(Iter\Iterator::create([null, false, '', 0]))); static::assertCount(3, Vec\filter_nulls(new Collection\Vector([null, false, '', 0]))); static::assertCount(3, Vec\filter_nulls(new Collection\Map([null, false, '', 0]))); - static::assertCount(3, Vec\filter_nulls((static function (): iterable { - yield null; - yield false; - yield ''; - yield 0; - yield null; - })())); + static::assertCount( + 3, + Vec\filter_nulls((static function (): iterable { + yield null; + yield false; + yield ''; + yield 0; + yield null; + })()), + ); } } diff --git a/tests/unit/Vec/FilterTest.php b/tests/unit/Vec/FilterTest.php index d67acd6e..76023136 100644 --- a/tests/unit/Vec/FilterTest.php +++ b/tests/unit/Vec/FilterTest.php @@ -12,7 +12,7 @@ final class FilterTest extends TestCase /** * @dataProvider provideData */ - public function testFilter(array $expected, array $array, ?callable $predicate = null): void + public function testFilter(array $expected, array $array, null|callable $predicate = null): void { $result = Vec\filter($array, $predicate); @@ -21,10 +21,10 @@ public function testFilter(array $expected, array $array, ?callable $predicate = public function provideData(): iterable { - yield [[], []]; - yield [['a', 'b'], ['a', 'b']]; - yield [[], ['a', 'b'], static fn () => false]; - yield [['a', 'b'], ['a', 'b'], static fn (string $_): bool => true]; - yield [['a'], ['a', 'b'], static fn (string $v): bool => 'b' !== $v]; + yield [[], []]; + yield [['a', 'b'], ['a', 'b']]; + yield [[], ['a', 'b'], static fn() => false]; + yield [['a', 'b'], ['a', 'b'], static fn(string $_): bool => true]; + yield [['a'], ['a', 'b'], static fn(string $v): bool => 'b' !== $v]; } } diff --git a/tests/unit/Vec/FilterWithKeyTest.php b/tests/unit/Vec/FilterWithKeyTest.php index a59d3ff7..c4699918 100644 --- a/tests/unit/Vec/FilterWithKeyTest.php +++ b/tests/unit/Vec/FilterWithKeyTest.php @@ -13,7 +13,7 @@ final class FilterWithKeyTest extends TestCase /** * @dataProvider provideData */ - public function testFilterWithKey(array $expected, iterable $iterable, ?callable $predicate = null): void + public function testFilterWithKey(array $expected, iterable $iterable, null|callable $predicate = null): void { $result = Vec\filter_with_key($iterable, $predicate); @@ -22,18 +22,18 @@ public function testFilterWithKey(array $expected, iterable $iterable, ?callable public function provideData(): iterable { - yield [[], []]; - yield [['a', 'b'], ['a', 'b']]; - yield [[], ['a', 'b'], static fn (int $_k, string $_v) => false]; - yield [['a', 'b'], ['a', 'b'], static fn (int $_k, string $_v): bool => true]; - yield [[], Collection\Vector::fromArray([])]; - yield [['a', 'b'], Collection\Vector::fromArray(['a', 'b'])]; - yield [[], Collection\Vector::fromArray(['a', 'b']), static fn (int $_k, string $_v) => false]; - yield [['a', 'b'], Collection\Vector::fromArray(['a', 'b']), static fn (int $_k, string $_v): bool => true]; - yield [['a'], ['a', 'b'], static fn (int $k, string $v): bool => 'b' !== $v]; - yield [[], ['a', 'b'], static fn (int $k, string $v): bool => 'b' !== $v && 0 !== $k]; - yield [['a'], ['a', 'b'], static fn (int $k, string $v): bool => 'b' !== $v && 1 !== $k]; - yield [[], ['a', 'b'], static fn (int $k, string $v): bool => 'a' !== $v && 1 !== $k]; - yield [['b'], ['a', 'b'], static fn (int $k, string $v): bool => 'a' !== $v && 0 !== $k]; + yield [[], []]; + yield [['a', 'b'], ['a', 'b']]; + yield [[], ['a', 'b'], static fn(int $_k, string $_v) => false]; + yield [['a', 'b'], ['a', 'b'], static fn(int $_k, string $_v): bool => true]; + yield [[], Collection\Vector::fromArray([])]; + yield [['a', 'b'], Collection\Vector::fromArray(['a', 'b'])]; + yield [[], Collection\Vector::fromArray(['a', 'b']), static fn(int $_k, string $_v) => false]; + yield [['a', 'b'], Collection\Vector::fromArray(['a', 'b']), static fn(int $_k, string $_v): bool => true]; + yield [['a'], ['a', 'b'], static fn(int $_k, string $v): bool => 'b' !== $v]; + yield [[], ['a', 'b'], static fn(int $k, string $v): bool => 'b' !== $v && 0 !== $k]; + yield [['a'], ['a', 'b'], static fn(int $k, string $v): bool => 'b' !== $v && 1 !== $k]; + yield [[], ['a', 'b'], static fn(int $k, string $v): bool => 'a' !== $v && 1 !== $k]; + yield [['b'], ['a', 'b'], static fn(int $k, string $v): bool => 'a' !== $v && 0 !== $k]; } } diff --git a/tests/unit/Vec/FlatMapTest.php b/tests/unit/Vec/FlatMapTest.php index d24b0ab7..8a5e67c6 100644 --- a/tests/unit/Vec/FlatMapTest.php +++ b/tests/unit/Vec/FlatMapTest.php @@ -22,15 +22,15 @@ public function testFlatMap(array $expected, array $array, callable $function): public function provideData(): iterable { - yield [[1, 2, 3], [1, 2, 3], static fn (int $v): array => [$v]]; - yield [[1, 2, 2, 4, 3, 6], [1, 2, 3], static fn (int $v): array => [$v, $v * 2]]; - yield [[], [1, 2], static fn (int $k): array => []]; - yield [[[1], [2]], [1, 2], static fn (int $v): array => [[$v]]]; - yield [[], [], static fn (int $k): array => []]; + yield [[1, 2, 3], [1, 2, 3], static fn(int $v): array => [$v]]; + yield [[1, 2, 2, 4, 3, 6], [1, 2, 3], static fn(int $v): array => [$v, $v * 2]]; + yield [[], [1, 2], static fn(int $_k): array => []]; + yield [[[1], [2]], [1, 2], static fn(int $v): array => [[$v]]]; + yield [[], [], static fn(int $_k): array => []]; yield [ ['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog', ''], ['The quick brown', 'fox', 'jumps over', 'the lazy dog', ''], - static fn (string $v): array => Str\Split($v, ' ') + static fn(string $v): array => Str\Split($v, ' '), ]; } } diff --git a/tests/unit/Vec/MapTest.php b/tests/unit/Vec/MapTest.php index 2945fb7e..db2f1a06 100644 --- a/tests/unit/Vec/MapTest.php +++ b/tests/unit/Vec/MapTest.php @@ -22,13 +22,13 @@ public function testMap(array $expected, iterable $iterable, callable $function) public function provideData(): iterable { - yield [[1, 2, 3], [1, 2, 3], static fn (int $v): int => $v]; - yield [[2, 4, 6], [1, 2, 3], static fn (int $v): int => $v * 2]; - yield [['1', '2', '3'], [1, 2, 3], static fn (int $v): string => (string)$v]; - yield [[], [], static fn (int $v): string => (string)$v]; - yield [[1, 2, 3], Collection\Vector::fromArray([1, 2, 3]), static fn (int $v): int => $v]; - yield [[2, 4, 6], Collection\Vector::fromArray([1, 2, 3]), static fn (int $v): int => $v * 2]; - yield [['1', '2', '3'], Collection\Vector::fromArray([1, 2, 3]), static fn (int $v): string => (string)$v]; - yield [[], Collection\Vector::fromArray([]), static fn (int $v): string => (string)$v]; + yield [[1, 2, 3], [1, 2, 3], static fn(int $v): int => $v]; + yield [[2, 4, 6], [1, 2, 3], static fn(int $v): int => $v * 2]; + yield [['1', '2', '3'], [1, 2, 3], static fn(int $v): string => (string) $v]; + yield [[], [], static fn(int $v): string => (string) $v]; + yield [[1, 2, 3], Collection\Vector::fromArray([1, 2, 3]), static fn(int $v): int => $v]; + yield [[2, 4, 6], Collection\Vector::fromArray([1, 2, 3]), static fn(int $v): int => $v * 2]; + yield [['1', '2', '3'], Collection\Vector::fromArray([1, 2, 3]), static fn(int $v): string => (string) $v]; + yield [[], Collection\Vector::fromArray([]), static fn(int $v): string => (string) $v]; } } diff --git a/tests/unit/Vec/MapWithKeyTest.php b/tests/unit/Vec/MapWithKeyTest.php index 61b18462..ed0fa16b 100644 --- a/tests/unit/Vec/MapWithKeyTest.php +++ b/tests/unit/Vec/MapWithKeyTest.php @@ -21,10 +21,10 @@ public function testMapWithKey(array $expected, array $array, callable $function public function provideData(): iterable { - yield [[1, 2, 3], ['a' => 1, 'b' => 2, 'c' => 3], static fn (string $k, int $v): int => $v]; - yield [[1, 3, 5], [1, 2, 3], static fn (int $k, int $v): int => $k + $v]; - yield [[0, 4, 16], [1, 2, 3], static fn (int $k, int $v): int => $k * (2 ** $v)]; - yield [['1', '3', '5'], [1, 2, 3], static fn (int $k, int $v): string => (string) ($k + $v)]; - yield [[], [], static fn (int $k, int $v): string => (string) ($k + $v)]; + yield [[1, 2, 3], ['a' => 1, 'b' => 2, 'c' => 3], static fn(string $_k, int $v): int => $v]; + yield [[1, 3, 5], [1, 2, 3], static fn(int $k, int $v): int => $k + $v]; + yield [[0, 4, 16], [1, 2, 3], static fn(int $k, int $v): int => $k * (2 ** $v)]; + yield [['1', '3', '5'], [1, 2, 3], static fn(int $k, int $v): string => (string) ($k + $v)]; + yield [[], [], static fn(int $k, int $v): string => (string) ($k + $v)]; } } diff --git a/tests/unit/Vec/PartitionTest.php b/tests/unit/Vec/PartitionTest.php index cda3d5e7..bb660045 100644 --- a/tests/unit/Vec/PartitionTest.php +++ b/tests/unit/Vec/PartitionTest.php @@ -12,6 +12,6 @@ final class PartitionTest extends TestCase { public function testPartition(): void { - static::assertSame([[1, 2, 3, 4], [0]], (Vec\partition([0, 1, 2, 3, 4], Fun\identity()))); + static::assertSame([[1, 2, 3, 4], [0]], Vec\partition([0, 1, 2, 3, 4], Fun\identity())); } } diff --git a/tests/unit/Vec/ReductionsTest.php b/tests/unit/Vec/ReductionsTest.php index 270d5aae..2b0820f9 100644 --- a/tests/unit/Vec/ReductionsTest.php +++ b/tests/unit/Vec/ReductionsTest.php @@ -34,21 +34,21 @@ public function provideData(): iterable yield [ [], [], - static fn (int $accumulator, int $k, int $v): int => $accumulator, + static fn(int $accumulator, int $_k, int $_v): int => $accumulator, 0, ]; yield [ [1, 3, 6], [1, 2, 3], - static fn (int $accumulator, int $k, int $v): int => $accumulator + $v, + static fn(int $accumulator, int $_k, int $v): int => $accumulator + $v, 0, ]; yield [ [1, 3, 6], Iter\to_iterator([1, 2, 3]), - static fn (int $accumulator, int $k, int $v): int => $accumulator + $v, + static fn(int $accumulator, int $_k, int $v): int => $accumulator + $v, 0, ]; } diff --git a/tests/unit/Vec/ReproduceTest.php b/tests/unit/Vec/ReproduceTest.php index 95847c88..52773b8a 100644 --- a/tests/unit/Vec/ReproduceTest.php +++ b/tests/unit/Vec/ReproduceTest.php @@ -12,7 +12,7 @@ final class ReproduceTest extends TestCase { public function testReproduce(): void { - static::assertSame([1], (Vec\reproduce(1, Fun\identity()))); + static::assertSame([1], Vec\reproduce(1, Fun\identity())); static::assertSame([1, 2, 3], Vec\reproduce(3, Fun\identity())); } } diff --git a/tests/unit/Vec/SliceTest.php b/tests/unit/Vec/SliceTest.php index d0d0090a..8c4e57e0 100644 --- a/tests/unit/Vec/SliceTest.php +++ b/tests/unit/Vec/SliceTest.php @@ -12,7 +12,7 @@ final class SliceTest extends TestCase /** * @dataProvider provideData */ - public function testSlice(array $expected, array $array, int $n, ?int $l = null): void + public function testSlice(array $expected, array $array, int $n, null|int $l = null): void { $result = Vec\slice($array, $n, $l); diff --git a/tests/unit/Vec/SortByTest.php b/tests/unit/Vec/SortByTest.php index 855b5172..e1b49723 100644 --- a/tests/unit/Vec/SortByTest.php +++ b/tests/unit/Vec/SortByTest.php @@ -14,25 +14,25 @@ final class SortByTest extends TestCase /** * @dataProvider provideData */ - public function testSortBy(array $expected, array $array, callable $scalar_fun, ?callable $comp = null): void + public function testSortBy(array $expected, array $array, callable $scalar_fun, null|callable $comp = null): void { static::assertSame($expected, Vec\sort_by($array, $scalar_fun, $comp)); } public function provideData(): array { - $a = [1, 2]; - $b = [1, 2, 3, 4]; - $c = ['a' => 'foo', 'b' => 'bar', 'c' => 'baz', 'd' => 'qux', 'e' => 'lax']; - $expected = [$a, $b, $c]; - $array = [$b, $c, $a]; + $a = [1, 2]; + $b = [1, 2, 3, 4]; + $c = ['a' => 'foo', 'b' => 'bar', 'c' => 'baz', 'd' => 'qux', 'e' => 'lax']; + $expected = [$a, $b, $c]; + $array = [$b, $c, $a]; $scalar_fun = /** * @param array $arr * * @psalm-pure */ - static fn (array $arr): int => Iter\count($arr); + static fn(array $arr): int => Iter\count($arr); return [ [ @@ -40,54 +40,49 @@ public function provideData(): array $array, $scalar_fun, ], - [ ['a', 'b', 'c', 'd'], ['d', 'a', 'b', 'c'], /** * @psalm-pure */ - static fn (string $v): string => $v, + static fn(string $v): string => $v, ], - [ ['a'], ['a'], /** * @psalm-pure */ - static fn (string $v): string => $v, + static fn(string $v): string => $v, ], - [ ['d', 'c', 'b', 'a'], ['d', 'a', 'b', 'c'], /** * @psalm-pure */ - static fn (string $v): string => $v, + static fn(string $v): string => $v, /** * @psalm-pure */ - static fn (string $a, string $b): int => Str\ord($a) > Str\ord($b) ? -1 : 1, + static fn(string $a, string $b): int => Str\ord($a) > Str\ord($b) ? -1 : 1, ], - [ ['bar', 'qux'], ['foo' => 'bar', 'baz' => 'qux'], /** * @psalm-pure */ - static fn (string $v): string => $v, + static fn(string $v): string => $v, ], - [ ['jumped', 'the', 'quick', 'brown', 'fox'], ['the', 'quick', 'brown', 'fox', 'jumped'], /** * @psalm-pure */ - static fn (string $v): string => Str\Byte\reverse($v), + static fn(string $v): string => Str\Byte\reverse($v), ], ]; } diff --git a/tests/unit/Vec/SortTest.php b/tests/unit/Vec/SortTest.php index ebcc1365..df886805 100644 --- a/tests/unit/Vec/SortTest.php +++ b/tests/unit/Vec/SortTest.php @@ -17,7 +17,7 @@ final class SortTest extends TestCase * * @dataProvider provideData */ - public function testSort(array $expected, array $array, ?callable $comparator = null): void + public function testSort(array $expected, array $array, null|callable $comparator = null): void { static::assertSame($expected, Vec\sort($array, $comparator)); } @@ -29,16 +29,14 @@ public function provideData(): array ['a', 'b', 'c'], ['c', 'a', 'b'], ], - [ [8, 9, 10], [8, 9, 10], /** * @psalm-pure */ - static fn (int $a, int $b): int => $a <=> $b ? -1 : 1, + static fn(int $a, int $b): int => $a <=> $b ? -1 : 1, ], - [ ['bar', 'baz'], ['foo' => 'bar', 'bar' => 'baz'], diff --git a/tests/unit/Vec/UniqueByTest.php b/tests/unit/Vec/UniqueByTest.php index 83717734..73077173 100644 --- a/tests/unit/Vec/UniqueByTest.php +++ b/tests/unit/Vec/UniqueByTest.php @@ -24,13 +24,12 @@ public function provideData(): array [ ['a', 'saif'], ['a', 'b', 'c', 'd', 'saif', 'jack'], - static fn (string $value): int => Str\length($value), + static fn(string $value): int => Str\length($value), ], - [ ['foo', 'bar', '@baz'], ['foo', '@foo', 'bar', '@bar', '@baz'], - static fn (string $value): string => Str\replace($value, '@', ''), + static fn(string $value): string => Str\replace($value, '@', ''), ], ]; } diff --git a/tests/unit/Vec/UniqueScalarTest.php b/tests/unit/Vec/UniqueScalarTest.php index 0d5cbce5..f7e42161 100644 --- a/tests/unit/Vec/UniqueScalarTest.php +++ b/tests/unit/Vec/UniqueScalarTest.php @@ -13,7 +13,7 @@ final class UniqueScalarTest extends TestCase { public function testUniqueScalars(): void { - $array = Vec\fill(10, 'foo'); + $array = Vec\fill(10, 'foo'); $array[] = 'bar'; $unique = Vec\unique_scalar($array); diff --git a/tests/unit/Vec/UniqueTest.php b/tests/unit/Vec/UniqueTest.php index bbe6e6b4..646cc9f8 100644 --- a/tests/unit/Vec/UniqueTest.php +++ b/tests/unit/Vec/UniqueTest.php @@ -26,7 +26,7 @@ public function testUniqueWithObjects(): void { $array = Vec\fill(10, 'foo'); $object = new Collection\Map([]); - $array = Vec\concat($array, Vec\fill(10, $object)); + $array = Vec\concat($array, Vec\fill(10, $object)); $unique = Vec\unique($array); diff --git a/tests/unit/Vec/ZipTest.php b/tests/unit/Vec/ZipTest.php index 7797ea9f..00d9c492 100644 --- a/tests/unit/Vec/ZipTest.php +++ b/tests/unit/Vec/ZipTest.php @@ -22,7 +22,7 @@ public function provideData(): iterable yield [ [['foo', 'baz'], ['bar', 'qux']], ['foo', 'bar'], - ['baz', 'qux'] + ['baz', 'qux'], ]; yield [