Skip to content

Commit 41b0bc8

Browse files
authored
PHPLIB-1106: Upgrade doctrine/coding-standard to 11.1.0 (#1058)
* PHPLIB-1106: Upgrade doctrine/coding-standard to ^11.1 Also bumps phpcs to ^3.7 * Specify minimum supported PHP version for CS config This ensures consistent reporting regardless of the PHP version used to execute phpcs. It also allows removing excludes for sniffs that apply to newer syntax. * phpcbf: fix SlevomatCodingStandard.Classes.ParentCallSpacing PHPCBF RESULT SUMMARY ---------------------------------------------------------------------- FILE FIXED REMAINING ---------------------------------------------------------------------- src/Model/ChangeStreamIterator.php 2 0 ---------------------------------------------------------------------- A TOTAL OF 2 ERRORS WERE FIXED IN 1 FILE ---------------------------------------------------------------------- Time: 7.86 secs; Memory: 10MB * phpcbf: fix SlevomatCodingStandard.Commenting.RequireOneLineDocComment PHPCBF RESULT SUMMARY ------------------------------------------------------------------------- FILE FIXED REMAINING ------------------------------------------------------------------------- tests/Operation/DropCollectionTest.php 1 0 tests/Operation/ListIndexesTest.php 1 0 tests/Operation/EstimatedDocumentCountTest.php 1 0 tests/Operation/RenameCollectionTest.php 1 0 tests/Command/ListDatabasesTest.php 1 0 tests/Operation/ModifyCollectionTest.php 1 0 tests/Operation/ExplainTest.php 1 0 tests/Operation/InsertOneTest.php 2 0 tests/Operation/UpdateManyTest.php 3 0 tests/Operation/CountTest.php 2 0 tests/Operation/UpdateOneTest.php 3 0 tests/Operation/CreateIndexesTest.php 2 0 tests/UnifiedSpecTests/FailPointObserver.php 3 0 tests/Operation/DeleteTest.php 4 0 tests/Operation/ReplaceOneTest.php 3 0 src/Model/CallbackIterator.php 3 0 tests/Command/ListCollectionsTest.php 1 0 src/InsertOneResult.php 1 0 tests/PedantryTest.php 1 0 tests/Operation/DropIndexesTest.php 1 0 tests/Operation/WatchTest.php 1 0 tests/GridFS/WritableStreamFunctionalTest.php 3 0 src/Model/DatabaseInfo.php 1 0 tests/Operation/UpdateTest.php 3 0 tests/Operation/FindOneFunctionalTest.php 1 0 tests/Operation/InsertManyTest.php 2 0 tests/Operation/DropEncryptedCollectionTest.php 1 0 tests/Operation/CreateEncryptedCollectionTest.php 1 0 tests/Operation/FindOneAndUpdateTest.php 4 0 tests/Operation/FindAndModifyTest.php 1 0 src/Model/CachingIterator.php 4 0 tests/Model/IndexInputTest.php 2 0 tests/Operation/FindOneAndReplaceTest.php 4 0 tests/Operation/DropDatabaseTest.php 1 0 src/ChangeStream.php 1 0 tests/Operation/InsertOneFunctionalTest.php 3 0 tests/Operation/InsertManyFunctionalTest.php 2 0 src/Operation/WithTransaction.php 1 0 tests/Model/BSONIteratorTest.php 1 0 tests/Operation/DistinctTest.php 2 0 tests/Operation/AggregateTest.php 1 0 tests/Operation/DropDatabaseFunctionalTest.php 1 0 src/Model/ChangeStreamIterator.php 3 0 tests/UnifiedSpecTests/EventCollector.php 3 0 src/Model/IndexInfo.php 1 0 tests/SpecTests/ReadWriteConcernSpecTest.php 1 0 tests/Operation/DropCollectionFunctionalTest.php 1 0 src/Model/BSONIterator.php 1 0 tests/Operation/CreateCollectionTest.php 1 0 tests/UnifiedSpecTests/EntityMap.php 3 0 tests/Model/ChangeStreamIteratorTest.php 3 0 tests/Operation/FindAndModifyFunctionalTest.php 2 0 tests/UnifiedSpecTests/Constraint/IsBsonTypeTest.php 2 0 tests/Operation/DeleteFunctionalTest.php 1 0 tests/GridFS/BucketFunctionalTest.php 15 0 tests/FunctionsTest.php 9 0 tests/Exception/InvalidArgumentExceptionTest.php 1 0 tests/Operation/FindTest.php 3 0 tests/Operation/UpdateFunctionalTest.php 4 0 tests/UnifiedSpecTests/UnifiedSpecTest.php 10 0 src/Model/CollectionInfo.php 1 0 tests/Operation/DatabaseCommandTest.php 2 0 tests/SpecTests/DocumentsMatchConstraintTest.php 2 0 tests/SpecTests/TransactionsSpecTest.php 1 0 tests/Operation/BulkWriteTest.php 20 0 tests/GridFS/ReadableStreamFunctionalTest.php 6 0 tests/Database/DatabaseFunctionalTest.php 3 0 tests/Operation/AggregateFunctionalTest.php 1 0 src/GridFS/WritableStream.php 1 0 tests/Operation/MapReduceFunctionalTest.php 2 0 tests/Operation/DistinctFunctionalTest.php 1 0 tests/UnifiedSpecTests/EventObserver.php 3 0 tests/Collection/CrudSpecFunctionalTest.php 1 0 tests/Operation/FindFunctionalTest.php 1 0 tests/Operation/FindOneAndDeleteTest.php 2 0 src/Operation/MapReduce.php 1 0 tests/Operation/CountDocumentsTest.php 2 0 tests/Operation/ExplainFunctionalTest.php 15 0 tests/Operation/MapReduceTest.php 2 0 tests/SpecTests/ErrorExpectation.php 2 0 tests/UnifiedSpecTests/Constraint/MatchesTest.php 2 0 tests/SpecTests/Operation.php 4 0 tests/Operation/BulkWriteFunctionalTest.php 6 0 tests/SpecTests/PrimaryStepDownSpecTest.php 6 0 tests/ClientTest.php 2 0 tests/Collection/CollectionFunctionalTest.php 8 0 tests/DocumentationExamplesTest.php 3 0 tests/Operation/WatchFunctionalTest.php 1 0 ------------------------------------------------------------------------- A TOTAL OF 242 ERRORS WERE FIXED IN 88 FILES ------------------------------------------------------------------------- Time: 13.38 secs; Memory: 10MB
1 parent 55c62d3 commit 41b0bc8

File tree

90 files changed

+249
-739
lines changed

Some content is hidden

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

90 files changed

+249
-739
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"symfony/polyfill-php80": "^1.19"
1818
},
1919
"require-dev": {
20-
"squizlabs/php_codesniffer": "^3.6",
21-
"doctrine/coding-standard": "^9.0",
20+
"squizlabs/php_codesniffer": "^3.7",
21+
"doctrine/coding-standard": "^11.1",
2222
"symfony/phpunit-bridge": "^5.2",
2323
"vimeo/psalm": "^4.28"
2424
},

phpcs.xml.dist

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,13 @@
1414
<file>tests</file>
1515
<file>tools</file>
1616

17+
<!-- Target minimum supported PHP version -->
18+
<config name="php_version" value="70200"/>
19+
1720
<!-- ****************************************** -->
1821
<!-- Import rules from doctrine/coding-standard -->
1922
<!-- ****************************************** -->
2023
<rule ref="Doctrine">
21-
<!-- ********************************************** -->
22-
<!-- Exclude sniffs that require newer PHP versions -->
23-
<!-- ********************************************** -->
24-
25-
<!-- Requires PHP 7.4 -->
26-
<exclude name="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator" />
27-
28-
<!-- Requires PHP 8.0 -->
29-
<exclude name="SlevomatCodingStandard.Classes.ModernClassNameReference.ClassNameReferencedViaFunctionCall" />
30-
31-
3224
<!-- *********************************** -->
3325
<!-- Exclude sniffs that cause BC breaks -->
3426
<!-- *********************************** -->

src/ChangeStream.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ public function current()
112112
return $this->iterator->current();
113113
}
114114

115-
/**
116-
* @return CursorId
117-
*/
115+
/** @return CursorId */
118116
public function getCursorId()
119117
{
120118
return $this->iterator->getInnerIterator()->getId();

src/GridFS/WritableStream.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,7 @@ private function abort(): void
255255
$this->isClosed = true;
256256
}
257257

258-
/**
259-
* @return mixed
260-
*/
258+
/** @return mixed */
261259
private function fileCollectionInsert()
262260
{
263261
$this->file['length'] = $this->length;

src/InsertOneResult.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ class InsertOneResult
3434
/** @var boolean */
3535
private $isAcknowledged;
3636

37-
/**
38-
* @param mixed $insertedId
39-
*/
37+
/** @param mixed $insertedId */
4038
public function __construct(WriteResult $writeResult, $insertedId)
4139
{
4240
$this->writeResult = $writeResult;

src/Model/BSONIterator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ public function rewind()
128128
$this->advance();
129129
}
130130

131-
/**
132-
* @see https://php.net/iterator.valid
133-
*/
131+
/** @see https://php.net/iterator.valid */
134132
#[ReturnTypeWillChange]
135133
public function valid(): bool
136134
{

src/Model/CachingIterator.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ public function __construct(Traversable $traversable)
7070
$this->storeCurrentItem();
7171
}
7272

73-
/**
74-
* @see https://php.net/countable.count
75-
*/
73+
/** @see https://php.net/countable.count */
7674
public function count(): int
7775
{
7876
$this->exhaustIterator();
@@ -104,9 +102,7 @@ public function key()
104102
return $currentItem !== false ? $currentItem[self::FIELD_KEY] : null;
105103
}
106104

107-
/**
108-
* @see https://php.net/iterator.next
109-
*/
105+
/** @see https://php.net/iterator.next */
110106
public function next(): void
111107
{
112108
if (! $this->iteratorExhausted) {
@@ -121,9 +117,7 @@ public function next(): void
121117
next($this->items);
122118
}
123119

124-
/**
125-
* @see https://php.net/iterator.rewind
126-
*/
120+
/** @see https://php.net/iterator.rewind */
127121
public function rewind(): void
128122
{
129123
/* If the iterator has advanced, exhaust it now so that future iteration
@@ -136,9 +130,7 @@ public function rewind(): void
136130
reset($this->items);
137131
}
138132

139-
/**
140-
* @see https://php.net/iterator.valid
141-
*/
133+
/** @see https://php.net/iterator.valid */
142134
public function valid(): bool
143135
{
144136
return $this->key() !== null;

src/Model/CallbackIterator.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,19 @@ public function key()
6262
return $this->iterator->key();
6363
}
6464

65-
/**
66-
* @see https://php.net/iterator.next
67-
*/
65+
/** @see https://php.net/iterator.next */
6866
public function next(): void
6967
{
7068
$this->iterator->next();
7169
}
7270

73-
/**
74-
* @see https://php.net/iterator.rewind
75-
*/
71+
/** @see https://php.net/iterator.rewind */
7672
public function rewind(): void
7773
{
7874
$this->iterator->rewind();
7975
}
8076

81-
/**
82-
* @see https://php.net/iterator.valid
83-
*/
77+
/** @see https://php.net/iterator.valid */
8478
public function valid(): bool
8579
{
8680
return $this->iterator->valid();

src/Model/ChangeStreamIterator.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ public function key()
181181
return $this->isValid ? parent::key() : null;
182182
}
183183

184-
/**
185-
* @see https://php.net/iteratoriterator.rewind
186-
*/
184+
/** @see https://php.net/iteratoriterator.rewind */
187185
public function next(): void
188186
{
189187
/* Determine if advancing the iterator will execute a getMore command
@@ -199,6 +197,7 @@ public function next(): void
199197

200198
try {
201199
parent::next();
200+
202201
$this->onIteration(! $getMore);
203202
} finally {
204203
if ($getMore) {
@@ -207,22 +206,19 @@ public function next(): void
207206
}
208207
}
209208

210-
/**
211-
* @see https://php.net/iteratoriterator.rewind
212-
*/
209+
/** @see https://php.net/iteratoriterator.rewind */
213210
public function rewind(): void
214211
{
215212
if ($this->isRewindNop) {
216213
return;
217214
}
218215

219216
parent::rewind();
217+
220218
$this->onIteration(false);
221219
}
222220

223-
/**
224-
* @see https://php.net/iteratoriterator.valid
225-
*/
221+
/** @see https://php.net/iteratoriterator.valid */
226222
public function valid(): bool
227223
{
228224
return $this->isValid;

src/Model/CollectionInfo.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ class CollectionInfo implements ArrayAccess
3939
/** @var array */
4040
private $info;
4141

42-
/**
43-
* @param array $info Collection info
44-
*/
42+
/** @param array $info Collection info */
4543
public function __construct(array $info)
4644
{
4745
$this->info = $info;

src/Model/DatabaseInfo.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ class DatabaseInfo implements ArrayAccess
3838
/** @var array */
3939
private $info;
4040

41-
/**
42-
* @param array $info Database info
43-
*/
41+
/** @param array $info Database info */
4442
public function __construct(array $info)
4543
{
4644
$this->info = $info;

src/Model/IndexInfo.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ class IndexInfo implements ArrayAccess
4444
/** @var array */
4545
private $info;
4646

47-
/**
48-
* @param array $info Index info
49-
*/
47+
/** @param array $info Index info */
5048
public function __construct(array $info)
5149
{
5250
$this->info = $info;

src/Operation/MapReduce.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,7 @@ public function execute(Server $server)
309309
return new MapReduceResult($getIterator, $result);
310310
}
311311

312-
/**
313-
* @param string|array|object $out
314-
*/
312+
/** @param string|array|object $out */
315313
private function checkOutDeprecations($out): void
316314
{
317315
if (is_string($out)) {

src/Operation/WithTransaction.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
use function call_user_func;
1111
use function time;
1212

13-
/**
14-
* @internal
15-
*/
13+
/** @internal */
1614
class WithTransaction
1715
{
1816
/** @var callable */

tests/ClientTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ public function testConstructorDefaultUri(): void
2222
$this->assertEquals('mongodb://127.0.0.1/', (string) $client);
2323
}
2424

25-
/**
26-
* @doesNotPerformAssertions
27-
*/
25+
/** @doesNotPerformAssertions */
2826
public function testConstructorAutoEncryptionOpts(): void
2927
{
3028
$autoEncryptionOpts = [
@@ -36,9 +34,7 @@ public function testConstructorAutoEncryptionOpts(): void
3634
new Client(static::getUri(), [], ['autoEncryption' => $autoEncryptionOpts]);
3735
}
3836

39-
/**
40-
* @dataProvider provideInvalidConstructorDriverOptions
41-
*/
37+
/** @dataProvider provideInvalidConstructorDriverOptions */
4238
public function testConstructorDriverOptionTypeChecks(array $driverOptions, string $exception = InvalidArgumentException::class): void
4339
{
4440
$this->expectException($exception);

tests/Collection/CollectionFunctionalTest.php

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,15 @@
3030
*/
3131
class CollectionFunctionalTest extends FunctionalTestCase
3232
{
33-
/**
34-
* @dataProvider provideInvalidDatabaseAndCollectionNames
35-
*/
33+
/** @dataProvider provideInvalidDatabaseAndCollectionNames */
3634
public function testConstructorDatabaseNameArgument($databaseName, string $expectedExceptionClass): void
3735
{
3836
$this->expectException($expectedExceptionClass);
3937
// TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378)
4038
new Collection($this->manager, $databaseName, $this->getCollectionName());
4139
}
4240

43-
/**
44-
* @dataProvider provideInvalidDatabaseAndCollectionNames
45-
*/
41+
/** @dataProvider provideInvalidDatabaseAndCollectionNames */
4642
public function testConstructorCollectionNameArgument($collectionName, string $expectedExceptionClass): void
4743
{
4844
$this->expectException($expectedExceptionClass);
@@ -58,9 +54,7 @@ public function provideInvalidDatabaseAndCollectionNames()
5854
];
5955
}
6056

61-
/**
62-
* @dataProvider provideInvalidConstructorOptions
63-
*/
57+
/** @dataProvider provideInvalidConstructorOptions */
6458
public function testConstructorOptionTypeChecks(array $options): void
6559
{
6660
$this->expectException(InvalidArgumentException::class);
@@ -172,9 +166,7 @@ function (array $event): void {
172166
);
173167
}
174168

175-
/**
176-
* @dataProvider provideTypeMapOptionsAndExpectedDocuments
177-
*/
169+
/** @dataProvider provideTypeMapOptionsAndExpectedDocuments */
178170
public function testDistinctWithTypeMap(array $typeMap, array $expectedDocuments): void
179171
{
180172
$bulkWrite = new BulkWrite(['ordered' => true]);
@@ -264,9 +256,7 @@ public function testDrop(): void
264256
$this->assertCollectionDoesNotExist($this->getCollectionName());
265257
}
266258

267-
/**
268-
* @todo Move this to a unit test once Manager can be mocked
269-
*/
259+
/** @todo Move this to a unit test once Manager can be mocked */
270260
public function testDropIndexShouldNotAllowWildcardCharacter(): void
271261
{
272262
$this->expectException(InvalidArgumentException::class);
@@ -732,9 +722,7 @@ function ($rw) {
732722
);
733723
}
734724

735-
/**
736-
* @dataProvider collectionMethodClosures
737-
*/
725+
/** @dataProvider collectionMethodClosures */
738726
public function testMethodDoesNotInheritReadWriteConcernInTranasaction(Closure $method): void
739727
{
740728
$this->skipIfTransactionsAreNotSupported();
@@ -760,9 +748,7 @@ function (array $event): void {
760748
);
761749
}
762750

763-
/**
764-
* @dataProvider collectionWriteMethodClosures
765-
*/
751+
/** @dataProvider collectionWriteMethodClosures */
766752
public function testMethodInTransactionWithWriteConcernOption($method): void
767753
{
768754
$this->skipIfTransactionsAreNotSupported();
@@ -782,9 +768,7 @@ public function testMethodInTransactionWithWriteConcernOption($method): void
782768
}
783769
}
784770

785-
/**
786-
* @dataProvider collectionReadMethodClosures
787-
*/
771+
/** @dataProvider collectionReadMethodClosures */
788772
public function testMethodInTransactionWithReadConcernOption($method): void
789773
{
790774
$this->skipIfTransactionsAreNotSupported();

tests/Collection/CrudSpecFunctionalTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ public function setUp(): void
5252
$this->expectedCollection->drop();
5353
}
5454

55-
/**
56-
* @dataProvider provideSpecificationTests
57-
*/
55+
/** @dataProvider provideSpecificationTests */
5856
public function testSpecification(array $initialData, array $test, $minServerVersion, $maxServerVersion, $serverless): void
5957
{
6058
if (isset($minServerVersion) || isset($maxServerVersion)) {

tests/Command/ListCollectionsTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
class ListCollectionsTest extends TestCase
1010
{
11-
/**
12-
* @dataProvider provideInvalidConstructorOptions
13-
*/
11+
/** @dataProvider provideInvalidConstructorOptions */
1412
public function testConstructorOptionTypeChecks(array $options): void
1513
{
1614
$this->expectException(InvalidArgumentException::class);

tests/Command/ListDatabasesTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99
class ListDatabasesTest extends TestCase
1010
{
11-
/**
12-
* @dataProvider provideInvalidConstructorOptions
13-
*/
11+
/** @dataProvider provideInvalidConstructorOptions */
1412
public function testConstructorOptionTypeChecks(array $options): void
1513
{
1614
$this->expectException(InvalidArgumentException::class);

0 commit comments

Comments
 (0)