Skip to content

Commit

Permalink
refactor: Update times constructor.
Browse files Browse the repository at this point in the history
Signed-off-by: Pol Dellaiera <pol.dellaiera@protonmail.com>
  • Loading branch information
drupol committed Oct 11, 2020
1 parent ca75d99 commit 3cec95a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 8 additions & 5 deletions spec/loophp/collection/CollectionSpec.php
Expand Up @@ -8,7 +8,6 @@
use Closure;
use Exception;
use Generator;
use InvalidArgumentException;
use Iterator;
use JsonSerializable;
use loophp\collection\Collection;
Expand Down Expand Up @@ -2629,8 +2628,7 @@ public function it_can_use_times_with_a_callback(): void
->shouldIterateAs($a);

$this::times(-1, 'count')
->shouldThrow(InvalidArgumentException::class)
->during('all');
->shouldIterateAs([]);
}

public function it_can_use_times_without_a_callback(): void
Expand All @@ -2639,11 +2637,16 @@ public function it_can_use_times_without_a_callback(): void
->shouldIterateAs(range(1, 10));

$this::times(-5)
->shouldThrow(InvalidArgumentException::class)
->during('all');
->shouldIterateAs([]);

$this::times(1)
->shouldIterateAs([1]);

$this::times(0)
->shouldIterateAs([]);

$this::times()
->shouldIterateAs([]);
}

public function it_can_use_with(): void
Expand Down
3 changes: 1 addition & 2 deletions src/Operation/Times.php
Expand Up @@ -6,7 +6,6 @@

use Closure;
use Generator;
use InvalidArgumentException;
use Iterator;

/**
Expand Down Expand Up @@ -42,7 +41,7 @@ static function (?callable $callback = null) use ($number): Closure {
*/
static function (?Iterator $iterator = null) use ($number, $callback): Generator {
if (1 > $number) {
throw new InvalidArgumentException('Invalid parameter. $number must be greater than 1.');
yield from [];
}

$callback = $callback ?? static function (int $value): int {
Expand Down

0 comments on commit 3cec95a

Please sign in to comment.