From f35926d761bf8a61add784acb58257c751b94e5c Mon Sep 17 00:00:00 2001 From: AlexandruGG Date: Mon, 31 May 2021 11:28:59 +0100 Subject: [PATCH 01/10] Initial tweaks --- composer.json | 2 +- phpstan-docs-baseline.neon | 5 ----- src/Collection.php | 4 ++-- src/Contract/Operation/Applyable.php | 7 ++++--- src/Operation/Apply.php | 2 +- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 42d09b65f..ce5c811d5 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "php": ">= 7.4" + "php": "^7.4 || ^8.0" }, "require-dev": { "amphp/parallel-functions": "^1", diff --git a/phpstan-docs-baseline.neon b/phpstan-docs-baseline.neon index 50554478a..c32abf778 100644 --- a/phpstan-docs-baseline.neon +++ b/phpstan-docs-baseline.neon @@ -9,8 +9,3 @@ parameters: message: "#^Unable to resolve the template type NewTKey in call to method static method loophp\\\\collection\\\\Collection\\\\:\\:fromIterable\\(\\)$#" count: 1 path: docs/pages/code/parse-git-log.php - - - - message: "#^Parameter \\#1 \\$str of function mb_strtolower expects string, int given\\.$#" - count: 1 - path: docs/pages/code/simple.php diff --git a/src/Collection.php b/src/Collection.php index 8fae5e0cb..b5f902cb2 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -166,9 +166,9 @@ public function append(...$items): CollectionInterface return new self(Append::of()(...$items), $this->getIterator()); } - public function apply(callable ...$callables): CollectionInterface + public function apply(callable ...$callbacks): CollectionInterface { - return new self(Apply::of()(...$callables), $this->getIterator()); + return new self(Apply::of()(...$callbacks), $this->getIterator()); } public function associate( diff --git a/src/Contract/Operation/Applyable.php b/src/Contract/Operation/Applyable.php index 17e5f1e20..a2f938a25 100644 --- a/src/Contract/Operation/Applyable.php +++ b/src/Contract/Operation/Applyable.php @@ -10,6 +10,7 @@ namespace loophp\collection\Contract\Operation; use loophp\collection\Contract\Collection; +use Iterator; /** * @template TKey @@ -20,9 +21,9 @@ interface Applyable /** * Execute a callback for each element of the collection. * - * @param callable(TKey, T):bool ...$callables + * @param callable(T, TKey, Iterator): bool ...$callbacks * - * @return \loophp\collection\Collection + * @return Collection */ - public function apply(callable ...$callables): Collection; + public function apply(callable ...$callbacks): Collection; } diff --git a/src/Operation/Apply.php b/src/Operation/Apply.php index 9b6ab5058..eae133194 100644 --- a/src/Operation/Apply.php +++ b/src/Operation/Apply.php @@ -28,7 +28,7 @@ public function __invoke(): Closure { return /** - * @param callable(T, TKey, Iterator):bool ...$callbacks + * @param callable(T, TKey, Iterator): bool ...$callbacks * * @return Closure(Iterator): Generator */ From 76e6cd711d9855695535287efe9f49f5e6e9f224 Mon Sep 17 00:00:00 2001 From: AlexandruGG Date: Tue, 1 Jun 2021 12:07:55 +0100 Subject: [PATCH 02/10] Update CI --- .github/workflows/code-style.yml | 2 +- .github/workflows/mutation-tests.yml | 2 +- .github/workflows/static-analysis.yml | 2 +- .github/workflows/tests.yml | 2 +- .scrutinizer.yml | 9 ++++++++- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml index 56c5e5f4b..37ddbce40 100644 --- a/.github/workflows/code-style.yml +++ b/.github/workflows/code-style.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest] - php-versions: ['7.4'] + php-versions: ['7.4', '8.0'] steps: - name: Set git to use LF diff --git a/.github/workflows/mutation-tests.yml b/.github/workflows/mutation-tests.yml index e61094af5..9cb7df2a7 100644 --- a/.github/workflows/mutation-tests.yml +++ b/.github/workflows/mutation-tests.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest] - php-versions: ['7.4'] + php-versions: ['7.4', '8.0'] steps: - name: Set git to use LF diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index f521dc632..864e2a79f 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest, windows-latest, macOS-latest] - php-versions: ['7.4'] + php-versions: ['7.4', '8.0'] steps: - name: Set git to use LF diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 447d861a7..4941a5eeb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: operating-system: [ubuntu-latest, windows-latest, macOS-latest] - php-versions: ['7.4'] + php-versions: ['7.4', '8.0'] steps: - name: Set git to use LF diff --git a/.scrutinizer.yml b/.scrutinizer.yml index db9944869..f858f0e33 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,12 +1,19 @@ build: nodes: - analysis: + php74: environment: php: version: 7.4 tests: override: - php-scrutinizer-run + php80: + environment: + php: + version: 8.0 + tests: + override: + - php-scrutinizer-run filter: paths: From a47faa78c9d5e3acfde786eec54c8632539a1722 Mon Sep 17 00:00:00 2001 From: AlexandruGG Date: Tue, 1 Jun 2021 12:11:38 +0100 Subject: [PATCH 03/10] Fixer --- src/Contract/Operation/Applyable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Contract/Operation/Applyable.php b/src/Contract/Operation/Applyable.php index a2f938a25..dfa2e4979 100644 --- a/src/Contract/Operation/Applyable.php +++ b/src/Contract/Operation/Applyable.php @@ -9,8 +9,8 @@ namespace loophp\collection\Contract\Operation; -use loophp\collection\Contract\Collection; use Iterator; +use loophp\collection\Contract\Collection; /** * @template TKey From cd1f289949d633124a7a031620ba7f0c2dec5f6a Mon Sep 17 00:00:00 2001 From: AlexandruGG Date: Tue, 1 Jun 2021 12:22:46 +0100 Subject: [PATCH 04/10] Fix asyncMap testcase --- spec/loophp/collection/CollectionSpec.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/spec/loophp/collection/CollectionSpec.php b/spec/loophp/collection/CollectionSpec.php index dbcdb2e9a..7ab5679be 100644 --- a/spec/loophp/collection/CollectionSpec.php +++ b/spec/loophp/collection/CollectionSpec.php @@ -12,6 +12,7 @@ use ArrayIterator; use ArrayObject; use Closure; +use Error; use Exception; use Generator; use InvalidArgumentException; @@ -27,9 +28,12 @@ use stdClass; use const INF; use const PHP_EOL; +use const PHP_VERSION_ID; class CollectionSpec extends ObjectBehavior { + private const PHP_VERSION_8 = 80000; + public function it_can_append(): void { $generator = static function (): Generator { @@ -226,9 +230,18 @@ public function it_can_asyncMap(): void return $v * 2; }; - $this::fromIterable(['c' => 3, 'b' => 2, 'a' => 1]) - ->asyncMap($callback1, $callback2) - ->shouldIterateAs(['a' => 2, 'b' => 4, 'c' => 6]); + $this->beConstructedThrough('fromIterable', [['c' => 3, 'b' => 2, 'a' => 1]]); + + if (PHP_VERSION_ID >= self::PHP_VERSION_8) { + $this + ->asyncMap($callback1, $callback2) + ->shouldThrow(Error::class) + ->during('all'); + } else { + $this + ->asyncMap($callback1, $callback2) + ->shouldIterateAs(['a' => 2, 'b' => 4, 'c' => 6]); + } } public function it_can_be_constructed_from_a_file(): void From 349cb1b42fe73d1c7e041d83ba9b045374a8a6ce Mon Sep 17 00:00:00 2001 From: AlexandruGG Date: Tue, 1 Jun 2021 12:28:33 +0100 Subject: [PATCH 05/10] Make 8.0 checks required in github --- .github/settings.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/settings.yml b/.github/settings.yml index 336a2af6f..aa18edd99 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -12,13 +12,21 @@ branches: strict: true contexts: - "Static Analysis (ubuntu-latest, 7.4)" + - "Static Analysis (ubuntu-latest, 8.0)" - "Static Analysis (windows-latest, 7.4)" + - "Static Analysis (windows-latest, 8.0)" - "Static Analysis (macOS-latest, 7.4)" + - "Static Analysis (macOS-latest, 8.0)" - "Unit Tests (ubuntu-latest, 7.4)" + - "Unit Tests (ubuntu-latest, 8.0)" - "Unit Tests (windows-latest, 7.4)" + - "Unit Tests (windows-latest, 8.0)" - "Unit Tests (macOS-latest, 7.4)" + - "Unit Tests (macOS-latest, 8.0)" - "Mutation Testing (ubuntu-latest, 7.4)" + - "Mutation Testing (ubuntu-latest, 8.0)" - "Code Style (ubuntu-latest, 7.4)" + - "Code Style (ubuntu-latest, 8.0)" restrictions: null required_linear_history: true From 5d0ccb0adc000abb6d581d3301d4cc2655da3169 Mon Sep 17 00:00:00 2001 From: AlexandruGG Date: Tue, 1 Jun 2021 16:45:36 +0100 Subject: [PATCH 06/10] Handle AsyncMap PHP 8 --- docs/pages/api.rst | 3 ++- spec/loophp/collection/CollectionSpec.php | 12 +++++------- src/Constant.php | 15 +++++++++++++++ src/Operation/AsyncMap.php | 10 ++++++++-- 4 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 src/Constant.php diff --git a/docs/pages/api.rst b/docs/pages/api.rst index 0fab4145e..b248ce0c2 100644 --- a/docs/pages/api.rst +++ b/docs/pages/api.rst @@ -268,7 +268,8 @@ asyncMap Asynchronously apply one or more supplied callbacks to every item of a collection and use the return value. -.. warning:: This method requires `ampphp/parallel-functions `_ to be installed. +.. warning:: This method requires `ampphp/parallel-functions `_ to be installed, + and is currently *not supported* in PHP 8. .. warning:: This operation is non-deterministic, we cannot ensure the order of the elements at the end. Additionally, diff --git a/spec/loophp/collection/CollectionSpec.php b/spec/loophp/collection/CollectionSpec.php index 7ab5679be..58fa14aad 100644 --- a/spec/loophp/collection/CollectionSpec.php +++ b/spec/loophp/collection/CollectionSpec.php @@ -12,19 +12,20 @@ use ArrayIterator; use ArrayObject; use Closure; -use Error; use Exception; use Generator; use InvalidArgumentException; use Iterator; use JsonSerializable; use loophp\collection\Collection; +use loophp\collection\Constant; use loophp\collection\Contract\Operation; use loophp\collection\Operation\AbstractOperation; use OutOfBoundsException; use PhpSpec\Exception\Example\FailureException; use PhpSpec\Exception\Example\MatcherException; use PhpSpec\ObjectBehavior; +use RuntimeException; use stdClass; use const INF; use const PHP_EOL; @@ -32,8 +33,6 @@ class CollectionSpec extends ObjectBehavior { - private const PHP_VERSION_8 = 80000; - public function it_can_append(): void { $generator = static function (): Generator { @@ -232,11 +231,10 @@ public function it_can_asyncMap(): void $this->beConstructedThrough('fromIterable', [['c' => 3, 'b' => 2, 'a' => 1]]); - if (PHP_VERSION_ID >= self::PHP_VERSION_8) { + if (PHP_VERSION_ID >= Constant::PHP_VERSION_8) { $this - ->asyncMap($callback1, $callback2) - ->shouldThrow(Error::class) - ->during('all'); + ->shouldThrow(RuntimeException::class) + ->during('asyncMap', [$callback1, $callback2]); } else { $this ->asyncMap($callback1, $callback2) diff --git a/src/Constant.php b/src/Constant.php new file mode 100644 index 000000000..642382a81 --- /dev/null +++ b/src/Constant.php @@ -0,0 +1,15 @@ += Constant::PHP_VERSION_8) { + throw new RuntimeException('This operation is currently not supported on PHP 8.'); } // phpcs:enable /** From 3031a5fbe7bc0028501ef41df64a15d5373723f9 Mon Sep 17 00:00:00 2001 From: AlexandruGG Date: Tue, 1 Jun 2021 16:47:59 +0100 Subject: [PATCH 07/10] Correct spelling --- docs/pages/api.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/api.rst b/docs/pages/api.rst index b248ce0c2..9aef7175b 100644 --- a/docs/pages/api.rst +++ b/docs/pages/api.rst @@ -268,7 +268,7 @@ asyncMap Asynchronously apply one or more supplied callbacks to every item of a collection and use the return value. -.. warning:: This method requires `ampphp/parallel-functions `_ to be installed, +.. warning:: This method requires `amphp/parallel-functions `_ to be installed, and is currently *not supported* in PHP 8. .. warning:: From 6ec9d69938ef89ef6bf629c7a380b64834c4d597 Mon Sep 17 00:00:00 2001 From: AlexandruGG Date: Tue, 1 Jun 2021 16:56:58 +0100 Subject: [PATCH 08/10] Fixes --- src/Operation/AsyncMap.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Operation/AsyncMap.php b/src/Operation/AsyncMap.php index 71a444628..c93f3f4c2 100644 --- a/src/Operation/AsyncMap.php +++ b/src/Operation/AsyncMap.php @@ -21,16 +21,13 @@ use function Amp\Promise\wait; use function Amp\Sync\ConcurrentIterator\map; use function function_exists; + use const PHP_VERSION_ID; // phpcs:disable if (false === function_exists('Amp\ParallelFunctions\parallel')) { throw new RuntimeException('You need amphp/parallel-functions to get this operation working.'); } - -if (PHP_VERSION_ID >= Constant::PHP_VERSION_8) { - throw new RuntimeException('This operation is currently not supported on PHP 8.'); -} // phpcs:enable /** * Class AsyncMap. @@ -47,6 +44,10 @@ final class AsyncMap extends AbstractOperation */ public function __invoke(): Closure { + if (PHP_VERSION_ID >= Constant::PHP_VERSION_8) { + throw new RuntimeException('This operation is currently not supported on PHP 8.'); + } + return /** * @param callable(T, TKey): T ...$callbacks From 781bac97d3bdf9cc8d98bf2f0e63af2f4e23c815 Mon Sep 17 00:00:00 2001 From: AlexandruGG Date: Sun, 6 Jun 2021 13:31:43 +0100 Subject: [PATCH 09/10] Remove runtime changes --- composer.json | 2 +- docs/pages/api.rst | 3 +-- spec/loophp/collection/CollectionSpec.php | 10 +++++----- src/Constant.php | 15 --------------- src/Operation/AsyncMap.php | 7 ------- 5 files changed, 7 insertions(+), 30 deletions(-) delete mode 100644 src/Constant.php diff --git a/composer.json b/composer.json index ce5c811d5..42d09b65f 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "php": "^7.4 || ^8.0" + "php": ">= 7.4" }, "require-dev": { "amphp/parallel-functions": "^1", diff --git a/docs/pages/api.rst b/docs/pages/api.rst index 9aef7175b..8e0dc7665 100644 --- a/docs/pages/api.rst +++ b/docs/pages/api.rst @@ -268,8 +268,7 @@ asyncMap Asynchronously apply one or more supplied callbacks to every item of a collection and use the return value. -.. warning:: This method requires `amphp/parallel-functions `_ to be installed, - and is currently *not supported* in PHP 8. +.. warning:: This method requires `amphp/parallel-functions `_ to be installed. .. warning:: This operation is non-deterministic, we cannot ensure the order of the elements at the end. Additionally, diff --git a/spec/loophp/collection/CollectionSpec.php b/spec/loophp/collection/CollectionSpec.php index 58fa14aad..80d40a1c1 100644 --- a/spec/loophp/collection/CollectionSpec.php +++ b/spec/loophp/collection/CollectionSpec.php @@ -12,20 +12,19 @@ use ArrayIterator; use ArrayObject; use Closure; +use Error; use Exception; use Generator; use InvalidArgumentException; use Iterator; use JsonSerializable; use loophp\collection\Collection; -use loophp\collection\Constant; use loophp\collection\Contract\Operation; use loophp\collection\Operation\AbstractOperation; use OutOfBoundsException; use PhpSpec\Exception\Example\FailureException; use PhpSpec\Exception\Example\MatcherException; use PhpSpec\ObjectBehavior; -use RuntimeException; use stdClass; use const INF; use const PHP_EOL; @@ -231,10 +230,11 @@ public function it_can_asyncMap(): void $this->beConstructedThrough('fromIterable', [['c' => 3, 'b' => 2, 'a' => 1]]); - if (PHP_VERSION_ID >= Constant::PHP_VERSION_8) { + if (PHP_VERSION_ID >= 80000) { $this - ->shouldThrow(RuntimeException::class) - ->during('asyncMap', [$callback1, $callback2]); + ->asyncMap($callback1, $callback2) + ->shouldThrow(Error::class) + ->during('all'); } else { $this ->asyncMap($callback1, $callback2) diff --git a/src/Constant.php b/src/Constant.php deleted file mode 100644 index 642382a81..000000000 --- a/src/Constant.php +++ /dev/null @@ -1,15 +0,0 @@ -= Constant::PHP_VERSION_8) { - throw new RuntimeException('This operation is currently not supported on PHP 8.'); - } - return /** * @param callable(T, TKey): T ...$callbacks From aec9eb048eab601e540c1e215d9ae3c6b379ad99 Mon Sep 17 00:00:00 2001 From: AlexandruGG Date: Sun, 6 Jun 2021 13:38:32 +0100 Subject: [PATCH 10/10] Trigger again for windows --- src/Operation/AsyncMap.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Operation/AsyncMap.php b/src/Operation/AsyncMap.php index 2a65efd22..ea9c5abca 100644 --- a/src/Operation/AsyncMap.php +++ b/src/Operation/AsyncMap.php @@ -11,9 +11,9 @@ use Amp\Sync\LocalSemaphore; use Closure; +use Exception; use Generator; use Iterator; -use RuntimeException; use function Amp\Iterator\fromIterable; use function Amp\ParallelFunctions\parallel; @@ -23,7 +23,7 @@ // phpcs:disable if (false === function_exists('Amp\ParallelFunctions\parallel')) { - throw new RuntimeException('You need amphp/parallel-functions to get this operation working.'); + throw new Exception('You need amphp/parallel-functions to get this operation working.'); } // phpcs:enable /**