Skip to content

Commit 4a764fe

Browse files
committed
Add type hints to all class properties
1 parent 2789277 commit 4a764fe

File tree

86 files changed

+598
-18
lines changed

Some content is hidden

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

86 files changed

+598
-18
lines changed

phpcs.xml.dist

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
<!-- Exclude sniffs that require newer PHP versions -->
2020
<!-- Available with PHP 7.0 -->
2121
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes" />
22-
<!-- In addition to requiring PHP 7.0, this sniff will cause a significant amount of BC breaks. Proceed with caution! -->
23-
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration" />
2422
<exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly" />
2523
<exclude name="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" />
2624

@@ -61,7 +59,6 @@
6159

6260
<!-- These sniffs cause a large diff, so enable them in separate steps -->
6361
<exclude name="SlevomatCodingStandard.Commenting.DocCommentSpacing.IncorrectAnnotationsGroup" />
64-
<exclude name="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment" />
6562
<exclude name="Squiz.Strings.DoubleQuoteUsage" />
6663

6764
<!-- Sniff currently breaks, see https://github.com/slevomat/coding-standard/issues/727 -->
@@ -90,6 +87,24 @@
9087
</properties>
9188
</rule>
9289

90+
<!-- Only enable some checks regarding type hints -->
91+
<!-- In addition to requiring PHP 7.0, this sniff will cause a significant amount of BC breaks. Proceed with caution! -->
92+
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
93+
<!-- Traversable type hints often end up as mixed[], so we skip them for now -->
94+
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification" />
95+
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification" />
96+
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification" />
97+
98+
<!-- Will cause BC breaks to method signatures - disabled for now -->
99+
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint" />
100+
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint" />
101+
102+
<properties>
103+
<property name="enableObjectTypeHint" value="true" />
104+
<property name="enableEachParameterAndReturnInspection" value="false" />
105+
</properties>
106+
</rule>
107+
93108
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
94109
<exclude-pattern>/src/GridFS/StreamWrapper</exclude-pattern>
95110
<exclude-pattern>/tests/DocumentationExamplesTest.php</exclude-pattern>

src/BulkWriteResult.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@
2525
*/
2626
class BulkWriteResult
2727
{
28+
/** @var WriteResult */
2829
private $writeResult;
30+
31+
/** @var mixed[] */
2932
private $insertedIds;
33+
34+
/** @var boolean */
3035
private $isAcknowledged;
3136

3237
/**

src/ChangeStream.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,27 @@ class ChangeStream implements Iterator
4242
*/
4343
const CURSOR_NOT_FOUND = 43;
4444

45+
/** @var array */
4546
private static $nonResumableErrorCodes = [
4647
136, // CappedPositionLost
4748
237, // CursorKilled
4849
11601, // Interrupted
4950
];
5051

52+
/** @var callable */
5153
private $resumeCallable;
54+
55+
/** @var ChangeStreamIterator */
5256
private $iterator;
57+
58+
/** @var integer */
5359
private $key = 0;
5460

5561
/**
5662
* Whether the change stream has advanced to its first result. This is used
5763
* to determine whether $key should be incremented after an iteration event.
64+
*
65+
* @var boolean
5866
*/
5967
private $hasAdvanced = false;
6068

src/Client.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,35 @@
3737

3838
class Client
3939
{
40+
/** @var array */
4041
private static $defaultTypeMap = [
4142
'array' => BSONArray::class,
4243
'document' => BSONDocument::class,
4344
'root' => BSONDocument::class,
4445
];
46+
47+
/** @var integer */
4548
private static $wireVersionForReadConcern = 4;
49+
50+
/** @var integer */
4651
private static $wireVersionForWritableCommandWriteConcern = 5;
4752

53+
/** @var Manager */
4854
private $manager;
55+
56+
/** @var ReadConcern */
4957
private $readConcern;
58+
59+
/** @var ReadPreference */
5060
private $readPreference;
61+
62+
/** @var string */
5163
private $uri;
64+
65+
/** @var array */
5266
private $typeMap;
67+
68+
/** @var WriteConcern */
5369
private $writeConcern;
5470

5571
/**

src/Collection.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,44 @@
6666

6767
class Collection
6868
{
69+
/** @var array */
6970
private static $defaultTypeMap = [
7071
'array' => BSONArray::class,
7172
'document' => BSONDocument::class,
7273
'root' => BSONDocument::class,
7374
];
75+
76+
/** @var integer */
7477
private static $wireVersionForFindAndModifyWriteConcern = 4;
78+
79+
/** @var integer */
7580
private static $wireVersionForReadConcern = 4;
81+
82+
/** @var integer */
7683
private static $wireVersionForWritableCommandWriteConcern = 5;
84+
85+
/** @var integer */
7786
private static $wireVersionForReadConcernWithWriteStage = 8;
7887

88+
/** @var string */
7989
private $collectionName;
90+
91+
/** @var string */
8092
private $databaseName;
93+
94+
/** @var Manager */
8195
private $manager;
96+
97+
/** @var ReadConcern */
8298
private $readConcern;
99+
100+
/** @var ReadPreference */
83101
private $readPreference;
102+
103+
/** @var array */
84104
private $typeMap;
105+
106+
/** @var WriteConcern */
85107
private $writeConcern;
86108

87109
/**

src/Database.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,38 @@
4444

4545
class Database
4646
{
47+
/** @var array */
4748
private static $defaultTypeMap = [
4849
'array' => BSONArray::class,
4950
'document' => BSONDocument::class,
5051
'root' => BSONDocument::class,
5152
];
53+
54+
/** @var integer */
5255
private static $wireVersionForReadConcern = 4;
56+
57+
/** @var integer */
5358
private static $wireVersionForWritableCommandWriteConcern = 5;
59+
60+
/** @var integer */
5461
private static $wireVersionForReadConcernWithWriteStage = 8;
5562

63+
/** @var string */
5664
private $databaseName;
65+
66+
/** @var Manager */
5767
private $manager;
68+
69+
/** @var ReadConcern */
5870
private $readConcern;
71+
72+
/** @var ReadPreference */
5973
private $readPreference;
74+
75+
/** @var array */
6076
private $typeMap;
77+
78+
/** @var WriteConcern */
6179
private $writeConcern;
6280

6381
/**

src/DeleteResult.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
*/
2626
class DeleteResult
2727
{
28+
/** @var WriteResult */
2829
private $writeResult;
30+
31+
/** @var boolean */
2932
private $isAcknowledged;
3033

31-
/**
32-
* @param WriteResult $writeResult
33-
*/
3434
public function __construct(WriteResult $writeResult)
3535
{
3636
$this->writeResult = $writeResult;

src/GridFS/Bucket.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,50 @@
6262
*/
6363
class Bucket
6464
{
65+
/** @var string */
6566
private static $defaultBucketName = 'fs';
67+
68+
/** @var integer */
6669
private static $defaultChunkSizeBytes = 261120;
70+
71+
/** @var array */
6772
private static $defaultTypeMap = [
6873
'array' => BSONArray::class,
6974
'document' => BSONDocument::class,
7075
'root' => BSONDocument::class,
7176
];
77+
78+
/** @var string */
7279
private static $streamWrapperProtocol = 'gridfs';
7380

81+
/** @var CollectionWrapper */
7482
private $collectionWrapper;
83+
84+
/** @var string */
7585
private $databaseName;
86+
87+
/** @var Manager */
7688
private $manager;
89+
90+
/** @var string */
7791
private $bucketName;
92+
93+
/** @var boolean */
7894
private $disableMD5;
95+
96+
/** @var integer */
7997
private $chunkSizeBytes;
98+
99+
/** @var ReadConcern */
80100
private $readConcern;
101+
102+
/** @var ReadPreference */
81103
private $readPreference;
104+
105+
/** @var array */
82106
private $typeMap;
107+
108+
/** @var WriteConcern */
83109
private $writeConcern;
84110

85111
/**

src/GridFS/CollectionWrapper.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,19 @@
3434
*/
3535
class CollectionWrapper
3636
{
37+
/** @var string */
3738
private $bucketName;
39+
40+
/** @var Collection */
3841
private $chunksCollection;
42+
43+
/** @var string */
3944
private $databaseName;
45+
46+
/** @var boolean */
4047
private $checkedIndexes = false;
48+
49+
/** @var Collection */
4150
private $filesCollection;
4251

4352
/**

src/GridFS/ReadableStream.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,34 @@
3636
*/
3737
class ReadableStream
3838
{
39+
/** @var string|null */
3940
private $buffer;
41+
42+
/** @var integer */
4043
private $bufferOffset = 0;
44+
45+
/** @var integer */
4146
private $chunkSize;
47+
48+
/** @var integer */
4249
private $chunkOffset = 0;
50+
51+
/** @var IteratorIterator|null */
4352
private $chunksIterator;
53+
54+
/** @var CollectionWrapper */
4455
private $collectionWrapper;
56+
57+
/** @var float|integer */
4558
private $expectedLastChunkSize = 0;
59+
60+
/** @var stdClass */
4661
private $file;
62+
63+
/** @var integer */
4764
private $length;
65+
66+
/** @var integer */
4867
private $numChunks = 0;
4968

5069
/**

src/GridFS/StreamWrapper.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,16 @@
4545
*/
4646
class StreamWrapper
4747
{
48-
/**
49-
* @var resource|null Stream context (set by PHP)
50-
*/
48+
/** @var resource|null Stream context (set by PHP) */
5149
public $context;
5250

51+
/** @var string|null */
5352
private $mode;
53+
54+
/** @var string|null */
5455
private $protocol;
56+
57+
/** @var ReadableStream|WritableStream|null */
5558
private $stream;
5659

5760
/**

src/GridFS/WritableStream.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,34 @@
4444
*/
4545
class WritableStream
4646
{
47+
/** @var integer */
4748
private static $defaultChunkSizeBytes = 261120;
4849

50+
/** @var string */
4951
private $buffer = '';
52+
53+
/** @var integer */
5054
private $chunkOffset = 0;
55+
56+
/** @var integer */
5157
private $chunkSize;
58+
59+
/** @var boolean */
5260
private $disableMD5;
61+
62+
/** @var CollectionWrapper */
5363
private $collectionWrapper;
64+
65+
/** @var array */
5466
private $file;
67+
68+
/** @var resource */
5569
private $hashCtx;
70+
71+
/** @var boolean */
5672
private $isClosed = false;
73+
74+
/** @var integer */
5775
private $length = 0;
5876

5977
/**

src/InsertManyResult.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@
2525
*/
2626
class InsertManyResult
2727
{
28+
/** @var WriteResult */
2829
private $writeResult;
30+
31+
/** @var mixed[] */
2932
private $insertedIds;
33+
34+
/** @var boolean */
3035
private $isAcknowledged;
3136

3237
/**

0 commit comments

Comments
 (0)