Skip to content

Commit

Permalink
docs: do not create ArrayIterator.
Browse files Browse the repository at this point in the history
It's not needed anymore since a69acec
  • Loading branch information
drupol committed Sep 28, 2022
1 parent 31f87a8 commit 806fa18
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 65 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -675,11 +675,6 @@ parameters:
count: 1
path: tests/static-analysis/flatMap.php

-
message: "#^Parameter \\#1 \\$callable of static method loophp\\\\collection\\\\Collection\\<mixed,mixed\\>\\:\\:fromCallable\\(\\) expects callable\\(\\.\\.\\.mixed\\)\\: iterable\\<string, int\\>, Closure\\(int\\)\\: ArrayIterator\\<string, int\\> given\\.$#"
count: 1
path: tests/static-analysis/fromCallable.php

-
message: "#^Parameter \\#1 \\$callable of method loophp\\\\collection\\\\Collection\\<int,string\\>\\:\\:groupBy\\(\\) expects callable\\(string\\=, int\\=\\)\\: int, Closure\\(string, int\\)\\: int given\\.$#"
count: 1
Expand Down
9 changes: 0 additions & 9 deletions tests/static-analysis/fromCallable.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ function fromCallable_checkMixed(CollectionInterface $collection): void
$arrayMap = static fn (): array => ['myKey' => 1];
$arrayMixed = static fn (): array => [1, 2, '3', 'b', 5];

/** @var Closure(): ArrayIterator<int, int> $arrayIteratorList */
$arrayIteratorList = static fn (int $a, int $b): ArrayIterator => new ArrayIterator(range($a, $b));
$arrayIteratorMap = static fn (int $x): ArrayIterator => new ArrayIterator(['myKey' => $x]);
$arrayIteratorMixed = static fn (): ArrayIterator => new ArrayIterator([1, 2, '3', 5, 'b']);

$classWithMethod = new class() {
/**
* @return Generator<string, int>
Expand Down Expand Up @@ -133,10 +128,6 @@ public function __invoke(): Generator
fromCallable_checkMap(Collection::fromCallable($arrayMap));
fromCallable_checkMixed(Collection::fromCallable($arrayMixed));

fromCallable_checkList(Collection::fromCallable($arrayIteratorList, [1, 3]));
fromCallable_checkMap(Collection::fromCallable($arrayIteratorMap, [1]));
fromCallable_checkMixed(Collection::fromCallable($arrayIteratorMixed));

fromCallable_checkList(Collection::fromCallable([$classWithMethod, 'getValues']));
fromCallable_checkMap(Collection::fromCallable([$classWithMethod, 'getKeyValues']));
fromCallable_checkMixed(Collection::fromCallable([$classWithMethod, 'getMixed']));
Expand Down
6 changes: 3 additions & 3 deletions tests/static-analysis/fromIterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ function fromIterable_checkMixed(CollectionInterface $collection): void
$arrayMap = ['foo' => 1, 'bar' => 2];
$arrayMixed = [1, 2, '3', 'b', 5];

$arrayIteratorList = new ArrayIterator(range(1, 3));
$arrayIteratorMap = new ArrayIterator(['foo' => 1, 'bar' => 2]);
$arrayIteratorMixed = new ArrayIterator([1, 2, '3', 'b', 5]);
$arrayIteratorList = range(1, 3);
$arrayIteratorMap = ['foo' => 1, 'bar' => 2];
$arrayIteratorMixed = [1, 2, '3', 'b', 5];

fromIterable_checkList(Collection::fromIterable($generatorList()));
fromIterable_checkMap(Collection::fromIterable($generatorMap()));
Expand Down
8 changes: 0 additions & 8 deletions tests/unit/CollectionConstructorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace tests\loophp\collection;

use ArrayIterator;
use Generator;
use InvalidArgumentException;
use loophp\collection\Collection;
Expand Down Expand Up @@ -54,13 +53,6 @@ public function testFromCallableConstructor(): void
$test2
);

$test3 = Collection::fromCallable(static fn (int $a, int $b): ArrayIterator => new ArrayIterator(range($a, $b)), [1, 5]);
self::assertInstanceOf(Collection::class, $test3);
self::assertIdenticalIterable(
range(1, 5),
$test3
);

$classWithMethod = new class() {
public function getValues(): Generator
{
Expand Down
41 changes: 12 additions & 29 deletions tests/unit/CollectionSpecificOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace tests\loophp\collection;

use ArrayIterator;
use Closure;
use Exception;
use Generator;
Expand Down Expand Up @@ -157,51 +156,45 @@ public function testCoalesceOperation(): void
{
$input = range('a', 'e');

$iterator = new ArrayIterator($input);

$coalesce = new Coalesce();

self::assertCount(1, $coalesce->__invoke()($iterator));
self::assertCount(1, $coalesce->__invoke()($input));

self::assertIdenticalIterable(
[
0 => 'a',
],
$coalesce->__invoke()($iterator)
$coalesce->__invoke()($input)
);

$input = ['', null, 'foo', false, ...range('a', 'e')];

$iterator = new ArrayIterator($input);

self::assertCount(1, $coalesce->__invoke()($iterator));
self::assertCount(1, $coalesce->__invoke()($input));

self::assertIdenticalIterable(
[
2 => 'foo',
],
$coalesce->__invoke()($iterator)
$coalesce->__invoke()($input)
);
}

public function testCurrentOperation(): void
{
$input = range('a', 'e');

$iterator = new ArrayIterator($input);

$current = new Current();

self::assertIdenticalIterable(
['a'],
$current->__invoke()(0)(null)($iterator)
$current->__invoke()(0)(null)($input)
);

self::assertCount(1, $current->__invoke()(0)(null)($iterator));
self::assertCount(1, $current->__invoke()(0)(null)($input));

self::assertIdenticalIterable(
['unavailable'],
$current->__invoke()(10)('unavailable')($iterator)
$current->__invoke()(10)('unavailable')($input)
);
}

Expand Down Expand Up @@ -307,30 +300,20 @@ public function testLimitOperation(): void
$limit = new Limit();
$input = range('a', 'e');

$iterator = new ArrayIterator($input);

self::assertCount(1, $limit()(1)(0)($iterator));

self::assertCount(2, $limit()(2)(0)($iterator));
self::assertCount(1, $limit()(1)(0)($input));

$input = range('a', 'e');

$iterator = new ArrayIterator($input);
self::assertCount(2, $limit()(2)(0)($input));

self::assertIdenticalIterable(
[2 => 'c'],
$limit()(1)(2)($iterator)
$limit()(1)(2)($input)
);

self::assertCount(2, $limit()(2)(2)($iterator));

$input = range('a', 'e');

$iterator = new ArrayIterator($input);
self::assertCount(2, $limit()(2)(2)($input));

self::assertIdenticalIterable(
['a', 'b', 'c', 'd', 'e'],
$limit()()()($iterator)
$limit()()()($input)
);
}

Expand Down
12 changes: 1 addition & 11 deletions tests/unit/Traits/GenericCollectionProviders.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace tests\loophp\collection\Traits;

use ArrayIterator;
use ArrayObject;
use Closure;
use Doctrine\Common\Collections\Criteria;
Expand Down Expand Up @@ -1502,15 +1501,6 @@ public function flatMapOperationProvider()
$gen(),
];

yield [
$operation,
[
static fn (int $item): iterable => new ArrayIterator([$item * $item]),
],
$input,
$gen(),
];

$output = static function () {
yield 0 => 2;

Expand Down Expand Up @@ -1666,7 +1656,7 @@ public function flattenOperationProvider()
yield [
$operation,
[],
[1, new ArrayIterator([2, 3]), 4],
[1, [2, 3], 4],
$output(),
];
}
Expand Down

0 comments on commit 806fa18

Please sign in to comment.