From 199b3ab22618232c04ad2dd4055f092b854091b9 Mon Sep 17 00:00:00 2001 From: Arkadiusz Kondas Date: Sun, 8 Dec 2024 18:50:40 +0100 Subject: [PATCH] bump phpstan levet to 6 --- composer.json | 3 +- phpstan.neon | 10 ++- src/Collection/GenericList.php | 14 ++-- src/Collection/GenericList/Nil.php | 3 + src/Collection/Iterator.php | 12 +++ src/Collection/Iterator/EmptyIterator.php | 12 ++- src/Collection/Iterator/MapIterator.php | 2 + src/Collection/Iterator/SingletonIterator.php | 2 + src/Collection/Map.php | 73 +++++++++++------ src/Collection/Set.php | 82 +++++++++++++------ src/Collection/Stream.php | 41 ++++++---- src/Collection/Stream/Collectors.php | 2 +- src/Collection/Stream/EmptyStream.php | 3 + src/Collection/Traversable.php | 2 + src/Control/TryTo.php | 21 ++++- src/Lazy.php | 3 + tests/Collection/MapTest.php | 2 +- tests/Collection/SetTest.php | 4 +- tests/Control/OptionTest.php | 6 +- tests/Helpers/TupleConcatTestHelper.php | 59 ------------- tests/TupleTest.php | 78 +++++++++++++++++- 21 files changed, 285 insertions(+), 149 deletions(-) delete mode 100644 tests/Helpers/TupleConcatTestHelper.php diff --git a/composer.json b/composer.json index 958b3e2..275b6fe 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,8 @@ "friendsofphp/php-cs-fixer": "^3.27", "nette/php-generator": "^4.0", "phpunit/phpunit": "^10.5", - "phpstan/phpstan": "^2.0" + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-phpunit": "^2.0" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon index b902618..d7eb07d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,9 +1,17 @@ includes: - vendor/phpstan/phpstan/conf/bleedingEdge.neon + - vendor/phpstan/phpstan-phpunit/extension.neon parameters: phpVersion: 80100 - level: 5 + level: 6 paths: - src - tests - generators + ignoreErrors: + - + identifier: argument.templateType + path: tests/Collection/MapTest.php + - + identifier: missingType.generics + path: src/Collection/Stream/Collectors.php diff --git a/src/Collection/GenericList.php b/src/Collection/GenericList.php index 9425182..be74270 100644 --- a/src/Collection/GenericList.php +++ b/src/Collection/GenericList.php @@ -19,13 +19,16 @@ abstract class GenericList extends Sequence * * @param U ...$elements * - * @return GenericList + * @return self */ public static function of(...$elements): self { return self::ofAll($elements); } + /** + * @return self + */ public static function empty(): self { return Nil::instance(); @@ -36,7 +39,7 @@ public static function empty(): self * * @param iterable $elements * - * @return GenericList + * @return self */ public static function ofAll(iterable $elements): self { @@ -65,7 +68,7 @@ public static function range(int $start, int $end): self * * @param callable(T):U $mapper * - * @return GenericList + * @return self */ public function map(callable $mapper): self { @@ -81,10 +84,11 @@ public function map(callable $mapper): self * * @param callable(T): Traversable $mapper * - * @return GenericList + * @return self */ public function flatMap(callable $mapper) { + /** @var self $list */ $list = self::empty(); foreach ($this as $value) { foreach ($mapper($value) as $mapped) { @@ -98,7 +102,7 @@ public function flatMap(callable $mapper) /** * @param callable(T):bool $predicate * - * @return GenericList + * @return self */ public function filter(callable $predicate) { diff --git a/src/Collection/GenericList/Nil.php b/src/Collection/GenericList/Nil.php index 1e3810c..1619a79 100644 --- a/src/Collection/GenericList/Nil.php +++ b/src/Collection/GenericList/Nil.php @@ -18,6 +18,9 @@ private function __construct() { } + /** + * @return self + */ public static function instance(): self { return new self(); diff --git a/src/Collection/Iterator.php b/src/Collection/Iterator.php index 30340d5..1796ae1 100644 --- a/src/Collection/Iterator.php +++ b/src/Collection/Iterator.php @@ -11,6 +11,8 @@ /** * @template T + * + * @implements \Iterator */ class Iterator implements \Iterator { @@ -51,11 +53,21 @@ public static function of(...$elements): self return new ArrayIterator($elements); } + /** + * @return self + */ public static function empty(): self { return EmptyIterator::instance(); } + /** + * @template U + * + * @param iterable $elements + * + * @return self + */ public static function fromIterable(iterable $elements): self { if ($elements instanceof self) { diff --git a/src/Collection/Iterator/EmptyIterator.php b/src/Collection/Iterator/EmptyIterator.php index c98d0d7..d772124 100644 --- a/src/Collection/Iterator/EmptyIterator.php +++ b/src/Collection/Iterator/EmptyIterator.php @@ -7,12 +7,20 @@ use Munus\Collection\Iterator; use Munus\Exception\NoSuchElementException; +/** + * @template T + * + * @template-extends Iterator + */ final class EmptyIterator extends Iterator { private function __construct() { } + /** + * @return self + */ public static function instance(): self { return new self(); @@ -24,7 +32,9 @@ public function hasNext(): bool } /** - * @return void + * @throws NoSuchElementException + * + * @return never-return */ public function next() { diff --git a/src/Collection/Iterator/MapIterator.php b/src/Collection/Iterator/MapIterator.php index a7c0e3c..2a57fb0 100644 --- a/src/Collection/Iterator/MapIterator.php +++ b/src/Collection/Iterator/MapIterator.php @@ -11,6 +11,8 @@ /** * @template K * @template V + * + * @template-extends Iterator> */ final class MapIterator extends Iterator { diff --git a/src/Collection/Iterator/SingletonIterator.php b/src/Collection/Iterator/SingletonIterator.php index eed6ff3..6655de4 100644 --- a/src/Collection/Iterator/SingletonIterator.php +++ b/src/Collection/Iterator/SingletonIterator.php @@ -9,6 +9,8 @@ /** * @template T + * + * @template-extends Iterator */ final class SingletonIterator extends Iterator { diff --git a/src/Collection/Map.php b/src/Collection/Map.php index d192790..214a577 100644 --- a/src/Collection/Map.php +++ b/src/Collection/Map.php @@ -34,6 +34,9 @@ private function __construct() { } + /** + * @return self + */ public static function empty(): self { return new self(); @@ -62,7 +65,7 @@ public static function from(array $map): self * * @param array $array * - * @return Map + * @return self */ public static function fromArray(array $array): self { @@ -80,7 +83,7 @@ public static function fromArray(array $array): self * * @param array> $map * - * @return Map + * @return self */ private static function fromPointer(array &$map): self { @@ -111,7 +114,7 @@ public function get(): Option * @param K $key * @param V $value * - * @return Map + * @return self */ public function put(mixed $key, mixed $value): self { @@ -128,6 +131,8 @@ public function put(mixed $key, mixed $value): self /** * @param K $key + * + * @return self */ public function remove(mixed $key): self { @@ -164,9 +169,9 @@ public function head(): Tuple2 /** * @throws NoSuchElementException * - * @return Map + * @return self */ - public function tail() + public function tail(): self { if ($this->isEmpty()) { throw new NoSuchElementException('tail of empty Map'); @@ -184,9 +189,9 @@ public function tail() * * @phpstan-param callable(Tuple2): Tuple2 $mapper * - * @return Map + * @return self */ - public function map(callable $mapper) + public function map(callable $mapper): self { $map = []; foreach ($this->map as $tuple) { @@ -196,7 +201,15 @@ public function map(callable $mapper) return self::fromPointer($map); } - public function flatMap(callable $mapper) + /** + * @template U + * @template T + * + * @phpstan-param callable(Tuple2): Traversable> $mapper + * + * @return self + */ + public function flatMap(callable $mapper): self { $map = []; foreach ($this->map as $tuple) { @@ -213,7 +226,7 @@ public function flatMap(callable $mapper) * * @param callable(K):U $keyMapper * - * @return Map + * @return self */ public function mapKeys(callable $keyMapper): self { @@ -230,7 +243,7 @@ public function mapKeys(callable $keyMapper): self * * @param callable(V):U $valueMapper * - * @return Map + * @return self */ public function mapValues(callable $valueMapper): self { @@ -245,9 +258,9 @@ public function mapValues(callable $valueMapper): self /** * @param callable(Tuple2):bool $predicate * - * @return Map + * @return self */ - public function filter(callable $predicate) + public function filter(callable $predicate): self { $map = []; foreach ($this->map as $tuple) { @@ -260,9 +273,9 @@ public function filter(callable $predicate) } /** - * @return Map + * @return self */ - public function sorted() + public function sorted(): self { $map = $this->map; usort($map, fn (Tuple2 $a, Tuple2 $b) => $a[1] <=> $b[1]); @@ -273,9 +286,9 @@ public function sorted() /** * @param callable(Tuple2):bool $predicate * - * @return Map + * @return self */ - public function dropWhile(callable $predicate) + public function dropWhile(callable $predicate): self { $map = $this->map; while ($map !== [] && $predicate(current($map)) === true) { @@ -288,9 +301,9 @@ public function dropWhile(callable $predicate) /** * @param callable(Tuple2):bool $predicate * - * @return Map + * @return self */ - public function dropUntil(callable $predicate) + public function dropUntil(callable $predicate): self { return parent::dropUntil($predicate); } @@ -298,9 +311,9 @@ public function dropUntil(callable $predicate) /** * @param callable(V): void $action * - * @return Map + * @return self */ - public function peek(callable $action) + public function peek(callable $action): self { if (!$this->isEmpty()) { $action($this->get()->get()); @@ -312,9 +325,9 @@ public function peek(callable $action) /** * Take n next entries of map. * - * @return Map + * @return self */ - public function take(int $n) + public function take(int $n): self { if ($n >= $this->length()) { return $this; @@ -328,9 +341,9 @@ public function take(int $n) /** * Drop n next entries of map. * - * @return Map + * @return self */ - public function drop(int $n) + public function drop(int $n): self { if ($n <= 0) { return $this; @@ -350,6 +363,9 @@ public function isEmpty(): bool return $this->length() === 0; } + /** + * @return Iterator> + */ public function iterator(): Iterator { return new MapIterator($this->map); @@ -417,6 +433,10 @@ public function containsValue($value): bool /** * If collisions occur, the value of this map is taken. + * + * @param self $map + * + * @return self */ public function merge(self $map): self { @@ -429,7 +449,7 @@ public function merge(self $map): self } return $map->fold($this, function (Map $result, Tuple2 $entry) { - return !$result->containsKey($entry[0]) ? $result->put($entry[0], $entry[1]) : $result; + return !$result->containsKey($entry[0]) ? $result->put($entry[0], $entry[1]) : $result; // @phpstan-ignore offsetAccess.notFound, offsetAccess.notFound, offsetAccess.notFound }); } @@ -464,6 +484,9 @@ public function offsetSet(mixed $offset, mixed $value): void throw new UnsupportedOperationException(); } + /** + * @throws UnsupportedOperationException + */ public function offsetUnset(mixed $offset): void { throw new UnsupportedOperationException(); diff --git a/src/Collection/Set.php b/src/Collection/Set.php index 47280fe..3ce4015 100644 --- a/src/Collection/Set.php +++ b/src/Collection/Set.php @@ -17,8 +17,11 @@ final class Set extends Traversable /** * @var T[] */ - private $elements = []; + private array $elements = []; + /** + * @param T[] $elements + */ private function __construct(array $elements = []) { foreach ($elements as $element) { @@ -30,6 +33,13 @@ private function __construct(array $elements = []) } } + /** + * @template U + * + * @param U[] $elements + * + * @return self + */ private static function fromPointer(array &$elements): self { $set = new self(); @@ -38,6 +48,9 @@ private static function fromPointer(array &$elements): self return $set; } + /** + * @return self + */ public static function empty(): self { return new self(); @@ -48,7 +61,7 @@ public static function empty(): self * * @param U ...$elements * - * @return Set + * @return self */ public static function of(...$elements): self { @@ -60,7 +73,7 @@ public static function of(...$elements): self * * @param U[] $elements * - * @return Set + * @return self */ public static function ofAll(array $elements): self { @@ -75,7 +88,7 @@ public function length(): int /** * @param T $element * - * @return Set + * @return self */ public function add($element): self { @@ -90,9 +103,9 @@ public function add($element): self } /** - * @param Set $elements + * @param self $elements * - * @return Set + * @return self */ public function addAll(Set $elements): self { @@ -109,7 +122,7 @@ public function addAll(Set $elements): self /** * @param T $element * - * @return Set + * @return self */ public function remove($element): self { @@ -128,9 +141,9 @@ public function remove($element): self } /** - * @param Set $elements + * @param self $elements * - * @return Set + * @return self */ public function removeAll(Set $elements): self { @@ -145,9 +158,9 @@ public function removeAll(Set $elements): self } /** - * @param Set $set + * @param self $set * - * @return Set + * @return self */ public function union(Set $set): self { @@ -172,9 +185,9 @@ public function union(Set $set): self } /** - * @param Set $set + * @param self $set * - * @return Set + * @return self */ public function diff(Set $set): self { @@ -183,6 +196,11 @@ public function diff(Set $set): self return self::fromPointer($diff); } + /** + * @param self $set + * + * @return self + */ public function intersect(Set $set): self { $intersect = array_intersect($this->elements, $set->elements); @@ -216,7 +234,10 @@ public function head() return $element; } - public function tail() + /** + * @return self + */ + public function tail(): self { $tail = $this->iterator()->toArray(); unset($tail[0]); @@ -229,9 +250,9 @@ public function tail() * * @param callable(T):U $mapper * - * @return Set + * @return self */ - public function map(callable $mapper) + public function map(callable $mapper): self { $mapped = []; $iterator = $this->iterator(); @@ -242,7 +263,14 @@ public function map(callable $mapper) return self::fromPointer($mapped); } - public function flatMap(callable $mapper) + /** + * @template U + * + * @param callable(T):U $mapper + * + * @return self + */ + public function flatMap(callable $mapper): self { $mapped = []; $iterator = $this->iterator(); @@ -259,9 +287,9 @@ public function flatMap(callable $mapper) /** * @param callable(T):bool $predicate * - * @return Set + * @return self */ - public function filter(callable $predicate) + public function filter(callable $predicate): self { $filtered = array_filter($this->elements, $predicate); @@ -269,9 +297,9 @@ public function filter(callable $predicate) } /** - * @return Set + * @return self */ - public function sorted() + public function sorted(): self { $elements = $this->elements; asort($elements); @@ -282,9 +310,9 @@ public function sorted() /** * @param callable(T):bool $predicate * - * @return Set + * @return self */ - public function dropWhile(callable $predicate) + public function dropWhile(callable $predicate): self { $elements = $this->elements; while ($elements !== [] && $predicate(current($elements)) === true) { @@ -295,9 +323,9 @@ public function dropWhile(callable $predicate) } /** - * @return Set + * @return self */ - public function take(int $n) + public function take(int $n): self { if ($n <= 0) { return self::empty(); @@ -312,9 +340,9 @@ public function take(int $n) } /** - * @return Set + * @return self */ - public function drop(int $n) + public function drop(int $n): self { if ($n <= 0) { return $this; diff --git a/src/Collection/Stream.php b/src/Collection/Stream.php index 050b865..4e17366 100644 --- a/src/Collection/Stream.php +++ b/src/Collection/Stream.php @@ -21,7 +21,7 @@ abstract class Stream extends Sequence * * @param U ...$elements * - * @return Stream + * @return self */ public static function of(...$elements): self { @@ -33,13 +33,16 @@ public static function of(...$elements): self * * @param iterable $elements * - * @return Stream + * @return self */ public static function ofAll(iterable $elements): self { $elements = Iterator::fromIterable($elements); if (!$elements->hasNext()) { - return self::empty(); + /** @var self $empty */ + $empty = self::empty(); + + return $empty; } return new Cons($elements->next(), function () use ($elements) { @@ -47,13 +50,16 @@ public static function ofAll(iterable $elements): self }); } + /** + * @return self + */ public static function empty(): self { return EmptyStream::instance(); } /** - * @return Stream + * @return self */ public static function range(int $start = 1, ?int $end = null): self { @@ -135,14 +141,14 @@ public static function cons($head, callable $supplier): self /** * @throws \RuntimeException if is empty * - * @return Stream + * @return self */ abstract public function tail(); /** * @param callable(T):void $action * - * @return Stream + * @return self */ public function peek(callable $action): self { @@ -163,12 +169,15 @@ public function peek(callable $action): self * * @param callable(T):U $mapper * - * @return Stream + * @return self */ public function map(callable $mapper): self { if ($this->isEmpty()) { - return self::empty(); + /** @var self $empty */ + $empty = self::empty(); + + return $empty; } return new Cons($mapper($this->head()), function () use ($mapper) {return $this->tail()->map($mapper); }); @@ -179,7 +188,7 @@ public function map(callable $mapper): self * * @param callable(T): Traversable $mapper * - * @return Stream + * @return self */ public function flatMap(callable $mapper) { @@ -196,7 +205,7 @@ public function flatMap(callable $mapper) /** * @param callable(T):bool $predicate * - * @return Stream + * @return self */ public function filter(callable $predicate) { @@ -217,7 +226,7 @@ public function filter(callable $predicate) } /** - * @return Stream + * @return self */ public function sorted() { @@ -227,7 +236,7 @@ public function sorted() /** * @param callable(T):bool $predicate * - * @return Stream + * @return self */ public function dropWhile(callable $predicate) { @@ -241,7 +250,7 @@ public function dropWhile(callable $predicate) } /** - * @return Stream + * @return self */ public function take(int $n) { @@ -259,7 +268,7 @@ public function take(int $n) } /** - * @return Stream + * @return self */ public function drop(int $n) { @@ -292,7 +301,7 @@ public function collect(Collector $collector) /** * @param T $element * - * @return Stream + * @return self */ public function prepend($element) { @@ -300,7 +309,7 @@ public function prepend($element) } /** - * @return Stream + * @return self */ public function prependAll(Traversable $elements) { diff --git a/src/Collection/Stream/Collectors.php b/src/Collection/Stream/Collectors.php index 5ed4425..be91bd7 100644 --- a/src/Collection/Stream/Collectors.php +++ b/src/Collection/Stream/Collectors.php @@ -93,7 +93,7 @@ public static function counting(): Collector } /** - * @return Collector + * @return Collector> */ public static function averaging(): Collector { diff --git a/src/Collection/Stream/EmptyStream.php b/src/Collection/Stream/EmptyStream.php index e6c03aa..1ff6903 100644 --- a/src/Collection/Stream/EmptyStream.php +++ b/src/Collection/Stream/EmptyStream.php @@ -22,6 +22,9 @@ private function __construct() { } + /** + * @return self + */ public static function instance(): self { return new self(); diff --git a/src/Collection/Traversable.php b/src/Collection/Traversable.php index a73d74e..0cdc4fc 100644 --- a/src/Collection/Traversable.php +++ b/src/Collection/Traversable.php @@ -16,6 +16,8 @@ * @template T * * @template-extends Value + * + * @implements \IteratorAggregate */ abstract class Traversable extends Value implements \IteratorAggregate { diff --git a/src/Control/TryTo.php b/src/Control/TryTo.php index ee6ff2c..c946155 100644 --- a/src/Control/TryTo.php +++ b/src/Control/TryTo.php @@ -21,7 +21,7 @@ abstract class TryTo extends Value * * @param callable():U $supplier * - * @return TryTo + * @return self */ public static function run(callable $supplier): self { @@ -42,7 +42,7 @@ public function isSingleValued(): bool * * @param callable(T): U $mapper * - * @return TryTo + * @return self */ public function map(callable $mapper) { @@ -67,7 +67,7 @@ public function iterator(): Iterator * * @param callable(\Throwable):U $recovery * - * @return TryTo + * @return self */ public function recover(string $throwable, callable $recovery): self { @@ -83,6 +83,9 @@ public function recover(string $throwable, callable $recovery): self return $this; } + /** + * @return self + */ public function andThen(callable $callable): self { if ($this->isFailure()) { @@ -98,6 +101,9 @@ public function andThen(callable $callable): self } } + /** + * @return self + */ public function andFinally(callable $callable): self { try { @@ -109,6 +115,9 @@ public function andFinally(callable $callable): self } } + /** + * @return self + */ public function onSuccess(callable $consumer): self { if ($this->isSuccess()) { @@ -118,6 +127,9 @@ public function onSuccess(callable $consumer): self return $this; } + /** + * @return self + */ public function onFailure(callable $consumer): self { if ($this->isFailure()) { @@ -127,6 +139,9 @@ public function onFailure(callable $consumer): self return $this; } + /** + * @return self + */ public function onSpecificFailure(string $throwable, callable $consumer): self { if ($this->isFailure()) { diff --git a/src/Lazy.php b/src/Lazy.php index 4719cc0..264f9ce 100644 --- a/src/Lazy.php +++ b/src/Lazy.php @@ -89,6 +89,9 @@ public function get() return $this->supplier === null ? $this->value : $this->computeValue(); } + /** + * @return T + */ public function __invoke() { return $this->get(); diff --git a/tests/Collection/MapTest.php b/tests/Collection/MapTest.php index 6fe7065..348835e 100644 --- a/tests/Collection/MapTest.php +++ b/tests/Collection/MapTest.php @@ -286,7 +286,7 @@ public function testMapSorted(): void public function testFlatMap(): void { - self::assertTrue(Map::fromArray(['a' => 'b', 'c' => 'd'])->flatMap(fn ($tuple) => GenericList::of($tuple, Tuple::of($tuple[1], $tuple[0])))->equals( + self::assertTrue(Map::fromArray(['a' => 'b', 'c' => 'd'])->flatMap(fn ($tuple) => GenericList::of($tuple, Tuple::of($tuple[1], $tuple[0])))->equals( // @phpstan-ignore argument.type Map::fromArray(['a' => 'b', 'b' => 'a', 'c' => 'd', 'd' => 'c']) )); } diff --git a/tests/Collection/SetTest.php b/tests/Collection/SetTest.php index 9299097..1e76e8c 100644 --- a/tests/Collection/SetTest.php +++ b/tests/Collection/SetTest.php @@ -266,7 +266,7 @@ public function testSetRemoveAll(): void self::assertTrue(Set::ofAll(['alpha', 'beta', 'gamma'])->removeAll(Set::ofAll(['1', '2', 'gamma']))->equals(Set::ofAll(['alpha', 'beta']))); } - public function testSetDisjoint() + public function testSetDisjoint(): void { self::assertTrue(Set::of('a', 'b', 'c')->disjoint(Set::empty())); self::assertTrue(Set::empty()->disjoint(Set::of('a', 'b', 'c'))); @@ -277,7 +277,7 @@ public function testSetDisjoint() self::assertFalse(Set::of('a', 'b', 'c')->disjoint(Set::of('d', 'e', 'c'))); } - public function testSetAddAll() + public function testSetAddAll(): void { self::assertTrue(Set::of('a', 'b', 'c')->equals(Set::of('a')->addAll(Set::of('b', 'c')))); self::assertTrue(Set::of('a', 'b', 'c')->equals(Set::empty()->addAll(Set::of('a', 'b', 'c')))); diff --git a/tests/Control/OptionTest.php b/tests/Control/OptionTest.php index d6b3c2d..ea401b1 100644 --- a/tests/Control/OptionTest.php +++ b/tests/Control/OptionTest.php @@ -58,17 +58,13 @@ public function testGetOrSomething(): void public function testMap(): void { - $option = Option::of('munus'); - - self::assertInstanceOf(Option::class, $option->map('strtolower')); - self::assertEquals('MUNUS', $option->map('strtoupper')->get()); + self::assertEquals('MUNUS', Option::of('munus')->map('strtoupper')->get()); } public function testFlatMapSome(): void { $option = Option::of('munus'); - self::assertInstanceOf(Option::class, $option->flatMap(fn (string $value) => Option::some($value))); self::assertEquals('munus', $option->flatMap(fn (string $value) => Option::some($value))->get()); self::assertEquals('2', $option->flatMap(fn () => Option::of('2'))->get()); self::assertTrue(Option::none()->equals($option->flatMap(fn () => Option::none()))); diff --git a/tests/Helpers/TupleConcatTestHelper.php b/tests/Helpers/TupleConcatTestHelper.php deleted file mode 100644 index 335e515..0000000 --- a/tests/Helpers/TupleConcatTestHelper.php +++ /dev/null @@ -1,59 +0,0 @@ - $values */ public function testTupleArity(array $values, int $arity): void { self::assertEquals($arity, Tuple::of(...$values)->arity()); } + /** + * @return array> + */ public static function arityTestData(): array { return [ @@ -63,12 +67,17 @@ public function testTupleArrayAccess(): void /** * @dataProvider toArrayTestData + * + * @param array $values */ public function testTupleToArray(array $values): void { self::assertEquals($values, Tuple::of(...$values)->toArray()); } + /** + * @return array>> + */ public static function toArrayTestData(): array { return [ @@ -86,6 +95,10 @@ public static function toArrayTestData(): array /** * @dataProvider concatTestData + * + * @param array $firstValues + * @param array $secondValues + * @param array $result */ public function testTupleConcat(array $firstValues, array $secondValues, string $method, array $result): void { @@ -97,9 +110,58 @@ public function testTupleConcat(array $firstValues, array $secondValues, string self::assertEquals($result, $newTuple->toArray()); } + /** + * @return array|string>> + */ public static function concatTestData(): array { - return TupleConcatTestHelper::concatTestData(); + return [ + [[], [], 'concatTuple0', []], + [[], ['a'], 'concatTuple1', ['a']], + [[], ['a', 'b'], 'concatTuple2', ['a', 'b']], + [[], ['a', 'b', 'c'], 'concatTuple3', ['a', 'b', 'c']], + [[], ['a', 'b', 'c', 'd'], 'concatTuple4', ['a', 'b', 'c', 'd']], + [[], ['a', 'b', 'c', 'd', 'e'], 'concatTuple5', ['a', 'b', 'c', 'd', 'e']], + [[], ['a', 'b', 'c', 'd', 'e', 'f'], 'concatTuple6', ['a', 'b', 'c', 'd', 'e', 'f']], + [[], ['a', 'b', 'c', 'd', 'e', 'f', 'g'], 'concatTuple7', ['a', 'b', 'c', 'd', 'e', 'f', 'g']], + [[], ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'], 'concatTuple8', ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']], + [['1'], [], 'concatTuple0', ['1']], + [['1'], ['a'], 'concatTuple1', ['1', 'a']], + [['1'], ['a', 'b'], 'concatTuple2', ['1', 'a', 'b']], + [['1'], ['a', 'b', 'c'], 'concatTuple3', ['1', 'a', 'b', 'c']], + [['1'], ['a', 'b', 'c', 'd'], 'concatTuple4', ['1', 'a', 'b', 'c', 'd']], + [['1'], ['a', 'b', 'c', 'd', 'e'], 'concatTuple5', ['1', 'a', 'b', 'c', 'd', 'e']], + [['1'], ['a', 'b', 'c', 'd', 'e', 'f'], 'concatTuple6', ['1', 'a', 'b', 'c', 'd', 'e', 'f']], + [['1'], ['a', 'b', 'c', 'd', 'e', 'f', 'g'], 'concatTuple7', ['1', 'a', 'b', 'c', 'd', 'e', 'f', 'g']], + [['1', '2'], [], 'concatTuple0', ['1', '2']], + [['1', '2'], ['a'], 'concatTuple1', ['1', '2', 'a']], + [['1', '2'], ['a', 'b'], 'concatTuple2', ['1', '2', 'a', 'b']], + [['1', '2'], ['a', 'b', 'c'], 'concatTuple3', ['1', '2', 'a', 'b', 'c']], + [['1', '2'], ['a', 'b', 'c', 'd'], 'concatTuple4', ['1', '2', 'a', 'b', 'c', 'd']], + [['1', '2'], ['a', 'b', 'c', 'd', 'e'], 'concatTuple5', ['1', '2', 'a', 'b', 'c', 'd', 'e']], + [['1', '2'], ['a', 'b', 'c', 'd', 'e', 'f'], 'concatTuple6', ['1', '2', 'a', 'b', 'c', 'd', 'e', 'f']], + [['1', '2', '3'], [], 'concatTuple0', ['1', '2', '3']], + [['1', '2', '3'], ['a'], 'concatTuple1', ['1', '2', '3', 'a']], + [['1', '2', '3'], ['a', 'b'], 'concatTuple2', ['1', '2', '3', 'a', 'b']], + [['1', '2', '3'], ['a', 'b', 'c'], 'concatTuple3', ['1', '2', '3', 'a', 'b', 'c']], + [['1', '2', '3'], ['a', 'b', 'c', 'd'], 'concatTuple4', ['1', '2', '3', 'a', 'b', 'c', 'd']], + [['1', '2', '3'], ['a', 'b', 'c', 'd', 'e'], 'concatTuple5', ['1', '2', '3', 'a', 'b', 'c', 'd', 'e']], + [['1', '2', '3', '4'], [], 'concatTuple0', ['1', '2', '3', '4']], + [['1', '2', '3', '4'], ['a'], 'concatTuple1', ['1', '2', '3', '4', 'a']], + [['1', '2', '3', '4'], ['a', 'b'], 'concatTuple2', ['1', '2', '3', '4', 'a', 'b']], + [['1', '2', '3', '4'], ['a', 'b', 'c'], 'concatTuple3', ['1', '2', '3', '4', 'a', 'b', 'c']], + [['1', '2', '3', '4'], ['a', 'b', 'c', 'd'], 'concatTuple4', ['1', '2', '3', '4', 'a', 'b', 'c', 'd']], + [['1', '2', '3', '4', '5'], [], 'concatTuple0', ['1', '2', '3', '4', '5']], + [['1', '2', '3', '4', '5'], ['a'], 'concatTuple1', ['1', '2', '3', '4', '5', 'a']], + [['1', '2', '3', '4', '5'], ['a', 'b'], 'concatTuple2', ['1', '2', '3', '4', '5', 'a', 'b']], + [['1', '2', '3', '4', '5'], ['a', 'b', 'c'], 'concatTuple3', ['1', '2', '3', '4', '5', 'a', 'b', 'c']], + [['1', '2', '3', '4', '5', '6'], [], 'concatTuple0', ['1', '2', '3', '4', '5', '6']], + [['1', '2', '3', '4', '5', '6'], ['a'], 'concatTuple1', ['1', '2', '3', '4', '5', '6', 'a']], + [['1', '2', '3', '4', '5', '6'], ['a', 'b'], 'concatTuple2', ['1', '2', '3', '4', '5', '6', 'a', 'b']], + [['1', '2', '3', '4', '5', '6', '7'], [], 'concatTuple0', ['1', '2', '3', '4', '5', '6', '7']], + [['1', '2', '3', '4', '5', '6', '7'], ['a'], 'concatTuple1', ['1', '2', '3', '4', '5', '6', '7', 'a']], + [['1', '2', '3', '4', '5', '6', '7', '8'], [], 'concatTuple0', ['1', '2', '3', '4', '5', '6', '7', '8']], + ]; } public function testTupleConcatFail(): void @@ -113,12 +175,18 @@ public function testTupleConcatFail(): void /** * @dataProvider appendTestData + * + * @param array $expected + * @param array $values */ public function testTupleAppend(array $expected, array $values, string $appendValue): void { self::assertEquals($expected, Tuple::of(...$values)->append($appendValue)->toArray()); } + /** + * @return array|string>> + */ public static function appendTestData(): array { return [ @@ -135,12 +203,18 @@ public static function appendTestData(): array /** * @dataProvider prependTestData + * + * @param array $expected + * @param array $values */ public function testTuplePrepend(array $expected, array $values, string $appendValue): void { self::assertEquals($expected, Tuple::of(...$values)->prepend($appendValue)->toArray()); } + /** + * @return array|string>> + */ public static function prependTestData(): array { return [