Skip to content

Commit

Permalink
Merge 7ed8a4e into 18e32d9
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed May 16, 2017
2 parents 18e32d9 + 7ed8a4e commit b94b561
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 34 deletions.
19 changes: 12 additions & 7 deletions README.md
Expand Up @@ -86,32 +86,37 @@ this package as well as its dependencies.
To add this package as a local, per-project dependency to your project, simply add a
dependency on `jeroen/batching-iterator` to your project's `composer.json` file.
Here is a minimal example of a `composer.json` file that just defines a dependency on
BatchingIterator 2.0:
BatchingIterator 3.x:

```json
{
"require": {
"jeroen/batching-iterator": "~2.0"
"jeroen/batching-iterator": "~3.0"
}
}
```

## Release notes

#### Version 2.1.2 (2014-11-02)
### Version 3.0.0 (2017-05-16)

* Dropped support for PHP 5.x
* Added scalar and return type hints

### Version 2.1.2 (2014-11-02)

* The max batch size in `BatchingIterator` now defaults to 10, avoiding usage of the
iterator without this value being set.

#### Version 2.1.1 (2014-08-19)
### Version 2.1.1 (2014-08-19)

* Release with package name `jeroen/batching-iterator` instead of `jeroen-de-dauw/batching-iterator`.

#### Version 2.1 (2014-07-19)
### Version 2.1 (2014-07-19)

* `MultipleBatchingFetcher` now accepts an array of `BatchingFetcher` in its constructor

#### Version 2.0 (2014-07-19)
### Version 2.0 (2014-07-19)

Breaking changes:

Expand All @@ -124,7 +129,7 @@ New features and enhancements:
* Added `MultipleBatchingFetcher`
* Added `IteratorBasedBatchingFetcher`

#### Version 1.0 (2014-07-03)
### Version 1.0 (2014-07-03)

Initial release with

Expand Down
14 changes: 7 additions & 7 deletions src/BatchingFetcher.php
@@ -1,29 +1,29 @@
<?php

declare( strict_types = 1 );

namespace BatchingIterator;

/**
* @since 1.0
* @since 3.0
* @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
interface BatchingFetcher {

/**
* Fetches the next n values for a BatchingFetcher.
* Should return an empty array when there are no further results.
* Values are not allowed to be null.
* Returns up to $maxFetchCount values.
* An empty array indicates there are no further results.
* Values are NOT ALLOWED TO BE NULL.
*
* @param int $maxFetchCount
*
* @return array
*/
public function fetchNext( $maxFetchCount );
public function fetchNext( int $maxFetchCount ): array;

/**
* Rewind the BatchingFetcher to the first element.
*
* @since 2.0
*/
public function rewind();

Expand Down
19 changes: 6 additions & 13 deletions src/BatchingIterator.php
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace BatchingIterator;

use InvalidArgumentException;
Expand Down Expand Up @@ -42,9 +44,6 @@ class BatchingIterator implements \Iterator {
*/
private $key;

/**
* @param BatchingFetcher $fetcher
*/
public function __construct( BatchingFetcher $fetcher ) {
$this->fetcher = $fetcher;
}
Expand All @@ -54,8 +53,8 @@ public function __construct( BatchingFetcher $fetcher ) {
*
* @throws InvalidArgumentException
*/
public function setMaxBatchSize( $maxBatchSize ) {
if ( !is_int( $maxBatchSize ) || $maxBatchSize < 1 ) {
public function setMaxBatchSize( int $maxBatchSize ) {
if ( $maxBatchSize < 1 ) {
throw new InvalidArgumentException( '$maxBatchSize should be an int bigger than 0.' );
}

Expand Down Expand Up @@ -95,17 +94,11 @@ private function nextValueFromNewBatch() {
}
}

/**
* @return int
*/
public function key() {
public function key(): int {
return $this->key;
}

/**
* @return bool
*/
public function valid() {
public function valid(): bool {
return $this->current !== null;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Fetchers/InMemoryBatchingFetcher.php
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace BatchingIterator\Fetchers;

use BatchingIterator\BatchingFetcher;
Expand Down Expand Up @@ -29,7 +31,7 @@ public function __construct( array $values ) {
*
* @return mixed[]
*/
public function fetchNext( $maxFetchCount ) {
public function fetchNext( int $maxFetchCount ): array {
$values = [];

while ( !is_null( key( $this->values ) ) && --$maxFetchCount >= 0 ) {
Expand Down
4 changes: 3 additions & 1 deletion src/Fetchers/IteratorBasedBatchingFetcher.php
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace BatchingIterator\Fetchers;

use BatchingIterator\BatchingFetcher;
Expand Down Expand Up @@ -29,7 +31,7 @@ public function __construct( \Iterator $iterator ) {
*
* @return mixed[]
*/
public function fetchNext( $maxFetchCount ) {
public function fetchNext( int $maxFetchCount ): array {
$values = [];

while ( !is_null( $this->iterator->key() ) && --$maxFetchCount >= 0 ) {
Expand Down
4 changes: 3 additions & 1 deletion src/Fetchers/MultipleBatchingFetcher.php
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace BatchingIterator\Fetchers;

use BatchingIterator\BatchingFetcher;
Expand Down Expand Up @@ -64,7 +66,7 @@ private function attachFetcher( BatchingFetcher $fetcher ) {
*
* @return mixed[]
*/
public function fetchNext( $maxFetchCount ) {
public function fetchNext( int $maxFetchCount ): array {
if ( key( $this->fetchers ) === null ) {
return [];
}
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/BatchingIteratorTest.php
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace Tests\BatchingIterator;

use BatchingIterator\BatchingIterator;
Expand Down Expand Up @@ -89,11 +91,8 @@ public function testSettingInvalidMaxBatchSizeCausesException( $invalidBatchSize
public function invalidBatchSizeProvider() {
return [
[ 0 ],
[ -1 ],
[ -5 ],
[ 4.2 ],
[ '1' ],
[ null ],
[ [] ],
];
}

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Fetchers/InMemoryBatchingFetcherTest.php
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace Tests\BatchingIterator;

use BatchingIterator\Fetchers\InMemoryBatchingFetcher;
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Fetchers/IteratorBasedBatchingFetcherTest.php
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace Tests\BatchingIterator;

use BatchingIterator\Fetchers\IteratorBasedBatchingFetcher;
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/Fetchers/MultipleBatchingFetcherTest.php
@@ -1,5 +1,7 @@
<?php

declare( strict_types = 1 );

namespace Tests\BatchingIterator;

use BatchingIterator\Fetchers\InMemoryBatchingFetcher;
Expand Down

0 comments on commit b94b561

Please sign in to comment.