Skip to content

PHPLIB-1106: Upgrade doctrine/coding-standard to 11.1.0 #1058

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 4 commits into from
Apr 12, 2023
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"symfony/polyfill-php80": "^1.19"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.6",
"doctrine/coding-standard": "^9.0",
"squizlabs/php_codesniffer": "^3.7",
"doctrine/coding-standard": "^11.1",
"symfony/phpunit-bridge": "^5.2",
"vimeo/psalm": "^4.28"
},
Expand Down
14 changes: 3 additions & 11 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,13 @@
<file>tests</file>
<file>tools</file>

<!-- Target minimum supported PHP version -->
<config name="php_version" value="70200"/>

<!-- ****************************************** -->
<!-- Import rules from doctrine/coding-standard -->
<!-- ****************************************** -->
<rule ref="Doctrine">
<!-- ********************************************** -->
<!-- Exclude sniffs that require newer PHP versions -->
<!-- ********************************************** -->

<!-- Requires PHP 7.4 -->
<exclude name="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator" />

<!-- Requires PHP 8.0 -->
<exclude name="SlevomatCodingStandard.Classes.ModernClassNameReference.ClassNameReferencedViaFunctionCall" />


<!-- *********************************** -->
<!-- Exclude sniffs that cause BC breaks -->
<!-- *********************************** -->
Expand Down
4 changes: 1 addition & 3 deletions src/ChangeStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ public function current()
return $this->iterator->current();
}

/**
* @return CursorId
*/
/** @return CursorId */
public function getCursorId()
{
return $this->iterator->getInnerIterator()->getId();
Expand Down
4 changes: 1 addition & 3 deletions src/GridFS/WritableStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ private function abort(): void
$this->isClosed = true;
}

/**
* @return mixed
*/
/** @return mixed */
private function fileCollectionInsert()
{
$this->file['length'] = $this->length;
Expand Down
4 changes: 1 addition & 3 deletions src/InsertOneResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class InsertOneResult
/** @var boolean */
private $isAcknowledged;

/**
* @param mixed $insertedId
*/
/** @param mixed $insertedId */
public function __construct(WriteResult $writeResult, $insertedId)
{
$this->writeResult = $writeResult;
Expand Down
4 changes: 1 addition & 3 deletions src/Model/BSONIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ public function rewind()
$this->advance();
}

/**
* @see https://php.net/iterator.valid
*/
/** @see https://php.net/iterator.valid */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fixes came from SlevomatCodingStandard.Commenting.RequireOneLineDocComment.

I don't mind them applying to src/. I think they make the most sense in tests/ where we had a lot of @dataProvider annotations taking up multiple lines.

#[ReturnTypeWillChange]
public function valid(): bool
{
Expand Down
16 changes: 4 additions & 12 deletions src/Model/CachingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ public function __construct(Traversable $traversable)
$this->storeCurrentItem();
}

/**
* @see https://php.net/countable.count
*/
/** @see https://php.net/countable.count */
public function count(): int
{
$this->exhaustIterator();
Expand Down Expand Up @@ -104,9 +102,7 @@ public function key()
return $currentItem !== false ? $currentItem[self::FIELD_KEY] : null;
}

/**
* @see https://php.net/iterator.next
*/
/** @see https://php.net/iterator.next */
public function next(): void
{
if (! $this->iteratorExhausted) {
Expand All @@ -121,9 +117,7 @@ public function next(): void
next($this->items);
}

/**
* @see https://php.net/iterator.rewind
*/
/** @see https://php.net/iterator.rewind */
public function rewind(): void
{
/* If the iterator has advanced, exhaust it now so that future iteration
Expand All @@ -136,9 +130,7 @@ public function rewind(): void
reset($this->items);
}

/**
* @see https://php.net/iterator.valid
*/
/** @see https://php.net/iterator.valid */
public function valid(): bool
{
return $this->key() !== null;
Expand Down
12 changes: 3 additions & 9 deletions src/Model/CallbackIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,19 @@ public function key()
return $this->iterator->key();
}

/**
* @see https://php.net/iterator.next
*/
/** @see https://php.net/iterator.next */
public function next(): void
{
$this->iterator->next();
}

/**
* @see https://php.net/iterator.rewind
*/
/** @see https://php.net/iterator.rewind */
public function rewind(): void
{
$this->iterator->rewind();
}

/**
* @see https://php.net/iterator.valid
*/
/** @see https://php.net/iterator.valid */
public function valid(): bool
{
return $this->iterator->valid();
Expand Down
14 changes: 5 additions & 9 deletions src/Model/ChangeStreamIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ public function key()
return $this->isValid ? parent::key() : null;
}

/**
* @see https://php.net/iteratoriterator.rewind
*/
/** @see https://php.net/iteratoriterator.rewind */
public function next(): void
{
/* Determine if advancing the iterator will execute a getMore command
Expand All @@ -199,6 +197,7 @@ public function next(): void

try {
parent::next();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From SlevomatCodingStandard.Classes.ParentCallSpacing.

I don't feel strongly about this and it was a small change affecting only this file.

$this->onIteration(! $getMore);
} finally {
if ($getMore) {
Expand All @@ -207,22 +206,19 @@ public function next(): void
}
}

/**
* @see https://php.net/iteratoriterator.rewind
*/
/** @see https://php.net/iteratoriterator.rewind */
public function rewind(): void
{
if ($this->isRewindNop) {
return;
}

parent::rewind();

$this->onIteration(false);
}

/**
* @see https://php.net/iteratoriterator.valid
*/
/** @see https://php.net/iteratoriterator.valid */
public function valid(): bool
{
return $this->isValid;
Expand Down
4 changes: 1 addition & 3 deletions src/Model/CollectionInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ class CollectionInfo implements ArrayAccess
/** @var array */
private $info;

/**
* @param array $info Collection info
*/
/** @param array $info Collection info */
public function __construct(array $info)
{
$this->info = $info;
Expand Down
4 changes: 1 addition & 3 deletions src/Model/DatabaseInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ class DatabaseInfo implements ArrayAccess
/** @var array */
private $info;

/**
* @param array $info Database info
*/
/** @param array $info Database info */
public function __construct(array $info)
{
$this->info = $info;
Expand Down
4 changes: 1 addition & 3 deletions src/Model/IndexInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ class IndexInfo implements ArrayAccess
/** @var array */
private $info;

/**
* @param array $info Index info
*/
/** @param array $info Index info */
public function __construct(array $info)
{
$this->info = $info;
Expand Down
4 changes: 1 addition & 3 deletions src/Operation/MapReduce.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,7 @@ public function execute(Server $server)
return new MapReduceResult($getIterator, $result);
}

/**
* @param string|array|object $out
*/
/** @param string|array|object $out */
private function checkOutDeprecations($out): void
{
if (is_string($out)) {
Expand Down
4 changes: 1 addition & 3 deletions src/Operation/WithTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
use function call_user_func;
use function time;

/**
* @internal
*/
/** @internal */
class WithTransaction
{
/** @var callable */
Expand Down
8 changes: 2 additions & 6 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public function testConstructorDefaultUri(): void
$this->assertEquals('mongodb://127.0.0.1/', (string) $client);
}

/**
* @doesNotPerformAssertions
*/
/** @doesNotPerformAssertions */
public function testConstructorAutoEncryptionOpts(): void
{
$autoEncryptionOpts = [
Expand All @@ -36,9 +34,7 @@ public function testConstructorAutoEncryptionOpts(): void
new Client(static::getUri(), [], ['autoEncryption' => $autoEncryptionOpts]);
}

/**
* @dataProvider provideInvalidConstructorDriverOptions
*/
/** @dataProvider provideInvalidConstructorDriverOptions */
public function testConstructorDriverOptionTypeChecks(array $driverOptions, string $exception = InvalidArgumentException::class): void
{
$this->expectException($exception);
Expand Down
32 changes: 8 additions & 24 deletions tests/Collection/CollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,15 @@
*/
class CollectionFunctionalTest extends FunctionalTestCase
{
/**
* @dataProvider provideInvalidDatabaseAndCollectionNames
*/
/** @dataProvider provideInvalidDatabaseAndCollectionNames */
public function testConstructorDatabaseNameArgument($databaseName, string $expectedExceptionClass): void
{
$this->expectException($expectedExceptionClass);
// TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378)
new Collection($this->manager, $databaseName, $this->getCollectionName());
}

/**
* @dataProvider provideInvalidDatabaseAndCollectionNames
*/
/** @dataProvider provideInvalidDatabaseAndCollectionNames */
public function testConstructorCollectionNameArgument($collectionName, string $expectedExceptionClass): void
{
$this->expectException($expectedExceptionClass);
Expand All @@ -58,9 +54,7 @@ public function provideInvalidDatabaseAndCollectionNames()
];
}

/**
* @dataProvider provideInvalidConstructorOptions
*/
/** @dataProvider provideInvalidConstructorOptions */
public function testConstructorOptionTypeChecks(array $options): void
{
$this->expectException(InvalidArgumentException::class);
Expand Down Expand Up @@ -172,9 +166,7 @@ function (array $event): void {
);
}

/**
* @dataProvider provideTypeMapOptionsAndExpectedDocuments
*/
/** @dataProvider provideTypeMapOptionsAndExpectedDocuments */
public function testDistinctWithTypeMap(array $typeMap, array $expectedDocuments): void
{
$bulkWrite = new BulkWrite(['ordered' => true]);
Expand Down Expand Up @@ -264,9 +256,7 @@ public function testDrop(): void
$this->assertCollectionDoesNotExist($this->getCollectionName());
}

/**
* @todo Move this to a unit test once Manager can be mocked
*/
/** @todo Move this to a unit test once Manager can be mocked */
public function testDropIndexShouldNotAllowWildcardCharacter(): void
{
$this->expectException(InvalidArgumentException::class);
Expand Down Expand Up @@ -732,9 +722,7 @@ function ($rw) {
);
}

/**
* @dataProvider collectionMethodClosures
*/
/** @dataProvider collectionMethodClosures */
public function testMethodDoesNotInheritReadWriteConcernInTranasaction(Closure $method): void
{
$this->skipIfTransactionsAreNotSupported();
Expand All @@ -760,9 +748,7 @@ function (array $event): void {
);
}

/**
* @dataProvider collectionWriteMethodClosures
*/
/** @dataProvider collectionWriteMethodClosures */
public function testMethodInTransactionWithWriteConcernOption($method): void
{
$this->skipIfTransactionsAreNotSupported();
Expand All @@ -782,9 +768,7 @@ public function testMethodInTransactionWithWriteConcernOption($method): void
}
}

/**
* @dataProvider collectionReadMethodClosures
*/
/** @dataProvider collectionReadMethodClosures */
public function testMethodInTransactionWithReadConcernOption($method): void
{
$this->skipIfTransactionsAreNotSupported();
Expand Down
4 changes: 1 addition & 3 deletions tests/Collection/CrudSpecFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ public function setUp(): void
$this->expectedCollection->drop();
}

/**
* @dataProvider provideSpecificationTests
*/
/** @dataProvider provideSpecificationTests */
public function testSpecification(array $initialData, array $test, $minServerVersion, $maxServerVersion, $serverless): void
{
if (isset($minServerVersion) || isset($maxServerVersion)) {
Expand Down
4 changes: 1 addition & 3 deletions tests/Command/ListCollectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

class ListCollectionsTest extends TestCase
{
/**
* @dataProvider provideInvalidConstructorOptions
*/
/** @dataProvider provideInvalidConstructorOptions */
public function testConstructorOptionTypeChecks(array $options): void
{
$this->expectException(InvalidArgumentException::class);
Expand Down
4 changes: 1 addition & 3 deletions tests/Command/ListDatabasesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

class ListDatabasesTest extends TestCase
{
/**
* @dataProvider provideInvalidConstructorOptions
*/
/** @dataProvider provideInvalidConstructorOptions */
public function testConstructorOptionTypeChecks(array $options): void
{
$this->expectException(InvalidArgumentException::class);
Expand Down
Loading