Skip to content

Commit 14d6d65

Browse files
committed
Modernise code for PHP 7.4
This uses rector and phpcbf to automatically fix issues
1 parent 7530dca commit 14d6d65

File tree

175 files changed

+972
-1393
lines changed

Some content is hidden

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

175 files changed

+972
-1393
lines changed

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 & 3 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 -->

rector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
]);
1616

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

2020
$rectorConfig->skip([
2121
// Falsely detect unassigned variables in code paths stopped by PHPUnit\Framework\Assert::markTestSkipped()

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
{

src/ChangeStream.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,13 @@ class ChangeStream implements Iterator
7474
/** @var ChangeStreamIterator */
7575
private $iterator;
7676

77-
/** @var integer */
78-
private $key = 0;
77+
private int $key = 0;
7978

8079
/**
8180
* Whether the change stream has advanced to its first result. This is used
8281
* to determine whether $key should be incremented after an iteration event.
83-
*
84-
* @var boolean
8582
*/
86-
private $hasAdvanced = false;
83+
private bool $hasAdvanced = false;
8784

8885
/**
8986
* @internal

src/Client.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,19 @@ class Client
5454

5555
private const HANDSHAKE_SEPARATOR = '/';
5656

57-
/** @var string|null */
58-
private static $version;
57+
private static ?string $version = null;
5958

60-
/** @var Manager */
61-
private $manager;
59+
private Manager $manager;
6260

63-
/** @var ReadConcern */
64-
private $readConcern;
61+
private ReadConcern $readConcern;
6562

66-
/** @var ReadPreference */
67-
private $readPreference;
63+
private ReadPreference $readPreference;
6864

69-
/** @var string */
70-
private $uri;
65+
private string $uri;
7166

72-
/** @var array */
73-
private $typeMap;
67+
private array $typeMap;
7468

75-
/** @var WriteConcern */
76-
private $writeConcern;
69+
private WriteConcern $writeConcern;
7770

7871
/**
7972
* Constructs a new Client instance.

src/Collection.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,11 @@ class Collection
7777

7878
private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8;
7979

80-
/** @var string */
81-
private $collectionName;
80+
private string $collectionName;
8281

83-
/** @var string */
84-
private $databaseName;
82+
private string $databaseName;
8583

86-
/** @var Manager */
87-
private $manager;
84+
private Manager $manager;
8885

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

src/Command/ListCollections.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@
3737
*/
3838
class ListCollections implements Executable
3939
{
40-
/** @var string */
41-
private $databaseName;
40+
private string $databaseName;
4241

43-
/** @var array */
44-
private $options;
42+
private array $options;
4543

4644
/**
4745
* Constructs a listCollections command.

src/Command/ListDatabases.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
*/
4040
class ListDatabases implements Executable
4141
{
42-
/** @var array */
43-
private $options;
42+
private array $options;
4443

4544
/**
4645
* Constructs a listDatabases command.

src/Database.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ class Database
6161

6262
private const WIRE_VERSION_FOR_READ_CONCERN_WITH_WRITE_STAGE = 8;
6363

64-
/** @var string */
65-
private $databaseName;
64+
private string $databaseName;
6665

67-
/** @var Manager */
68-
private $manager;
66+
private Manager $manager;
6967

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

src/DeleteResult.php

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

31-
/** @var boolean */
32-
private $isAcknowledged;
30+
private bool $isAcknowledged;
3331

3432
public function __construct(WriteResult $writeResult)
3533
{

src/Exception/CreateEncryptedCollectionException.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
*/
2929
final class CreateEncryptedCollectionException extends RuntimeException
3030
{
31-
/** @var array */
32-
private $encryptedFields;
31+
private array $encryptedFields;
3332

3433
public function __construct(Throwable $previous, array $encryptedFields)
3534
{

src/GridFS/Bucket.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,17 @@ class Bucket
7474

7575
private const STREAM_WRAPPER_PROTOCOL = 'gridfs';
7676

77-
/** @var CollectionWrapper */
78-
private $collectionWrapper;
77+
private CollectionWrapper $collectionWrapper;
7978

80-
/** @var string */
81-
private $databaseName;
79+
private string $databaseName;
8280

83-
/** @var Manager */
84-
private $manager;
81+
private Manager $manager;
8582

86-
/** @var string */
87-
private $bucketName;
83+
private string $bucketName;
8884

89-
/** @var boolean */
90-
private $disableMD5;
85+
private bool $disableMD5;
9186

92-
/** @var integer */
93-
private $chunkSizeBytes;
87+
private int $chunkSizeBytes;
9488

9589
/** @var ReadConcern */
9690
private $readConcern;
@@ -654,7 +648,7 @@ private function createPathForFile(object $file): string
654648
self::STREAM_WRAPPER_PROTOCOL,
655649
urlencode($this->databaseName),
656650
urlencode($this->bucketName),
657-
urlencode($id)
651+
urlencode($id),
658652
);
659653
}
660654

@@ -667,7 +661,7 @@ private function createPathForUpload(): string
667661
'%s://%s/%s.files',
668662
self::STREAM_WRAPPER_PROTOCOL,
669663
urlencode($this->databaseName),
670-
urlencode($this->bucketName)
664+
urlencode($this->bucketName),
671665
);
672666
}
673667

src/GridFS/CollectionWrapper.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,15 @@
4040
*/
4141
class CollectionWrapper
4242
{
43-
/** @var string */
44-
private $bucketName;
43+
private string $bucketName;
4544

46-
/** @var Collection */
47-
private $chunksCollection;
45+
private Collection $chunksCollection;
4846

49-
/** @var string */
50-
private $databaseName;
47+
private string $databaseName;
5148

52-
/** @var boolean */
53-
private $checkedIndexes = false;
49+
private bool $checkedIndexes = false;
5450

55-
/** @var Collection */
56-
private $filesCollection;
51+
private Collection $filesCollection;
5752

5853
/**
5954
* Constructs a GridFS collection wrapper.
@@ -120,7 +115,7 @@ public function findChunksByFileId($id, int $fromChunk = 0): Cursor
120115
[
121116
'sort' => ['n' => 1],
122117
'typeMap' => ['root' => 'stdClass'],
123-
]
118+
],
124119
);
125120
}
126121

@@ -158,7 +153,7 @@ public function findFileByFilenameAndRevision(string $filename, int $revision):
158153
'skip' => $skip,
159154
'sort' => ['uploadDate' => $sortOrder],
160155
'typeMap' => ['root' => 'stdClass'],
161-
]
156+
],
162157
);
163158
assert(is_object($file) || $file === null);
164159

@@ -174,7 +169,7 @@ public function findFileById($id): ?object
174169
{
175170
$file = $this->filesCollection->findOne(
176171
['_id' => $id],
177-
['typeMap' => ['root' => 'stdClass']]
172+
['typeMap' => ['root' => 'stdClass']],
178173
);
179174
assert(is_object($file) || $file === null);
180175

@@ -265,7 +260,7 @@ public function updateFilenameForId($id, string $filename): UpdateResult
265260
{
266261
return $this->filesCollection->updateOne(
267262
['_id' => $id],
268-
['$set' => ['filename' => $filename]]
263+
['$set' => ['filename' => $filename]],
269264
);
270265
}
271266

0 commit comments

Comments
 (0)