Skip to content

Commit 9e974f6

Browse files
committed
Update based on PR feedback
1 parent 36f9d99 commit 9e974f6

File tree

5 files changed

+14
-18
lines changed

5 files changed

+14
-18
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ composer install
3333
composer test-coverage
3434
```
3535

36-
To run tests in a docker container (without coverage):
37-
38-
```bash
39-
docker run -it --rm --workdir /app --volume .:/app php:8.1 php vendor/bin/phpunit tests/
40-
```
41-
4236
## Usage
4337

4438
The library defines interfaces to deal with collections and also boilerplate code with default implementations.

docs/collection-interfaces.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ $collection->add($item1)->add($item2);
5151
public function chunk(int $size): array
5252
```
5353

54-
This method [mirrors the behavior of `array_chunk`](https://www.php.net/manual/function.array-chunk.php) and returns a zero indexed numeric array of the current Collection based on the chunk size provided.
54+
This method [mirrors the behavior of `array_chunk`](https://www.php.net/manual/function.array-chunk.php) and returns a zero indexed numeric array of the current collection based on the chunk size provided.
5555

5656
### diff
5757

docs/collection-trait.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Internally it is call the `ArrayIterator::append` and returning the instance to
9797

9898
## chunk
9999

100-
This method [mirrors the behavior of `array_chunk`](https://www.php.net/manual/function.array-chunk.php) and returns a zero indexed numeric array of the current Collection based on the chunk size provided.
100+
Internally this method chunks [a copy](https://www.php.net/manual/arrayobject.getarraycopy.php) of the collection with the [`array_chunk` php function](https://www.php.net/manual/function.array-chunk.php), returning a zero indexed array of collections of the same type as the initial one.
101101

102102
## diff
103103

@@ -123,7 +123,7 @@ Internally, this method will iterate through each item of a collection, optional
123123

124124
## eachChunk
125125

126-
This method chunks the collection and executes the given anonymous function with each chunk.
126+
Internally, this method calls the [chunk](#chunk) function and then executes the passed anonymous function with each chunk.
127127

128128
## empty
129129

src/CollectionTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function chunk(int $size): array
4343

4444
return array_map(
4545
static fn(array $chunk) => self::fromIterable($chunk),
46-
array_chunk($this->toArray(), $size)
46+
array_chunk($this->getArrayCopy(), $size)
4747
);
4848
}
4949

tests/CollectionTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,11 @@ public function testReverse(): void
486486
}
487487

488488
#[DataProvider('chunkDataProvider')]
489-
public function testChunk(Collection $collectionToChunk, int $chunkSize, array $expectedChunks): void
489+
public function testChunk(Collection $collection, int $chunkSize, array $expectedChunks): void
490490
{
491491
self::assertEquals(
492492
$expectedChunks,
493-
$collectionToChunk->chunk($chunkSize)
493+
$collection->chunk($chunkSize)
494494
);
495495
}
496496

@@ -603,14 +603,16 @@ public static function eachDataProvider(): array
603603
}
604604

605605
#[DataProvider('chunkEachDataProvider')]
606-
public function testChunkEach(Collection $collectionToChunk, int $chunkSize, array $expectedChunks): void
606+
public function testChunkEach(Collection $collection, int $chunkSize, array $expectedChunks): void
607607
{
608-
$expectedLambda = function(CollectionStub $collection) use ($expectedChunks): void {
609-
static $i = 0;
610-
self::assertEquals($collection, $expectedChunks[$i++]);
611-
};
608+
$i = 0;
612609

613-
$collectionToChunk->eachChunk($chunkSize, $expectedLambda);
610+
$collection->eachChunk(
611+
$chunkSize,
612+
function(CollectionStub $collection) use (&$i, $expectedChunks): void {
613+
self::assertEquals($collection, $expectedChunks[$i++]);
614+
}
615+
);
614616
}
615617

616618
public static function chunkEachDataProvider(): array

0 commit comments

Comments
 (0)