Skip to content

PHPLIB-330: Add property type hints #673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
<!-- Exclude sniffs that require newer PHP versions -->
<!-- Available with PHP 7.0 -->
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes" />
<!-- In addition to requiring PHP 7.0, this sniff will cause a significant amount of BC breaks. Proceed with caution! -->
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration" />
<exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly" />
<exclude name="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" />

Expand Down Expand Up @@ -61,7 +59,6 @@

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

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

<!-- Only enable some checks regarding type hints -->
<!-- In addition to requiring PHP 7.0, this sniff will cause a significant amount of BC breaks. Proceed with caution! -->
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
<!-- Traversable type hints often end up as mixed[], so we skip them for now -->
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification" />
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification" />
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification" />

<!-- Will cause BC breaks to method signatures - disabled for now -->
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint" />
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint" />

<properties>
<property name="enableObjectTypeHint" value="true" />
<property name="enableEachParameterAndReturnInspection" value="false" />
</properties>
</rule>

<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern>/src/GridFS/StreamWrapper</exclude-pattern>
<exclude-pattern>/tests/DocumentationExamplesTest.php</exclude-pattern>
Expand Down
5 changes: 5 additions & 0 deletions src/BulkWriteResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@
*/
class BulkWriteResult
{
/** @var WriteResult */
private $writeResult;

/** @var mixed[] */
private $insertedIds;

/** @var boolean */
private $isAcknowledged;

/**
Expand Down
8 changes: 8 additions & 0 deletions src/ChangeStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,27 @@ class ChangeStream implements Iterator
*/
const CURSOR_NOT_FOUND = 43;

/** @var array */
private static $nonResumableErrorCodes = [
136, // CappedPositionLost
237, // CursorKilled
11601, // Interrupted
];

/** @var callable */
private $resumeCallable;

/** @var ChangeStreamIterator */
private $iterator;

/** @var integer */
private $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;

Expand Down
16 changes: 16 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,35 @@

class Client
{
/** @var array */
private static $defaultTypeMap = [
'array' => BSONArray::class,
'document' => BSONDocument::class,
'root' => BSONDocument::class,
];

/** @var integer */
private static $wireVersionForReadConcern = 4;

/** @var integer */
private static $wireVersionForWritableCommandWriteConcern = 5;

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

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

/** @var ReadPreference */
private $readPreference;

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

/** @var array */
private $typeMap;

/** @var WriteConcern */
private $writeConcern;

/**
Expand Down
22 changes: 22 additions & 0 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,44 @@

class Collection
{
/** @var array */
private static $defaultTypeMap = [
'array' => BSONArray::class,
'document' => BSONDocument::class,
'root' => BSONDocument::class,
];

/** @var integer */
private static $wireVersionForFindAndModifyWriteConcern = 4;

/** @var integer */
private static $wireVersionForReadConcern = 4;

/** @var integer */
private static $wireVersionForWritableCommandWriteConcern = 5;

/** @var integer */
private static $wireVersionForReadConcernWithWriteStage = 8;

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

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

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

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

/** @var ReadPreference */
private $readPreference;

/** @var array */
private $typeMap;

/** @var WriteConcern */
private $writeConcern;

/**
Expand Down
18 changes: 18 additions & 0 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,38 @@

class Database
{
/** @var array */
private static $defaultTypeMap = [
'array' => BSONArray::class,
'document' => BSONDocument::class,
'root' => BSONDocument::class,
];

/** @var integer */
private static $wireVersionForReadConcern = 4;

/** @var integer */
private static $wireVersionForWritableCommandWriteConcern = 5;

/** @var integer */
private static $wireVersionForReadConcernWithWriteStage = 8;

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

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

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

/** @var ReadPreference */
private $readPreference;

/** @var array */
private $typeMap;

/** @var WriteConcern */
private $writeConcern;

/**
Expand Down
6 changes: 3 additions & 3 deletions src/DeleteResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
*/
class DeleteResult
{
/** @var WriteResult */
private $writeResult;

/** @var boolean */
private $isAcknowledged;

/**
* @param WriteResult $writeResult
*/
public function __construct(WriteResult $writeResult)
{
$this->writeResult = $writeResult;
Expand Down
26 changes: 26 additions & 0 deletions src/GridFS/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,50 @@
*/
class Bucket
{
/** @var string */
private static $defaultBucketName = 'fs';

/** @var integer */
private static $defaultChunkSizeBytes = 261120;

/** @var array */
private static $defaultTypeMap = [
'array' => BSONArray::class,
'document' => BSONDocument::class,
'root' => BSONDocument::class,
];

/** @var string */
private static $streamWrapperProtocol = 'gridfs';

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

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

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

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

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

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

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

/** @var ReadPreference */
private $readPreference;

/** @var array */
private $typeMap;

/** @var WriteConcern */
private $writeConcern;

/**
Expand Down
9 changes: 9 additions & 0 deletions src/GridFS/CollectionWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,19 @@
*/
class CollectionWrapper
{
/** @var string */
private $bucketName;

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

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

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

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

/**
Expand Down
19 changes: 19 additions & 0 deletions src/GridFS/ReadableStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,34 @@
*/
class ReadableStream
{
/** @var string|null */
private $buffer;

/** @var integer */
private $bufferOffset = 0;

/** @var integer */
private $chunkSize;

/** @var integer */
private $chunkOffset = 0;

/** @var IteratorIterator|null */
private $chunksIterator;

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

/** @var float|integer */
private $expectedLastChunkSize = 0;

/** @var stdClass */
private $file;

/** @var integer */
private $length;

/** @var integer */
private $numChunks = 0;

/**
Expand Down
9 changes: 6 additions & 3 deletions src/GridFS/StreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,16 @@
*/
class StreamWrapper
{
/**
* @var resource|null Stream context (set by PHP)
*/
/** @var resource|null Stream context (set by PHP) */
public $context;

/** @var string|null */
private $mode;

/** @var string|null */
private $protocol;

/** @var ReadableStream|WritableStream|null */
private $stream;

/**
Expand Down
18 changes: 18 additions & 0 deletions src/GridFS/WritableStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,34 @@
*/
class WritableStream
{
/** @var integer */
private static $defaultChunkSizeBytes = 261120;

/** @var string */
private $buffer = '';

/** @var integer */
private $chunkOffset = 0;

/** @var integer */
private $chunkSize;

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

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

/** @var array */
private $file;

/** @var resource */
private $hashCtx;

/** @var boolean */
private $isClosed = false;

/** @var integer */
private $length = 0;

/**
Expand Down
5 changes: 5 additions & 0 deletions src/InsertManyResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@
*/
class InsertManyResult
{
/** @var WriteResult */
private $writeResult;

/** @var mixed[] */
private $insertedIds;

/** @var boolean */
private $isAcknowledged;

/**
Expand Down
Loading