Skip to content

Commit 150177a

Browse files
committed
Merge pull request #720
2 parents 239e9fa + b689d43 commit 150177a

28 files changed

+103
-103
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ jobs:
4949
- CHECKS=phpcs
5050

5151
# Test remaining supported PHP versions
52-
- stage: Test
53-
php: "5.6"
5452
- stage: Test
5553
php: "7.0"
5654
- stage: Test
@@ -62,7 +60,7 @@ jobs:
6260

6361
# Test against lowest supported dependencies
6462
- stage: Test
65-
php: "5.6"
63+
php: "7.0"
6664
env:
6765
- COMPOSER_OPTIONS=--prefer-lowest
6866

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
{ "name": "Katherine Walker", "email": "[email protected]" }
1111
],
1212
"require": {
13-
"php": "^5.6 || ^7.0",
13+
"php": "^7.0",
1414
"ext-hash": "*",
1515
"ext-json": "*",
1616
"ext-mongodb": "^1.7"
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": "^5.7.27 || ^6.4 || ^8.3",
20-
"sebastian/comparator": "^1.0 || ^2.0 || ^3.0",
21-
"squizlabs/php_codesniffer": "^3.4",
19+
"phpunit/phpunit": "^6.4 || ^8.3",
20+
"sebastian/comparator": "^2.0 || ^3.0",
21+
"squizlabs/php_codesniffer": "^3.5",
2222
"symfony/phpunit-bridge": "^4.4@dev"
2323
},
2424
"autoload": {

phpcs.xml.dist

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,14 @@
1717

1818
<rule ref="Doctrine">
1919
<!-- Exclude sniffs that require newer PHP versions -->
20-
<!-- Available with PHP 7.0 -->
21-
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes" />
22-
<exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly" />
23-
<exclude name="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" />
24-
2520
<!-- Available with PHP 7.1 -->
2621
<exclude name="SlevomatCodingStandard.Classes.ClassConstantVisibility" />
2722
<exclude name="SlevomatCodingStandard.PHP.ShortList.LongListUsed" />
2823
<exclude name="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue" />
2924

25+
<!-- Can cause subtle BC breaks, disabled for now -->
26+
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes" />
27+
3028
<!-- No statement alignment so far -->
3129
<exclude name="Generic.Formatting.MultipleStatementAlignment" />
3230

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function __construct($uri = 'mongodb://127.0.0.1/', array $uriOptions = [
109109
}
110110

111111
$this->uri = (string) $uri;
112-
$this->typeMap = isset($driverOptions['typeMap']) ? $driverOptions['typeMap'] : null;
112+
$this->typeMap = $driverOptions['typeMap'] ?? null;
113113

114114
unset($driverOptions['typeMap']);
115115

src/Collection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ public function __construct(Manager $manager, $databaseName, $collectionName, ar
162162
$this->manager = $manager;
163163
$this->databaseName = (string) $databaseName;
164164
$this->collectionName = (string) $collectionName;
165-
$this->readConcern = isset($options['readConcern']) ? $options['readConcern'] : $this->manager->getReadConcern();
166-
$this->readPreference = isset($options['readPreference']) ? $options['readPreference'] : $this->manager->getReadPreference();
167-
$this->typeMap = isset($options['typeMap']) ? $options['typeMap'] : self::$defaultTypeMap;
168-
$this->writeConcern = isset($options['writeConcern']) ? $options['writeConcern'] : $this->manager->getWriteConcern();
165+
$this->readConcern = $options['readConcern'] ?? $this->manager->getReadConcern();
166+
$this->readPreference = $options['readPreference'] ?? $this->manager->getReadPreference();
167+
$this->typeMap = $options['typeMap'] ?? self::$defaultTypeMap;
168+
$this->writeConcern = $options['writeConcern'] ?? $this->manager->getWriteConcern();
169169
}
170170

171171
/**

src/Database.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ public function __construct(Manager $manager, $databaseName, array $options = []
129129

130130
$this->manager = $manager;
131131
$this->databaseName = (string) $databaseName;
132-
$this->readConcern = isset($options['readConcern']) ? $options['readConcern'] : $this->manager->getReadConcern();
133-
$this->readPreference = isset($options['readPreference']) ? $options['readPreference'] : $this->manager->getReadPreference();
134-
$this->typeMap = isset($options['typeMap']) ? $options['typeMap'] : self::$defaultTypeMap;
135-
$this->writeConcern = isset($options['writeConcern']) ? $options['writeConcern'] : $this->manager->getWriteConcern();
132+
$this->readConcern = $options['readConcern'] ?? $this->manager->getReadConcern();
133+
$this->readPreference = $options['readPreference'] ?? $this->manager->getReadPreference();
134+
$this->typeMap = $options['typeMap'] ?? self::$defaultTypeMap;
135+
$this->writeConcern = $options['writeConcern'] ?? $this->manager->getWriteConcern();
136136
}
137137

138138
/**

src/GridFS/Bucket.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ public function __construct(Manager $manager, $databaseName, array $options = []
180180
$this->bucketName = $options['bucketName'];
181181
$this->chunkSizeBytes = $options['chunkSizeBytes'];
182182
$this->disableMD5 = $options['disableMD5'];
183-
$this->readConcern = isset($options['readConcern']) ? $options['readConcern'] : $this->manager->getReadConcern();
184-
$this->readPreference = isset($options['readPreference']) ? $options['readPreference'] : $this->manager->getReadPreference();
185-
$this->typeMap = isset($options['typeMap']) ? $options['typeMap'] : self::$defaultTypeMap;
186-
$this->writeConcern = isset($options['writeConcern']) ? $options['writeConcern'] : $this->manager->getWriteConcern();
183+
$this->readConcern = $options['readConcern'] ?? $this->manager->getReadConcern();
184+
$this->readPreference = $options['readPreference'] ?? $this->manager->getReadPreference();
185+
$this->typeMap = $options['typeMap'] ?? self::$defaultTypeMap;
186+
$this->writeConcern = $options['writeConcern'] ?? $this->manager->getWriteConcern();
187187

188188
$collectionOptions = array_intersect_key($options, ['readConcern' => 1, 'readPreference' => 1, 'typeMap' => 1, 'writeConcern' => 1]);
189189

@@ -688,7 +688,7 @@ private function getRawFileDocumentForStream($stream)
688688
$metadata = stream_get_meta_data($stream);
689689

690690
if (! isset($metadata['wrapper_data']) || ! $metadata['wrapper_data'] instanceof StreamWrapper) {
691-
throw InvalidArgumentException::invalidType('$stream wrapper data', isset($metadata['wrapper_data']) ? $metadata['wrapper_data'] : null, StreamWrapper::class);
691+
throw InvalidArgumentException::invalidType('$stream wrapper data', $metadata['wrapper_data'] ?? null, StreamWrapper::class);
692692
}
693693

694694
return $metadata['wrapper_data']->getFile();

src/GridFS/StreamWrapper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
namespace MongoDB\GridFS;
1919

20-
use Exception;
2120
use MongoDB\BSON\UTCDateTime;
2221
use stdClass;
22+
use Throwable;
2323
use function explode;
2424
use function get_class;
2525
use function in_array;
@@ -150,7 +150,7 @@ public function stream_read($length)
150150

151151
try {
152152
return $this->stream->readBytes($length);
153-
} catch (Exception $e) {
153+
} catch (Throwable $e) {
154154
trigger_error(sprintf('%s: %s', get_class($e), $e->getMessage()), E_USER_WARNING);
155155

156156
return false;
@@ -247,7 +247,7 @@ public function stream_write($data)
247247

248248
try {
249249
return $this->stream->writeBytes($data);
250-
} catch (Exception $e) {
250+
} catch (Throwable $e) {
251251
trigger_error(sprintf('%s: %s', get_class($e), $e->getMessage()), E_USER_WARNING);
252252

253253
return false;

src/Model/ChangeStreamIterator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ private function extractResumeToken($document)
230230
}
231231

232232
$resumeToken = is_array($document)
233-
? (isset($document['_id']) ? $document['_id'] : null)
234-
: (isset($document->_id) ? $document->_id : null);
233+
? ($document['_id'] ?? null)
234+
: ($document->_id ?? null);
235235

236236
if (! isset($resumeToken)) {
237237
$this->isValid = false;

src/Operation/Aggregate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public function execute(Server $server)
325325
private function createCommand(Server $server, $hasWriteStage)
326326
{
327327
$cmd = [
328-
'aggregate' => isset($this->collectionName) ? $this->collectionName : 1,
328+
'aggregate' => $this->collectionName ?? 1,
329329
'pipeline' => $this->pipeline,
330330
];
331331
$cmdOptions = [];

src/Operation/FindAndModify.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public function execute(Server $server)
243243

244244
$result = current($cursor->toArray());
245245

246-
return isset($result->value) ? $result->value : null;
246+
return $result->value ?? null;
247247
}
248248

249249
public function getCommandDocument(Server $server)

src/Operation/WithTransaction.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Exception;
66
use MongoDB\Driver\Exception\RuntimeException;
77
use MongoDB\Driver\Session;
8+
use Throwable;
89
use function call_user_func;
910
use function time;
1011

@@ -63,7 +64,7 @@ public function execute(Session $session)
6364

6465
try {
6566
call_user_func($this->callback, $session);
66-
} catch (Exception $e) {
67+
} catch (Throwable $e) {
6768
if ($session->isInTransaction()) {
6869
$session->abortTransaction();
6970
}

tests/Collection/CrudSpecFunctionalTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testSpecification(array $initialData, array $test, $minServerVer
5757
$this->checkServerVersion($minServerVersion, $maxServerVersion);
5858
}
5959

60-
$expectedData = isset($test['outcome']['collection']['data']) ? $test['outcome']['collection']['data'] : null;
60+
$expectedData = $test['outcome']['collection']['data'] ?? null;
6161
$this->initializeData($initialData, $expectedData);
6262

6363
if (isset($test['outcome']['collection']['name'])) {
@@ -84,8 +84,8 @@ public function provideSpecificationTests()
8484
foreach (glob(__DIR__ . '/spec-tests/*/*.json') as $filename) {
8585
$json = json_decode(file_get_contents($filename), true);
8686

87-
$minServerVersion = isset($json['minServerVersion']) ? $json['minServerVersion'] : null;
88-
$maxServerVersion = isset($json['maxServerVersion']) ? $json['maxServerVersion'] : null;
87+
$minServerVersion = $json['minServerVersion'] ?? null;
88+
$maxServerVersion = $json['maxServerVersion'] ?? null;
8989

9090
foreach ($json['tests'] as $test) {
9191
$name = str_replace(' ', '_', $test['description']);
@@ -152,13 +152,13 @@ private function executeOperation(array $operation)
152152
case 'bulkWrite':
153153
return $this->collection->bulkWrite(
154154
array_map([$this, 'prepareBulkWriteRequest'], $operation['arguments']['requests']),
155-
isset($operation['arguments']['options']) ? $operation['arguments']['options'] : []
155+
$operation['arguments']['options'] ?? []
156156
);
157157
case 'count':
158158
case 'countDocuments':
159159
case 'find':
160160
return $this->collection->{$operation['name']}(
161-
isset($operation['arguments']['filter']) ? $operation['arguments']['filter'] : [],
161+
$operation['arguments']['filter'] ?? [],
162162
array_diff_key($operation['arguments'], ['filter' => 1])
163163
);
164164
case 'estimatedDocumentCount':
@@ -173,7 +173,7 @@ private function executeOperation(array $operation)
173173
case 'distinct':
174174
return $this->collection->distinct(
175175
$operation['arguments']['fieldName'],
176-
isset($operation['arguments']['filter']) ? $operation['arguments']['filter'] : [],
176+
$operation['arguments']['filter'] ?? [],
177177
array_diff_key($operation['arguments'], ['fieldName' => 1, 'filter' => 1])
178178
);
179179
case 'findOneAndReplace':
@@ -200,7 +200,7 @@ private function executeOperation(array $operation)
200200
case 'insertMany':
201201
return $this->collection->insertMany(
202202
$operation['arguments']['documents'],
203-
isset($operation['arguments']['options']) ? $operation['arguments']['options'] : []
203+
$operation['arguments']['options'] ?? []
204204
);
205205
case 'insertOne':
206206
return $this->collection->insertOne(
@@ -263,15 +263,15 @@ private function extractResultFromException(array $operation, array $outcome, Ru
263263
{
264264
switch ($operation['name']) {
265265
case 'bulkWrite':
266-
$insertedIds = isset($outcome['result']['insertedIds']) ? $outcome['result']['insertedIds'] : [];
266+
$insertedIds = $outcome['result']['insertedIds'] ?? [];
267267

268268
if ($exception instanceof BulkWriteException) {
269269
return new BulkWriteResult($exception->getWriteResult(), $insertedIds);
270270
}
271271
break;
272272

273273
case 'insertMany':
274-
$insertedIds = isset($outcome['result']['insertedIds']) ? $outcome['result']['insertedIds'] : [];
274+
$insertedIds = $outcome['result']['insertedIds'] ?? [];
275275

276276
if ($exception instanceof BulkWriteException) {
277277
return new InsertManyResult($exception->getWriteResult(), $insertedIds);

tests/CommandObserver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace MongoDB\Tests;
44

5-
use Exception;
65
use MongoDB\Driver\Monitoring\CommandFailedEvent;
76
use MongoDB\Driver\Monitoring\CommandStartedEvent;
87
use MongoDB\Driver\Monitoring\CommandSubscriber;
98
use MongoDB\Driver\Monitoring\CommandSucceededEvent;
9+
use Throwable;
1010
use function call_user_func;
1111
use function MongoDB\Driver\Monitoring\addSubscriber;
1212
use function MongoDB\Driver\Monitoring\removeSubscriber;
@@ -27,7 +27,7 @@ public function observe(callable $execution, callable $commandCallback)
2727

2828
try {
2929
call_user_func($execution);
30-
} catch (Exception $executionException) {
30+
} catch (Throwable $executionException) {
3131
}
3232

3333
removeSubscriber($this);

tests/GridFS/ReadableStreamFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function testReadBytesCalledMultipleTimes($fileId, $length, $expectedByte
136136
$fileDocument = $this->collectionWrapper->findFileById($fileId);
137137
$stream = new ReadableStream($this->collectionWrapper, $fileDocument);
138138
for ($i = 0; $i < $length; $i++) {
139-
$expectedByte = isset($expectedBytes[$i]) ? $expectedBytes[$i] : '';
139+
$expectedByte = $expectedBytes[$i] ?? '';
140140
$this->assertSame($expectedByte, $stream->readBytes(1));
141141
}
142142
}

tests/GridFS/SpecFunctionalTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace MongoDB\Tests\GridFS;
44

55
use DateTime;
6-
use Exception;
76
use IteratorIterator;
87
use LogicException;
98
use MongoDB\BSON\Binary;
@@ -15,6 +14,7 @@
1514
use MultipleIterator;
1615
use PHPUnit\Framework\Error\Warning;
1716
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
17+
use Throwable;
1818
use function array_walk;
1919
use function array_walk_recursive;
2020
use function file_get_contents;
@@ -70,7 +70,7 @@ public function testSpecification(array $initialData, array $test)
7070

7171
try {
7272
$result = $this->executeAct($test['act']);
73-
} catch (Exception $e) {
73+
} catch (Throwable $e) {
7474
$result = $e;
7575
}
7676

@@ -211,13 +211,13 @@ private function executeAct(array $act)
211211
case 'download_by_name':
212212
return stream_get_contents($this->bucket->openDownloadStreamByName(
213213
$act['arguments']['filename'],
214-
isset($act['arguments']['options']) ? $act['arguments']['options'] : []
214+
$act['arguments']['options'] ?? []
215215
));
216216
case 'upload':
217217
return $this->bucket->uploadFromStream(
218218
$act['arguments']['filename'],
219219
$this->createStream($act['arguments']['source']),
220-
isset($act['arguments']['options']) ? $act['arguments']['options'] : []
220+
$act['arguments']['options'] ?? []
221221
);
222222
default:
223223
throw new LogicException('Unsupported act: ' . $act['operation']);

tests/Model/CachingIteratorTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Exception;
66
use MongoDB\Model\CachingIterator;
77
use MongoDB\Tests\TestCase;
8+
use Throwable;
89
use function iterator_to_array;
910

1011
class CachingIteratorTest extends TestCase
@@ -14,7 +15,7 @@ public function testTraversingGeneratorConsumesIt()
1415
$iterator = $this->getTraversable([1, 2, 3]);
1516
$this->assertSame([1, 2, 3], iterator_to_array($iterator));
1617

17-
$this->expectException(Exception::class);
18+
$this->expectException(Throwable::class);
1819
$this->expectExceptionMessage('Cannot traverse an already closed generator');
1920
iterator_to_array($iterator);
2021
}

tests/SpecTests/ChangeStreamsSpecTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ public function provideTests()
149149
foreach (glob(__DIR__ . '/change-streams/*.json') as $filename) {
150150
$json = $this->decodeJson(file_get_contents($filename));
151151
$group = basename($filename, '.json');
152-
$databaseName = isset($json->database_name) ? $json->database_name : null;
153-
$database2Name = isset($json->database2_name) ? $json->database2_name : null;
154-
$collectionName = isset($json->collection_name) ? $json->collection_name : null;
155-
$collection2Name = isset($json->collection2_name) ? $json->collection2_name : null;
152+
$databaseName = $json->database_name ?? null;
153+
$database2Name = $json->database2_name ?? null;
154+
$collectionName = $json->collection_name ?? null;
155+
$collection2Name = $json->collection2_name ?? null;
156156

157157
foreach ($json->tests as $test) {
158158
$name = $group . ': ' . $test->description;
@@ -173,7 +173,7 @@ public function provideTests()
173173
private function createChangeStream(stdClass $test)
174174
{
175175
$context = $this->getContext();
176-
$pipeline = isset($test->changeStreamPipeline) ? $test->changeStreamPipeline : [];
176+
$pipeline = $test->changeStreamPipeline ?? [];
177177
$options = isset($test->changeStreamOptions) ? (array) $test->changeStreamOptions : [];
178178

179179
switch ($test->target) {

0 commit comments

Comments
 (0)