Skip to content

Commit f81b4a6

Browse files
authored
PHPLIB-1118: Drop support for PHP 7.2 and 7.3 (#1128)
* PHPLIB-1118: Drop support for PHP 7.2 and 7.3 * Modernise code for PHP 7.4 This uses rector and phpcbf to automatically fix issues * Skip rector rule creating adding wrong property type * Add more missing property types * Use strval instead of closure * Use FQN for constant in documentation examples * Add undectected missing trailing commas * Split line for readability * Fix wrong property type * Remove requirement for JSON_THROW_ON_ERROR in docs examples * Address code review issues
1 parent 2f431c0 commit f81b4a6

File tree

179 files changed

+1029
-1461
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+1029
-1461
lines changed

.evergreen/config.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -690,14 +690,6 @@ axes:
690690
display_name: "PHP 7.4"
691691
variables:
692692
PHP_VERSION: "7.4"
693-
- id: "7.3"
694-
display_name: "PHP 7.3"
695-
variables:
696-
PHP_VERSION: "7.3"
697-
- id: "7.2"
698-
display_name: "PHP 7.2"
699-
variables:
700-
PHP_VERSION: "7.2"
701693

702694
- id: php-edge-versions
703695
display_name: PHP Version
@@ -707,9 +699,9 @@ axes:
707699
variables:
708700
PHP_VERSION: "8.2"
709701
- id: "oldest-supported"
710-
display_name: "PHP 7.2"
702+
display_name: "PHP 7.4"
711703
variables:
712-
PHP_VERSION: "7.2"
704+
PHP_VERSION: "7.4"
713705

714706
- id: mongodb-versions
715707
display_name: MongoDB Version
@@ -898,7 +890,7 @@ buildvariants:
898890
# Exclude "latest-stable" PHP version for Debian 11 (see: test-mongodb-versions matrix)
899891
- { "os": "debian11", "mongodb-edge-versions": "latest-stable", "php-versions": "8.2", "driver-versions": "latest-stable" }
900892
# Exclude PHP versions older than 8.1 on RHEL 9 and Ubuntu 22.04 (OpenSSL 3 is only supported on PHP 8.1+)
901-
- { "os": ["rhel90", "ubuntu2204-arm64", "ubuntu2204"], "php-versions": ["7.2", "7.3", "7.4", "8.0"], "mongodb-edge-versions": "*", "driver-versions": "*" }
893+
- { "os": ["rhel90", "ubuntu2204-arm64", "ubuntu2204"], "php-versions": ["7.4", "8.0"], "mongodb-edge-versions": "*", "driver-versions": "*" }
902894
tasks:
903895
- name: "test-standalone"
904896
- name: "test-replica_set"

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{ "name": "Jérôme Tamarelle", "email": "[email protected]" }
1111
],
1212
"require": {
13-
"php": "^7.2 || ^8.0",
13+
"php": "^7.4 || ^8.0",
1414
"ext-hash": "*",
1515
"ext-json": "*",
1616
"ext-mongodb": "^1.16.0",

examples/bulk.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function toJSON(object $document): string
6868
['x' => 10], // Document
6969
],
7070
],
71-
]
71+
],
7272
);
7373

7474
$cursor = $collection->find([]);

examples/command_logger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function commandFailed(CommandFailedEvent $event): void
6969

7070
$collection->updateMany(
7171
['x' => ['$gt' => 1]],
72-
['$set' => ['y' => 1]]
72+
['$set' => ['y' => 1]],
7373
);
7474

7575
$cursor = $collection->find([], ['batchSize' => 2]);

examples/persistable.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616

1717
class PersistableEntry implements Persistable
1818
{
19-
/** @var ObjectId */
20-
private $id;
19+
private ObjectId $id;
2120

22-
/** @var string */
23-
public $name;
21+
public string $name;
2422

2523
/** @var array<PersistableEmail> */
26-
public $emails = [];
24+
public array $emails = [];
2725

2826
public function __construct(string $name)
2927
{
@@ -65,11 +63,9 @@ public function bsonUnserialize(array $data): void
6563

6664
class PersistableEmail implements Persistable
6765
{
68-
/** @var string */
69-
public $type;
66+
public string $type;
7067

71-
/** @var string */
72-
public $address;
68+
public string $address;
7369

7470
public function __construct(string $type, string $address)
7571
{

examples/typemap.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616

1717
class TypeMapEntry implements Unserializable
1818
{
19-
/** @var ObjectId */
20-
private $id;
19+
private ObjectId $id;
2120

22-
/** @var string */
23-
private $name;
21+
private string $name;
2422

2523
/** @var array<TypeMapEmail> */
26-
private $emails;
24+
private array $emails;
2725

2826
private function __construct()
2927
{
@@ -64,11 +62,9 @@ public function bsonUnserialize(array $data): void
6462

6563
class TypeMapEmail implements Unserializable
6664
{
67-
/** @var string */
68-
private $type;
65+
private string $type;
6966

70-
/** @var string */
71-
private $address;
67+
private string $address;
7268

7369
private function __construct()
7470
{

examples/with_transaction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ function toJSON(object $document): string
3737
['x' => 2],
3838
['x' => 3],
3939
],
40-
['session' => $session]
40+
['session' => $session],
4141
);
4242

4343
$collection->updateMany(
4444
['x' => ['$gt' => 1]],
4545
['$set' => ['y' => 1]],
46-
['session' => $session]
46+
['session' => $session],
4747
);
4848
};
4949

phpcs.xml.dist

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<file>rector.php</file>
1818

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

2222
<!-- ****************************************** -->
2323
<!-- Import rules from doctrine/coding-standard -->
@@ -112,8 +112,6 @@
112112

113113
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
114114
<properties>
115-
<!-- Requires PHP 7.4 -->
116-
<property name="enableNativeTypeHint" value="false" />
117115
<!-- Requires PHP 8.0 -->
118116
<property name="enableMixedTypeHint" value="false" />
119117
<!-- Requires PHP 8.0 -->
@@ -154,9 +152,6 @@
154152
<!-- *********************************************************** -->
155153
<!-- Require native type hints for all code without a BC promise -->
156154
<!-- *********************************************************** -->
157-
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint">
158-
<exclude-pattern>src</exclude-pattern>
159-
</rule>
160155
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint">
161156
<exclude-pattern>src</exclude-pattern>
162157
</rule>

rector.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
use Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector;
55
use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector;
66
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
7+
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
78
use Rector\Set\ValueObject\LevelSetList;
9+
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
810

911
return static function (RectorConfig $rectorConfig): void {
1012
$rectorConfig->paths([
@@ -15,7 +17,7 @@
1517
]);
1618

1719
// Modernize code
18-
$rectorConfig->sets([LevelSetList::UP_TO_PHP_72]);
20+
$rectorConfig->sets([LevelSetList::UP_TO_PHP_74]);
1921

2022
$rectorConfig->skip([
2123
// Falsely detect unassigned variables in code paths stopped by PHPUnit\Framework\Assert::markTestSkipped()
@@ -26,6 +28,14 @@
2628
RemoveExtraParametersRector::class => [
2729
__DIR__ . '/src/Operation/',
2830
],
31+
// Assigns wrong type due to outdated PHPStan stubs
32+
TypedPropertyFromAssignsRector::class => [
33+
__DIR__ . '/src/Model/BSONIterator.php',
34+
],
35+
// Not necessary in documentation examples
36+
JsonThrowOnErrorRector::class => [
37+
__DIR__ . '/tests/DocumentationExamplesTest.php',
38+
],
2939
]);
3040

3141
// All classes are public API by default, unless marked with @internal.

src/BulkWriteResult.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,11 @@
2525
*/
2626
class BulkWriteResult
2727
{
28-
/** @var WriteResult */
29-
private $writeResult;
28+
private WriteResult $writeResult;
3029

31-
/** @var array */
32-
private $insertedIds;
30+
private array $insertedIds;
3331

34-
/** @var boolean */
35-
private $isAcknowledged;
32+
private bool $isAcknowledged;
3633

3734
public function __construct(WriteResult $writeResult, array $insertedIds)
3835
{

0 commit comments

Comments
 (0)