Skip to content

Commit 2c85d8b

Browse files
authored
Merge pull request #3 from SpacePossum/SpacePossum-patch-1
Prepare for release 1.0
2 parents f0199a3 + 7da6191 commit 2c85d8b

File tree

5 files changed

+24
-73
lines changed

5 files changed

+24
-73
lines changed

.travis.yml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,28 @@ sudo: false
88
matrix:
99
fast_finish: true
1010
include:
11-
- php: 5.6
12-
env: COMPOSER_FLAGS="--prefer-stable"
1311
- php: 7.0
1412
env: COMPOSER_FLAGS="--prefer-stable"
1513
- php: 7.1
1614
env: COMPOSER_FLAGS="--dev"
17-
- php: hhvm-3.12
18-
sudo: required
19-
dist: trusty
20-
group: edge
21-
env: COMPOSER_FLAGS="--prefer-stable"
22-
- php: hhvm-nightly
23-
sudo: required
24-
dist: trusty
25-
group: edge
15+
- php: nightly
2616
env: COMPOSER_FLAGS="--dev"
2717
allow_failures:
28-
- php: hhvm-nightly
18+
- php: nightly
19+
20+
services:
21+
- mongodb
22+
23+
before_install:
24+
- INI_FILE=$(echo "<?php echo get_cfg_var('cfg_file_path');"|php);
25+
- echo $INI_FILE;
26+
- echo extension=mongodb.so >> $INI_FILE;
2927

3028
install:
3129
- composer update $COMPOSER_FLAGS --no-interaction -v
3230
- if [[ $TRAVIS_PHP_VERSION = 7.0 ]]; then curl -L https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v1.12.1/php-cs-fixer.phar -o php-cs-fixer.phar; fi
3331

3432
script:
35-
- composer show twig/twig
3633
- phpunit --verbose
3734
- phpenv config-rm xdebug.ini || return 0
38-
- if [[ $TRAVIS_PHP_VERSION = 7.0 ]]; then php php-cs-fixer.phar --dry-run -vvv fix; fi
35+
- if [[ $TRAVIS_PHP_VERSION = 7.0 ]]; then php php-cs-fixer.phar --dry-run --diff -vvv fix; fi

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The iterator can return the values it reads from the file by converting those in
1010

1111
### Requirements
1212

13-
PHP 5.6 (PHP 7 supported). Optional HHVM support >= 3.12.
13+
PHP 7
1414
This package is framework agnostic.
1515

1616
### Install

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"license": "MIT",
77
"keywords": ["BSON", "Iterator"],
88
"require": {
9-
"php": "^5.6.0 || >=7.0 <7.2",
9+
"php": ">=7.0 <7.3",
1010
"mongodb/mongodb": "^1.0.0"
1111
},
1212
"require-dev": {

src/Bson/BsonFileIterator.php

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* with this source code in the file LICENSE.
1010
*/
1111

12+
declare(strict_types=1);
13+
1214
namespace GeckoPackages\Bson;
1315

1416
/**
@@ -64,14 +66,14 @@ final class BsonFileIterator implements \Iterator
6466
*/
6567
public function __construct(
6668
$file,
67-
$constructType = 1,
68-
$maxUnpackSize = 5242880, // 5*1024*1024 bytes
69-
$jsonDecodeMaxDepth = 512,
70-
$jsonDecodeOptions = 0
69+
int $constructType = 1,
70+
int $maxUnpackSize = 5242880, // 5*1024*1024 bytes
71+
int $jsonDecodeMaxDepth = 512,
72+
int $jsonDecodeOptions = 0
7173
) {
7274
$this->resolveFileHandle($file);
7375
$this->resolveDecoder($constructType, $jsonDecodeMaxDepth, $jsonDecodeOptions);
74-
$this->resolveMaxUnpackSize($maxUnpackSize, $file);
76+
$this->resolveMaxUnpackSize($maxUnpackSize, $file instanceof \SplFileInfo ? $file->getPathname() : $file);
7577
}
7678

7779
public function __destruct()
@@ -183,16 +185,8 @@ private function resolveFileHandle($file)
183185
$this->fileHandle = $fileHandle;
184186
}
185187

186-
private function resolveDecoder($constructType, $jsonDecodeMaxDepth, $jsonDecodeOptions)
188+
private function resolveDecoder(int $constructType, int $jsonDecodeMaxDepth, int $jsonDecodeOptions)
187189
{
188-
if (!is_int($constructType)) {
189-
throw new \InvalidArgumentException(sprintf(
190-
'Construct type must be any of integers "%s" got "%s".',
191-
implode(', ', [self::CONSTRUCT_JSON, self::CONSTRUCT_ARRAY, self::CONSTRUCT_STD]),
192-
is_object($constructType) ? get_class($constructType) : gettype($constructType).(is_resource($constructType) ? '' : '#'.$constructType)
193-
));
194-
}
195-
196190
switch ($constructType) {
197191
case self::CONSTRUCT_JSON:
198192
$this->decoder = function ($key, $content) {
@@ -215,20 +209,13 @@ private function resolveDecoder($constructType, $jsonDecodeMaxDepth, $jsonDecode
215209
));
216210
}
217211

218-
if (!is_int($jsonDecodeMaxDepth) || $jsonDecodeMaxDepth < 1) {
212+
if ($jsonDecodeMaxDepth < 1) {
219213
throw new \InvalidArgumentException(sprintf(
220214
'Expected integer > 0 for JSON decode max depth, got "%s".',
221215
is_object($jsonDecodeMaxDepth) ? get_class($jsonDecodeMaxDepth) : gettype($jsonDecodeMaxDepth).(is_resource($jsonDecodeMaxDepth) ? '' : '#'.$jsonDecodeMaxDepth)
222216
));
223217
}
224218

225-
if (!is_int($jsonDecodeOptions)) {
226-
throw new \InvalidArgumentException(sprintf(
227-
'Expected integer for JSON decode options, got "%s".',
228-
is_object($jsonDecodeOptions) ? get_class($jsonDecodeOptions) : gettype($jsonDecodeOptions).(is_resource($jsonDecodeOptions) ? '' : '#'.$jsonDecodeOptions)
229-
));
230-
}
231-
232219
$this->decoder = function ($key, $content) use ($assoc, $jsonDecodeMaxDepth, $jsonDecodeOptions) {
233220
$content = @json_decode($content, $assoc, $jsonDecodeMaxDepth, $jsonDecodeOptions);
234221
if (null === $content) {
@@ -245,9 +232,9 @@ private function resolveDecoder($constructType, $jsonDecodeMaxDepth, $jsonDecode
245232
*
246233
* @throws \InvalidArgumentException
247234
*/
248-
private function resolveMaxUnpackSize($maxUnpackSize, $file)
235+
private function resolveMaxUnpackSize(int $maxUnpackSize, string $file)
249236
{
250-
if (!is_int($maxUnpackSize) || $maxUnpackSize <= 0) {
237+
if ($maxUnpackSize <= 0) {
251238
throw new \InvalidArgumentException(sprintf(
252239
'Expected integer > 0 for max. unpack size, got "%s".',
253240
is_object($maxUnpackSize) ? get_class($maxUnpackSize) : gettype($maxUnpackSize).(is_resource($maxUnpackSize) ? '' : '#'.$maxUnpackSize)

tests/Bson/BsonFileIteratorTest.php

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,6 @@ public function testIteratorFileEmpty()
191191
$this->assertCount(0, $iterator);
192192
}
193193

194-
/**
195-
* @expectedException \InvalidArgumentException
196-
* @expectedExceptionMessageRegExp #^Construct type must be any of integers \"1, 2, 3\" got \"stdClass\".$#
197-
*/
198-
public function testIteratorInvalidConstructionOtherType()
199-
{
200-
new BsonFileIterator($this->getAssetDir().'test.bson', new \stdClass());
201-
}
202-
203194
/**
204195
* @expectedException \InvalidArgumentException
205196
* @expectedExceptionMessageRegExp #^Construct type must be any of integers \"1, 2, 3\" got \"777\".$#
@@ -209,15 +200,6 @@ public function testIteratorInvalidConstructionValueInt()
209200
new BsonFileIterator($this->getAssetDir().'test.bson', 777);
210201
}
211202

212-
/**
213-
* @expectedException \InvalidArgumentException
214-
* @expectedExceptionMessageRegExp #^Construct type must be any of integers \"1, 2, 3\" got \"NULL\#\".$#
215-
*/
216-
public function testIteratorInvalidConstructionValueNull()
217-
{
218-
new BsonFileIterator($this->getAssetDir().'test.bson', null);
219-
}
220-
221203
/**
222204
* @expectedException \UnexpectedValueException
223205
* @expectedExceptionMessageRegExp #^Invalid data at item \#1, size 12435439 exceeds max. unpack size 372.$#
@@ -279,21 +261,6 @@ public function testIteratorInvalidJsonDecodeMaxDepthValue()
279261
);
280262
}
281263

282-
/**
283-
* @expectedException \InvalidArgumentException
284-
* @expectedExceptionMessageRegExp #^Expected integer for JSON decode options, got \"stdClass\".$#
285-
*/
286-
public function testIteratorInvalidJsonDecodeOptionsType()
287-
{
288-
new BsonFileIterator(
289-
$this->getAssetDir().'empty.bson',
290-
BsonFileIterator::CONSTRUCT_ARRAY,
291-
5242880,
292-
10,
293-
new \stdClass()
294-
);
295-
}
296-
297264
/**
298265
* @expectedException \InvalidArgumentException
299266
* @expectedExceptionMessageRegExp #^Expected integer > 0 for max. unpack size, got \"integer\#-1\".$#

0 commit comments

Comments
 (0)