Skip to content

Commit b0f110f

Browse files
committed
PHPLIB-600: Add type definitions for parameters
1 parent 5d48a1e commit b0f110f

Some content is hidden

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

60 files changed

+128
-122
lines changed

phpcs.xml.dist

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,9 @@
162162
</rule>
163163

164164

165-
<!-- *********************************************************************************** -->
166-
<!-- Require native type hints for all parameters, properties, and return types in tests -->
167-
<!-- *********************************************************************************** -->
168-
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint">
169-
<exclude-pattern>src</exclude-pattern>
170-
</rule>
165+
<!-- *********************************************************** -->
166+
<!-- Require native type hints for all code without a BC promise -->
167+
<!-- *********************************************************** -->
171168
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint">
172169
<exclude-pattern>src</exclude-pattern>
173170
</rule>

src/ChangeStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private function isResumableError(RuntimeException $exception)
224224
* @param boolean $incrementKey Increment $key if there is a current result
225225
* @throws ResumeTokenException
226226
*/
227-
private function onIteration($incrementKey)
227+
private function onIteration(bool $incrementKey)
228228
{
229229
/* If the cursorId is 0, the server has invalidated the cursor and we
230230
* will never perform another getMore nor need to resume since any

src/Client.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class Client
9898
* @throws DriverInvalidArgumentException for parameter/option parsing errors in the driver
9999
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
100100
*/
101-
public function __construct($uri = 'mongodb://127.0.0.1/', array $uriOptions = [], array $driverOptions = [])
101+
public function __construct(string $uri = 'mongodb://127.0.0.1/', array $uriOptions = [], array $driverOptions = [])
102102
{
103103
$driverOptions += ['typeMap' => self::$defaultTypeMap];
104104

@@ -155,7 +155,7 @@ public function __debugInfo()
155155
* @param string $databaseName Name of the database to select
156156
* @return Database
157157
*/
158-
public function __get($databaseName)
158+
public function __get(string $databaseName)
159159
{
160160
return $this->selectDatabase($databaseName);
161161
}
@@ -201,7 +201,7 @@ public function createClientEncryption(array $options)
201201
* @throws InvalidArgumentException for parameter/option parsing errors
202202
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
203203
*/
204-
public function dropDatabase($databaseName, array $options = [])
204+
public function dropDatabase(string $databaseName, array $options = [])
205205
{
206206
if (! isset($options['typeMap'])) {
207207
$options['typeMap'] = $this->typeMap;
@@ -314,7 +314,7 @@ public function listDatabases(array $options = [])
314314
* @return Collection
315315
* @throws InvalidArgumentException for parameter/option parsing errors
316316
*/
317-
public function selectCollection($databaseName, $collectionName, array $options = [])
317+
public function selectCollection(string $databaseName, string $collectionName, array $options = [])
318318
{
319319
$options += ['typeMap' => $this->typeMap];
320320

@@ -330,7 +330,7 @@ public function selectCollection($databaseName, $collectionName, array $options
330330
* @return Database
331331
* @throws InvalidArgumentException for parameter/option parsing errors
332332
*/
333-
public function selectDatabase($databaseName, array $options = [])
333+
public function selectDatabase(string $databaseName, array $options = [])
334334
{
335335
$options += ['typeMap' => $this->typeMap];
336336

src/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class Collection
126126
* @param array $options Collection options
127127
* @throws InvalidArgumentException for parameter/option parsing errors
128128
*/
129-
public function __construct(Manager $manager, $databaseName, $collectionName, array $options = [])
129+
public function __construct(Manager $manager, string $databaseName, string $collectionName, array $options = [])
130130
{
131131
if (strlen((string) $databaseName) < 1) {
132132
throw new InvalidArgumentException('$databaseName is invalid: ' . $databaseName);
@@ -452,7 +452,7 @@ public function deleteOne($filter, array $options = [])
452452
* @throws InvalidArgumentException for parameter/option parsing errors
453453
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
454454
*/
455-
public function distinct($fieldName, $filter = [], array $options = [])
455+
public function distinct(string $fieldName, $filter = [], array $options = [])
456456
{
457457
if (! isset($options['readPreference']) && ! is_in_transaction($options)) {
458458
$options['readPreference'] = $this->readPreference;

src/Command/ListCollections.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ListCollections implements Executable
7373
* @param array $options Command options
7474
* @throws InvalidArgumentException for parameter/option parsing errors
7575
*/
76-
public function __construct($databaseName, array $options = [])
76+
public function __construct(string $databaseName, array $options = [])
7777
{
7878
if (isset($options['authorizedCollections']) && ! is_bool($options['authorizedCollections'])) {
7979
throw InvalidArgumentException::invalidType('"authorizedCollections" option', $options['authorizedCollections'], 'boolean');

src/Database.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class Database
104104
* @param array $options Database options
105105
* @throws InvalidArgumentException for parameter/option parsing errors
106106
*/
107-
public function __construct(Manager $manager, $databaseName, array $options = [])
107+
public function __construct(Manager $manager, string $databaseName, array $options = [])
108108
{
109109
if (strlen((string) $databaseName) < 1) {
110110
throw new InvalidArgumentException('$databaseName is invalid: ' . $databaseName);
@@ -164,7 +164,7 @@ public function __debugInfo()
164164
* @param string $collectionName Name of the collection to select
165165
* @return Collection
166166
*/
167-
public function __get($collectionName)
167+
public function __get(string $collectionName)
168168
{
169169
return $this->selectCollection($collectionName);
170170
}
@@ -264,7 +264,7 @@ public function command($command, array $options = [])
264264
* @throws InvalidArgumentException for parameter/option parsing errors
265265
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
266266
*/
267-
public function createCollection($collectionName, array $options = [])
267+
public function createCollection(string $collectionName, array $options = [])
268268
{
269269
if (! isset($options['typeMap'])) {
270270
$options['typeMap'] = $this->typeMap;
@@ -340,7 +340,7 @@ public function drop(array $options = [])
340340
* @throws InvalidArgumentException for parameter/option parsing errors
341341
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
342342
*/
343-
public function dropCollection($collectionName, array $options = [])
343+
public function dropCollection(string $collectionName, array $options = [])
344344
{
345345
if (! isset($options['typeMap'])) {
346346
$options['typeMap'] = $this->typeMap;
@@ -477,7 +477,7 @@ public function listCollections(array $options = [])
477477
* @throws InvalidArgumentException for parameter/option parsing errors
478478
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
479479
*/
480-
public function modifyCollection($collectionName, array $collectionOptions, array $options = [])
480+
public function modifyCollection(string $collectionName, array $collectionOptions, array $options = [])
481481
{
482482
if (! isset($options['typeMap'])) {
483483
$options['typeMap'] = $this->typeMap;
@@ -537,7 +537,7 @@ public function renameCollection(string $fromCollectionName, string $toCollectio
537537
* @return Collection
538538
* @throws InvalidArgumentException for parameter/option parsing errors
539539
*/
540-
public function selectCollection($collectionName, array $options = [])
540+
public function selectCollection(string $collectionName, array $options = [])
541541
{
542542
$options += [
543543
'readConcern' => $this->readConcern,

src/Exception/BadMethodCallException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BadMethodCallException extends BaseBadMethodCallException implements Excep
2929
* @param string $class Class name
3030
* @return self
3131
*/
32-
public static function classIsImmutable($class)
32+
public static function classIsImmutable(string $class)
3333
{
3434
return new static(sprintf('%s is immutable', $class));
3535
}
@@ -40,7 +40,7 @@ public static function classIsImmutable($class)
4040
* @param string $method Method name
4141
* @return self
4242
*/
43-
public static function unacknowledgedWriteResultAccess($method)
43+
public static function unacknowledgedWriteResultAccess(string $method)
4444
{
4545
return new static(sprintf('%s should not be called for an unacknowledged write result', $method));
4646
}

src/Exception/InvalidArgumentException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class InvalidArgumentException extends DriverInvalidArgumentException implements
3636
* @param string|string[] $expectedType Expected type
3737
* @return self
3838
*/
39-
public static function invalidType($name, $value, $expectedType)
39+
public static function invalidType(string $name, $value, $expectedType)
4040
{
4141
if (is_array($expectedType)) {
4242
switch (count($expectedType)) {

src/GridFS/Bucket.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class Bucket
137137
* @param array $options Bucket options
138138
* @throws InvalidArgumentException for parameter/option parsing errors
139139
*/
140-
public function __construct(Manager $manager, $databaseName, array $options = [])
140+
public function __construct(Manager $manager, string $databaseName, array $options = [])
141141
{
142142
$options += [
143143
'bucketName' => self::$defaultBucketName,
@@ -282,7 +282,7 @@ public function downloadToStream($id, $destination)
282282
* @throws StreamException if the file could not be uploaded
283283
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
284284
*/
285-
public function downloadToStreamByName($filename, $destination, array $options = [])
285+
public function downloadToStreamByName(string $filename, $destination, array $options = [])
286286
{
287287
if (! is_resource($destination) || get_resource_type($destination) != "stream") {
288288
throw InvalidArgumentException::invalidType('$destination', $destination, 'resource');
@@ -517,7 +517,7 @@ public function openDownloadStream($id)
517517
* @throws FileNotFoundException if no file could be selected
518518
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
519519
*/
520-
public function openDownloadStreamByName($filename, array $options = [])
520+
public function openDownloadStreamByName(string $filename, array $options = [])
521521
{
522522
$options += ['revision' => -1];
523523

@@ -550,7 +550,7 @@ public function openDownloadStreamByName($filename, array $options = [])
550550
* @param array $options Upload options
551551
* @return resource
552552
*/
553-
public function openUploadStream($filename, array $options = [])
553+
public function openUploadStream(string $filename, array $options = [])
554554
{
555555
$options += ['chunkSizeBytes' => $this->chunkSizeBytes];
556556

@@ -574,7 +574,7 @@ public function openUploadStream($filename, array $options = [])
574574
* @throws FileNotFoundException if no file could be selected
575575
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
576576
*/
577-
public function rename($id, $newFilename)
577+
public function rename($id, string $newFilename)
578578
{
579579
$updateResult = $this->collectionWrapper->updateFilenameForId($id, $newFilename);
580580

@@ -620,7 +620,7 @@ public function rename($id, $newFilename)
620620
* @throws StreamException if the file could not be uploaded
621621
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
622622
*/
623-
public function uploadFromStream($filename, $source, array $options = [])
623+
public function uploadFromStream(string $filename, $source, array $options = [])
624624
{
625625
if (! is_resource($source) || get_resource_type($source) != "stream") {
626626
throw InvalidArgumentException::invalidType('$source', $source, 'resource');

src/GridFS/CollectionWrapper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class CollectionWrapper
6464
* @param array $collectionOptions Collection options
6565
* @throws InvalidArgumentException
6666
*/
67-
public function __construct(Manager $manager, $databaseName, $bucketName, array $collectionOptions = [])
67+
public function __construct(Manager $manager, string $databaseName, string $bucketName, array $collectionOptions = [])
6868
{
6969
$this->databaseName = (string) $databaseName;
7070
$this->bucketName = (string) $bucketName;
@@ -110,7 +110,7 @@ public function dropCollections()
110110
* @param integer $fromChunk Starting chunk (inclusive)
111111
* @return Cursor
112112
*/
113-
public function findChunksByFileId($id, $fromChunk = 0)
113+
public function findChunksByFileId($id, int $fromChunk = 0)
114114
{
115115
return $this->chunksCollection->find(
116116
[
@@ -142,7 +142,7 @@ public function findChunksByFileId($id, $fromChunk = 0)
142142
* @param integer $revision
143143
* @return stdClass|null
144144
*/
145-
public function findFileByFilenameAndRevision($filename, $revision)
145+
public function findFileByFilenameAndRevision(string $filename, int $revision)
146146
{
147147
$filename = (string) $filename;
148148
$revision = (integer) $revision;
@@ -281,7 +281,7 @@ public function insertFile($file)
281281
* @param string $filename
282282
* @return UpdateResult
283283
*/
284-
public function updateFilenameForId($id, $filename)
284+
public function updateFilenameForId($id, string $filename)
285285
{
286286
return $this->filesCollection->updateOne(
287287
['_id' => $id],

0 commit comments

Comments
 (0)