Skip to content

PHPLIB-1118: Drop support for PHP 7.2 and 7.3 #1128

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 11 commits into from
Jul 14, 2023
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
14 changes: 3 additions & 11 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -690,14 +690,6 @@ axes:
display_name: "PHP 7.4"
variables:
PHP_VERSION: "7.4"
- id: "7.3"
display_name: "PHP 7.3"
variables:
PHP_VERSION: "7.3"
- id: "7.2"
display_name: "PHP 7.2"
variables:
PHP_VERSION: "7.2"

- id: php-edge-versions
display_name: PHP Version
Expand All @@ -707,9 +699,9 @@ axes:
variables:
PHP_VERSION: "8.2"
- id: "oldest-supported"
display_name: "PHP 7.2"
display_name: "PHP 7.4"
variables:
PHP_VERSION: "7.2"
PHP_VERSION: "7.4"

- id: mongodb-versions
display_name: MongoDB Version
Expand Down Expand Up @@ -898,7 +890,7 @@ buildvariants:
# Exclude "latest-stable" PHP version for Debian 11 (see: test-mongodb-versions matrix)
- { "os": "debian11", "mongodb-edge-versions": "latest-stable", "php-versions": "8.2", "driver-versions": "latest-stable" }
# Exclude PHP versions older than 8.1 on RHEL 9 and Ubuntu 22.04 (OpenSSL 3 is only supported on PHP 8.1+)
- { "os": ["rhel90", "ubuntu2204-arm64", "ubuntu2204"], "php-versions": ["7.2", "7.3", "7.4", "8.0"], "mongodb-edge-versions": "*", "driver-versions": "*" }
- { "os": ["rhel90", "ubuntu2204-arm64", "ubuntu2204"], "php-versions": ["7.4", "8.0"], "mongodb-edge-versions": "*", "driver-versions": "*" }
tasks:
- name: "test-standalone"
- name: "test-replica_set"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{ "name": "Jérôme Tamarelle", "email": "jerome.tamarelle@mongodb.com" }
],
"require": {
"php": "^7.2 || ^8.0",
"php": "^7.4 || ^8.0",
"ext-hash": "*",
"ext-json": "*",
"ext-mongodb": "^1.16.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function toJSON(object $document): string
['x' => 10], // Document
],
],
]
],
Copy link
Member Author

@alcaeus alcaeus Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is responsible for most of the non-functional diff in this PR: a trailing comma after the last argument in multi-line method calls is now required. This is consistent with the rules already in place for multi-line arrays.

);

$cursor = $collection->find([]);
Expand Down
2 changes: 1 addition & 1 deletion examples/command_logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function commandFailed(CommandFailedEvent $event): void

$collection->updateMany(
['x' => ['$gt' => 1]],
['$set' => ['y' => 1]]
['$set' => ['y' => 1]],
);

$cursor = $collection->find([], ['batchSize' => 2]);
Expand Down
14 changes: 5 additions & 9 deletions examples/persistable.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@

class PersistableEntry implements Persistable
{
/** @var ObjectId */
private $id;
private ObjectId $id;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went through the various type changes and confirmed they were accurate, but a second look certainly won't hurt.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to me. Some missing property types from ext-mongodb, maybe due to outdated stubs.

When types are added to properties, the biggest risk is to have an error when trying to access an uninitialized property.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: the missing property types weren't caught by Rector for some reason, and I only later realised that we had an exclusion in the phpcs config to prevent native types from being added. This has since been removed and types for properties are now enforced.


/** @var string */
public $name;
public string $name;

/** @var array<PersistableEmail> */
public $emails = [];
public array $emails = [];

public function __construct(string $name)
{
Expand Down Expand Up @@ -65,11 +63,9 @@ public function bsonUnserialize(array $data): void

class PersistableEmail implements Persistable
{
/** @var string */
public $type;
public string $type;

/** @var string */
public $address;
public string $address;

public function __construct(string $type, string $address)
{
Expand Down
14 changes: 5 additions & 9 deletions examples/typemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@

class TypeMapEntry implements Unserializable
{
/** @var ObjectId */
private $id;
private ObjectId $id;

/** @var string */
private $name;
private string $name;

/** @var array<TypeMapEmail> */
private $emails;
private array $emails;

private function __construct()
{
Expand Down Expand Up @@ -64,11 +62,9 @@ public function bsonUnserialize(array $data): void

class TypeMapEmail implements Unserializable
{
/** @var string */
private $type;
private string $type;

/** @var string */
private $address;
private string $address;

private function __construct()
{
Expand Down
4 changes: 2 additions & 2 deletions examples/with_transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ function toJSON(object $document): string
['x' => 2],
['x' => 3],
],
['session' => $session]
['session' => $session],
);

$collection->updateMany(
['x' => ['$gt' => 1]],
['$set' => ['y' => 1]],
['session' => $session]
['session' => $session],
);
};

Expand Down
7 changes: 1 addition & 6 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<file>rector.php</file>

<!-- Target minimum supported PHP version -->
<config name="php_version" value="70200"/>
<config name="php_version" value="70400"/>

<!-- ****************************************** -->
<!-- Import rules from doctrine/coding-standard -->
Expand Down Expand Up @@ -112,8 +112,6 @@

<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<properties>
<!-- Requires PHP 7.4 -->
<property name="enableNativeTypeHint" value="false" />
<!-- Requires PHP 8.0 -->
<property name="enableMixedTypeHint" value="false" />
<!-- Requires PHP 8.0 -->
Expand Down Expand Up @@ -154,9 +152,6 @@
<!-- *********************************************************** -->
<!-- Require native type hints for all code without a BC promise -->
<!-- *********************************************************** -->
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint">
<exclude-pattern>src</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint">
<exclude-pattern>src</exclude-pattern>
</rule>
Expand Down
12 changes: 11 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
use Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector;
use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector;
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
Expand All @@ -15,7 +17,7 @@
]);

// Modernize code
$rectorConfig->sets([LevelSetList::UP_TO_PHP_72]);
$rectorConfig->sets([LevelSetList::UP_TO_PHP_74]);

$rectorConfig->skip([
// Falsely detect unassigned variables in code paths stopped by PHPUnit\Framework\Assert::markTestSkipped()
Expand All @@ -26,6 +28,14 @@
RemoveExtraParametersRector::class => [
__DIR__ . '/src/Operation/',
],
// Assigns wrong type due to outdated PHPStan stubs
TypedPropertyFromAssignsRector::class => [
__DIR__ . '/src/Model/BSONIterator.php',
],
// Not necessary in documentation examples
JsonThrowOnErrorRector::class => [
__DIR__ . '/tests/DocumentationExamplesTest.php',
],
]);

// All classes are public API by default, unless marked with @internal.
Expand Down
9 changes: 3 additions & 6 deletions src/BulkWriteResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@
*/
class BulkWriteResult
{
/** @var WriteResult */
private $writeResult;
private WriteResult $writeResult;

/** @var array */
private $insertedIds;
private array $insertedIds;

/** @var boolean */
private $isAcknowledged;
private bool $isAcknowledged;

public function __construct(WriteResult $writeResult, array $insertedIds)
{
Expand Down
10 changes: 3 additions & 7 deletions src/ChangeStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,15 @@ class ChangeStream implements Iterator
/** @var ResumeCallable|null */
private $resumeCallable;

/** @var ChangeStreamIterator */
private $iterator;
private ChangeStreamIterator $iterator;

/** @var integer */
private $key = 0;
private int $key = 0;

/**
* Whether the change stream has advanced to its first result. This is used
* to determine whether $key should be incremented after an iteration event.
*
* @var boolean
*/
private $hasAdvanced = false;
private bool $hasAdvanced = false;

/**
* @internal
Expand Down
21 changes: 7 additions & 14 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,19 @@ class Client

private const HANDSHAKE_SEPARATOR = '/';

/** @var string|null */
private static $version;
private static ?string $version = null;

/** @var Manager */
private $manager;
private Manager $manager;

/** @var ReadConcern */
private $readConcern;
private ReadConcern $readConcern;

/** @var ReadPreference */
private $readPreference;
private ReadPreference $readPreference;

/** @var string */
private $uri;
private string $uri;

/** @var array */
private $typeMap;
private array $typeMap;

/** @var WriteConcern */
private $writeConcern;
private WriteConcern $writeConcern;

/**
* Constructs a new Client instance.
Expand Down
8 changes: 4 additions & 4 deletions src/Codec/CodecLibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class CodecLibrary implements Codec
use DecodeIfSupported;
use EncodeIfSupported;

/** @var array<Decoder> */
private $decoders = [];
/** @var list<Decoder> */
private array $decoders = [];

/** @var array<Encoder> */
private $encoders = [];
/** @var list<Encoder> */
private array $encoders = [];

/** @param Decoder|Encoder $items */
public function __construct(...$items)
Expand Down
21 changes: 7 additions & 14 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,19 @@ class Collection

private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8;

/** @var string */
private $collectionName;
private string $collectionName;

/** @var string */
private $databaseName;
private string $databaseName;

/** @var Manager */
private $manager;
private Manager $manager;

/** @var ReadConcern */
private $readConcern;
private ReadConcern $readConcern;

/** @var ReadPreference */
private $readPreference;
private ReadPreference $readPreference;

/** @var array */
private $typeMap;
private array $typeMap;

/** @var WriteConcern */
private $writeConcern;
private WriteConcern $writeConcern;

/**
* Constructs new Collection instance.
Expand Down
6 changes: 2 additions & 4 deletions src/Command/ListCollections.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@
*/
class ListCollections implements Executable
{
/** @var string */
private $databaseName;
private string $databaseName;

/** @var array */
private $options;
private array $options;

/**
* Constructs a listCollections command.
Expand Down
3 changes: 1 addition & 2 deletions src/Command/ListDatabases.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
*/
class ListDatabases implements Executable
{
/** @var array */
private $options;
private array $options;

/**
* Constructs a listDatabases command.
Expand Down
18 changes: 6 additions & 12 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,17 @@ class Database

private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8;

/** @var string */
private $databaseName;
private string $databaseName;

/** @var Manager */
private $manager;
private Manager $manager;

/** @var ReadConcern */
private $readConcern;
private ReadConcern $readConcern;

/** @var ReadPreference */
private $readPreference;
private ReadPreference $readPreference;

/** @var array */
private $typeMap;
private array $typeMap;

/** @var WriteConcern */
private $writeConcern;
private WriteConcern $writeConcern;

/**
* Constructs new Database instance.
Expand Down
6 changes: 2 additions & 4 deletions src/DeleteResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
*/
class DeleteResult
{
/** @var WriteResult */
private $writeResult;
private WriteResult $writeResult;

/** @var boolean */
private $isAcknowledged;
private bool $isAcknowledged;

public function __construct(WriteResult $writeResult)
{
Expand Down
Loading