Skip to content

Commit

Permalink
Modernise code for PHP 7.4
Browse files Browse the repository at this point in the history
This uses rector and phpcbf to automatically fix issues
  • Loading branch information
alcaeus committed Jul 13, 2023
1 parent 7530dca commit 0416b94
Show file tree
Hide file tree
Showing 175 changed files with 961 additions and 1,380 deletions.
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
],
],
]
],
);

$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;

/** @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
4 changes: 1 addition & 3 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
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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 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
7 changes: 2 additions & 5 deletions src/ChangeStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,13 @@ class ChangeStream implements Iterator
/** @var ChangeStreamIterator */
private $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
9 changes: 3 additions & 6 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,11 @@ 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;
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
6 changes: 2 additions & 4 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,9 @@ 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;
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
3 changes: 1 addition & 2 deletions src/Exception/CreateEncryptedCollectionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
*/
final class CreateEncryptedCollectionException extends RuntimeException
{
/** @var array */
private $encryptedFields;
private array $encryptedFields;

public function __construct(Throwable $previous, array $encryptedFields)
{
Expand Down
22 changes: 8 additions & 14 deletions src/GridFS/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,17 @@ class Bucket

private const STREAM_WRAPPER_PROTOCOL = 'gridfs';

/** @var CollectionWrapper */
private $collectionWrapper;
private CollectionWrapper $collectionWrapper;

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

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

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

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

/** @var integer */
private $chunkSizeBytes;
private int $chunkSizeBytes;

/** @var ReadConcern */
private $readConcern;
Expand Down Expand Up @@ -654,7 +648,7 @@ private function createPathForFile(object $file): string
self::STREAM_WRAPPER_PROTOCOL,
urlencode($this->databaseName),
urlencode($this->bucketName),
urlencode($id)
urlencode($id),
);
}

Expand All @@ -667,7 +661,7 @@ private function createPathForUpload(): string
'%s://%s/%s.files',
self::STREAM_WRAPPER_PROTOCOL,
urlencode($this->databaseName),
urlencode($this->bucketName)
urlencode($this->bucketName),
);
}

Expand Down
23 changes: 9 additions & 14 deletions src/GridFS/CollectionWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,15 @@
*/
class CollectionWrapper
{
/** @var string */
private $bucketName;
private string $bucketName;

/** @var Collection */
private $chunksCollection;
private Collection $chunksCollection;

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

/** @var boolean */
private $checkedIndexes = false;
private bool $checkedIndexes = false;

/** @var Collection */
private $filesCollection;
private Collection $filesCollection;

/**
* Constructs a GridFS collection wrapper.
Expand Down Expand Up @@ -120,7 +115,7 @@ public function findChunksByFileId($id, int $fromChunk = 0): Cursor
[
'sort' => ['n' => 1],
'typeMap' => ['root' => 'stdClass'],
]
],
);
}

Expand Down Expand Up @@ -158,7 +153,7 @@ public function findFileByFilenameAndRevision(string $filename, int $revision):
'skip' => $skip,
'sort' => ['uploadDate' => $sortOrder],
'typeMap' => ['root' => 'stdClass'],
]
],
);
assert(is_object($file) || $file === null);

Expand All @@ -174,7 +169,7 @@ public function findFileById($id): ?object
{
$file = $this->filesCollection->findOne(
['_id' => $id],
['typeMap' => ['root' => 'stdClass']]
['typeMap' => ['root' => 'stdClass']],
);
assert(is_object($file) || $file === null);

Expand Down Expand Up @@ -265,7 +260,7 @@ public function updateFilenameForId($id, string $filename): UpdateResult
{
return $this->filesCollection->updateOne(
['_id' => $id],
['$set' => ['filename' => $filename]]
['$set' => ['filename' => $filename]],
);
}

Expand Down
Loading

0 comments on commit 0416b94

Please sign in to comment.