Skip to content

PHPLIB-529: Drop support for PHP 5.6 #720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ jobs:
- CHECKS=phpcs

# Test remaining supported PHP versions
- stage: Test
php: "5.6"
- stage: Test
php: "7.0"
- stage: Test
Expand All @@ -62,7 +60,7 @@ jobs:

# Test against lowest supported dependencies
- stage: Test
php: "5.6"
php: "7.0"
env:
- COMPOSER_OPTIONS=--prefer-lowest

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
{ "name": "Katherine Walker", "email": "[email protected]" }
],
"require": {
"php": "^5.6 || ^7.0",
"php": "^7.0",
"ext-hash": "*",
"ext-json": "*",
"ext-mongodb": "^1.7"
},
"require-dev": {
"phpunit/phpunit": "^5.7.27 || ^6.4 || ^8.3",
"sebastian/comparator": "^1.0 || ^2.0 || ^3.0",
"squizlabs/php_codesniffer": "^3.4",
"phpunit/phpunit": "^6.4 || ^8.3",
"sebastian/comparator": "^2.0 || ^3.0",
"squizlabs/php_codesniffer": "^3.5",
"symfony/phpunit-bridge": "^4.4@dev"
},
"autoload": {
Expand Down
8 changes: 3 additions & 5 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@

<rule ref="Doctrine">
<!-- Exclude sniffs that require newer PHP versions -->
<!-- Available with PHP 7.0 -->
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes" />
<exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly" />
<exclude name="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" />

<!-- Available with PHP 7.1 -->
<exclude name="SlevomatCodingStandard.Classes.ClassConstantVisibility" />
<exclude name="SlevomatCodingStandard.PHP.ShortList.LongListUsed" />
<exclude name="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue" />

<!-- Can cause subtle BC breaks, disabled for now -->
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes" />

<!-- No statement alignment so far -->
<exclude name="Generic.Formatting.MultipleStatementAlignment" />

Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function __construct($uri = 'mongodb://127.0.0.1/', array $uriOptions = [
}

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

unset($driverOptions['typeMap']);

Expand Down
8 changes: 4 additions & 4 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ public function __construct(Manager $manager, $databaseName, $collectionName, ar
$this->manager = $manager;
$this->databaseName = (string) $databaseName;
$this->collectionName = (string) $collectionName;
$this->readConcern = isset($options['readConcern']) ? $options['readConcern'] : $this->manager->getReadConcern();
$this->readPreference = isset($options['readPreference']) ? $options['readPreference'] : $this->manager->getReadPreference();
$this->typeMap = isset($options['typeMap']) ? $options['typeMap'] : self::$defaultTypeMap;
$this->writeConcern = isset($options['writeConcern']) ? $options['writeConcern'] : $this->manager->getWriteConcern();
$this->readConcern = $options['readConcern'] ?? $this->manager->getReadConcern();
$this->readPreference = $options['readPreference'] ?? $this->manager->getReadPreference();
$this->typeMap = $options['typeMap'] ?? self::$defaultTypeMap;
$this->writeConcern = $options['writeConcern'] ?? $this->manager->getWriteConcern();
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ public function __construct(Manager $manager, $databaseName, array $options = []

$this->manager = $manager;
$this->databaseName = (string) $databaseName;
$this->readConcern = isset($options['readConcern']) ? $options['readConcern'] : $this->manager->getReadConcern();
$this->readPreference = isset($options['readPreference']) ? $options['readPreference'] : $this->manager->getReadPreference();
$this->typeMap = isset($options['typeMap']) ? $options['typeMap'] : self::$defaultTypeMap;
$this->writeConcern = isset($options['writeConcern']) ? $options['writeConcern'] : $this->manager->getWriteConcern();
$this->readConcern = $options['readConcern'] ?? $this->manager->getReadConcern();
$this->readPreference = $options['readPreference'] ?? $this->manager->getReadPreference();
$this->typeMap = $options['typeMap'] ?? self::$defaultTypeMap;
$this->writeConcern = $options['writeConcern'] ?? $this->manager->getWriteConcern();
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/GridFS/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ public function __construct(Manager $manager, $databaseName, array $options = []
$this->bucketName = $options['bucketName'];
$this->chunkSizeBytes = $options['chunkSizeBytes'];
$this->disableMD5 = $options['disableMD5'];
$this->readConcern = isset($options['readConcern']) ? $options['readConcern'] : $this->manager->getReadConcern();
$this->readPreference = isset($options['readPreference']) ? $options['readPreference'] : $this->manager->getReadPreference();
$this->typeMap = isset($options['typeMap']) ? $options['typeMap'] : self::$defaultTypeMap;
$this->writeConcern = isset($options['writeConcern']) ? $options['writeConcern'] : $this->manager->getWriteConcern();
$this->readConcern = $options['readConcern'] ?? $this->manager->getReadConcern();
$this->readPreference = $options['readPreference'] ?? $this->manager->getReadPreference();
$this->typeMap = $options['typeMap'] ?? self::$defaultTypeMap;
$this->writeConcern = $options['writeConcern'] ?? $this->manager->getWriteConcern();

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

Expand Down Expand Up @@ -688,7 +688,7 @@ private function getRawFileDocumentForStream($stream)
$metadata = stream_get_meta_data($stream);

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

return $metadata['wrapper_data']->getFile();
Expand Down
6 changes: 3 additions & 3 deletions src/GridFS/StreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

namespace MongoDB\GridFS;

use Exception;
use MongoDB\BSON\UTCDateTime;
use stdClass;
use Throwable;
use function explode;
use function get_class;
use function in_array;
Expand Down Expand Up @@ -150,7 +150,7 @@ public function stream_read($length)

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

return false;
Expand Down Expand Up @@ -247,7 +247,7 @@ public function stream_write($data)

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

return false;
Expand Down
4 changes: 2 additions & 2 deletions src/Model/ChangeStreamIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ private function extractResumeToken($document)
}

$resumeToken = is_array($document)
? (isset($document['_id']) ? $document['_id'] : null)
: (isset($document->_id) ? $document->_id : null);
? ($document['_id'] ?? null)
: ($document->_id ?? null);

if (! isset($resumeToken)) {
$this->isValid = false;
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Aggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public function execute(Server $server)
private function createCommand(Server $server, $hasWriteStage)
{
$cmd = [
'aggregate' => isset($this->collectionName) ? $this->collectionName : 1,
'aggregate' => $this->collectionName ?? 1,
'pipeline' => $this->pipeline,
];
$cmdOptions = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/FindAndModify.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function execute(Server $server)

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

return isset($result->value) ? $result->value : null;
return $result->value ?? null;
}

public function getCommandDocument(Server $server)
Expand Down
3 changes: 2 additions & 1 deletion src/Operation/WithTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Exception;
use MongoDB\Driver\Exception\RuntimeException;
use MongoDB\Driver\Session;
use Throwable;
use function call_user_func;
use function time;

Expand Down Expand Up @@ -63,7 +64,7 @@ public function execute(Session $session)

try {
call_user_func($this->callback, $session);
} catch (Exception $e) {
} catch (Throwable $e) {
if ($session->isInTransaction()) {
$session->abortTransaction();
}
Expand Down
18 changes: 9 additions & 9 deletions tests/Collection/CrudSpecFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function testSpecification(array $initialData, array $test, $minServerVer
$this->checkServerVersion($minServerVersion, $maxServerVersion);
}

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

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

$minServerVersion = isset($json['minServerVersion']) ? $json['minServerVersion'] : null;
$maxServerVersion = isset($json['maxServerVersion']) ? $json['maxServerVersion'] : null;
$minServerVersion = $json['minServerVersion'] ?? null;
$maxServerVersion = $json['maxServerVersion'] ?? null;

foreach ($json['tests'] as $test) {
$name = str_replace(' ', '_', $test['description']);
Expand Down Expand Up @@ -152,13 +152,13 @@ private function executeOperation(array $operation)
case 'bulkWrite':
return $this->collection->bulkWrite(
array_map([$this, 'prepareBulkWriteRequest'], $operation['arguments']['requests']),
isset($operation['arguments']['options']) ? $operation['arguments']['options'] : []
$operation['arguments']['options'] ?? []
);
case 'count':
case 'countDocuments':
case 'find':
return $this->collection->{$operation['name']}(
isset($operation['arguments']['filter']) ? $operation['arguments']['filter'] : [],
$operation['arguments']['filter'] ?? [],
array_diff_key($operation['arguments'], ['filter' => 1])
);
case 'estimatedDocumentCount':
Expand All @@ -173,7 +173,7 @@ private function executeOperation(array $operation)
case 'distinct':
return $this->collection->distinct(
$operation['arguments']['fieldName'],
isset($operation['arguments']['filter']) ? $operation['arguments']['filter'] : [],
$operation['arguments']['filter'] ?? [],
array_diff_key($operation['arguments'], ['fieldName' => 1, 'filter' => 1])
);
case 'findOneAndReplace':
Expand All @@ -200,7 +200,7 @@ private function executeOperation(array $operation)
case 'insertMany':
return $this->collection->insertMany(
$operation['arguments']['documents'],
isset($operation['arguments']['options']) ? $operation['arguments']['options'] : []
$operation['arguments']['options'] ?? []
);
case 'insertOne':
return $this->collection->insertOne(
Expand Down Expand Up @@ -263,15 +263,15 @@ private function extractResultFromException(array $operation, array $outcome, Ru
{
switch ($operation['name']) {
case 'bulkWrite':
$insertedIds = isset($outcome['result']['insertedIds']) ? $outcome['result']['insertedIds'] : [];
$insertedIds = $outcome['result']['insertedIds'] ?? [];

if ($exception instanceof BulkWriteException) {
return new BulkWriteResult($exception->getWriteResult(), $insertedIds);
}
break;

case 'insertMany':
$insertedIds = isset($outcome['result']['insertedIds']) ? $outcome['result']['insertedIds'] : [];
$insertedIds = $outcome['result']['insertedIds'] ?? [];

if ($exception instanceof BulkWriteException) {
return new InsertManyResult($exception->getWriteResult(), $insertedIds);
Expand Down
4 changes: 2 additions & 2 deletions tests/CommandObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace MongoDB\Tests;

use Exception;
use MongoDB\Driver\Monitoring\CommandFailedEvent;
use MongoDB\Driver\Monitoring\CommandStartedEvent;
use MongoDB\Driver\Monitoring\CommandSubscriber;
use MongoDB\Driver\Monitoring\CommandSucceededEvent;
use Throwable;
use function call_user_func;
use function MongoDB\Driver\Monitoring\addSubscriber;
use function MongoDB\Driver\Monitoring\removeSubscriber;
Expand All @@ -27,7 +27,7 @@ public function observe(callable $execution, callable $commandCallback)

try {
call_user_func($execution);
} catch (Exception $executionException) {
} catch (Throwable $executionException) {
}

removeSubscriber($this);
Expand Down
2 changes: 1 addition & 1 deletion tests/GridFS/ReadableStreamFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function testReadBytesCalledMultipleTimes($fileId, $length, $expectedByte
$fileDocument = $this->collectionWrapper->findFileById($fileId);
$stream = new ReadableStream($this->collectionWrapper, $fileDocument);
for ($i = 0; $i < $length; $i++) {
$expectedByte = isset($expectedBytes[$i]) ? $expectedBytes[$i] : '';
$expectedByte = $expectedBytes[$i] ?? '';
$this->assertSame($expectedByte, $stream->readBytes(1));
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/GridFS/SpecFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace MongoDB\Tests\GridFS;

use DateTime;
use Exception;
use IteratorIterator;
use LogicException;
use MongoDB\BSON\Binary;
Expand All @@ -15,6 +14,7 @@
use MultipleIterator;
use PHPUnit\Framework\Error\Warning;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
use Throwable;
use function array_walk;
use function array_walk_recursive;
use function file_get_contents;
Expand Down Expand Up @@ -70,7 +70,7 @@ public function testSpecification(array $initialData, array $test)

try {
$result = $this->executeAct($test['act']);
} catch (Exception $e) {
} catch (Throwable $e) {
$result = $e;
}

Expand Down Expand Up @@ -211,13 +211,13 @@ private function executeAct(array $act)
case 'download_by_name':
return stream_get_contents($this->bucket->openDownloadStreamByName(
$act['arguments']['filename'],
isset($act['arguments']['options']) ? $act['arguments']['options'] : []
$act['arguments']['options'] ?? []
));
case 'upload':
return $this->bucket->uploadFromStream(
$act['arguments']['filename'],
$this->createStream($act['arguments']['source']),
isset($act['arguments']['options']) ? $act['arguments']['options'] : []
$act['arguments']['options'] ?? []
);
default:
throw new LogicException('Unsupported act: ' . $act['operation']);
Expand Down
3 changes: 2 additions & 1 deletion tests/Model/CachingIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Exception;
use MongoDB\Model\CachingIterator;
use MongoDB\Tests\TestCase;
use Throwable;
use function iterator_to_array;

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

$this->expectException(Exception::class);
$this->expectException(Throwable::class);
$this->expectExceptionMessage('Cannot traverse an already closed generator');
iterator_to_array($iterator);
}
Expand Down
10 changes: 5 additions & 5 deletions tests/SpecTests/ChangeStreamsSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ public function provideTests()
foreach (glob(__DIR__ . '/change-streams/*.json') as $filename) {
$json = $this->decodeJson(file_get_contents($filename));
$group = basename($filename, '.json');
$databaseName = isset($json->database_name) ? $json->database_name : null;
$database2Name = isset($json->database2_name) ? $json->database2_name : null;
$collectionName = isset($json->collection_name) ? $json->collection_name : null;
$collection2Name = isset($json->collection2_name) ? $json->collection2_name : null;
$databaseName = $json->database_name ?? null;
$database2Name = $json->database2_name ?? null;
$collectionName = $json->collection_name ?? null;
$collection2Name = $json->collection2_name ?? null;

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

switch ($test->target) {
Expand Down
Loading