Skip to content

Commit 6f1d624

Browse files
committed
Apply automated phpcs fixes for PHP 8.1
1 parent 8fdd646 commit 6f1d624

File tree

76 files changed

+222
-393
lines changed

Some content is hidden

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

76 files changed

+222
-393
lines changed

benchmark/src/Fixtures/PassThruCodec.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,17 @@ final class PassThruCodec implements DocumentCodec
1313
use DecodeIfSupported;
1414
use EncodeIfSupported;
1515

16-
/** @param mixed $value */
17-
public function canDecode($value): bool
16+
public function canDecode(mixed $value): bool
1817
{
1918
return $value instanceof Document;
2019
}
2120

22-
/** @param mixed $value */
23-
public function canEncode($value): bool
21+
public function canEncode(mixed $value): bool
2422
{
2523
return $value instanceof Document;
2624
}
2725

28-
/** @param mixed $value */
29-
public function decode($value): Document
26+
public function decode(mixed $value): Document
3027
{
3128
if (! $value instanceof Document) {
3229
throw UnsupportedValueException::invalidDecodableValue($value);
@@ -35,8 +32,7 @@ public function decode($value): Document
3532
return $value;
3633
}
3734

38-
/** @param mixed $value */
39-
public function encode($value): Document
35+
public function encode(mixed $value): Document
4036
{
4137
if (! $value instanceof Document) {
4238
throw UnsupportedValueException::invalidEncodableValue($value);

benchmark/src/Fixtures/ToObjectCodec.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,17 @@ final class ToObjectCodec implements DocumentCodec
1515
use DecodeIfSupported;
1616
use EncodeIfSupported;
1717

18-
/** @param mixed $value */
19-
public function canDecode($value): bool
18+
public function canDecode(mixed $value): bool
2019
{
2120
return $value instanceof Document;
2221
}
2322

24-
/** @param mixed $value */
25-
public function canEncode($value): bool
23+
public function canEncode(mixed $value): bool
2624
{
2725
return is_object($value);
2826
}
2927

30-
/** @param mixed $value */
31-
public function decode($value): object
28+
public function decode(mixed $value): object
3229
{
3330
if (! $value instanceof Document) {
3431
throw UnsupportedValueException::invalidDecodableValue($value);
@@ -37,8 +34,7 @@ public function decode($value): object
3734
return $value->toPHP(['root' => 'stdClass', 'array' => 'array', 'document' => 'stdClass']);
3835
}
3936

40-
/** @param mixed $value */
41-
public function encode($value): Document
37+
public function encode(mixed $value): Document
4238
{
4339
if (! is_object($value)) {
4440
throw UnsupportedValueException::invalidEncodableValue($value);

benchmark/src/ReadLargeDocumentBench.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ public function benchAccessLastField(array $params): void
129129
}
130130
}
131131

132-
/** @param array|object $document */
133-
private function accessId($document, string $accessor): void
132+
private function accessId(array|object $document, string $accessor): void
134133
{
135134
switch ($accessor) {
136135
case 'array':
@@ -153,8 +152,7 @@ private function accessId($document, string $accessor): void
153152
}
154153
}
155154

156-
/** @param array|object $document */
157-
private function accessLastField($document, string $accessor): void
155+
private function accessLastField(array|object $document, string $accessor): void
158156
{
159157
switch ($accessor) {
160158
case 'array':
@@ -178,8 +176,7 @@ private function accessLastField($document, string $accessor): void
178176
}
179177
}
180178

181-
/** @param array|object $document */
182-
private function accessFirstField($document, string $accessor): void
179+
private function accessFirstField(array|object $document, string $accessor): void
183180
{
184181
switch ($accessor) {
185182
case 'array':

benchmark/src/ReadMultipleDocumentsBench.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ public function benchAccessNestedItem(array $params): void
116116
}
117117
}
118118

119-
/** @param array|object $document */
120-
private function accessId($document, string $accessor): void
119+
private function accessId(array|object $document, string $accessor): void
121120
{
122121
switch ($accessor) {
123122
case 'array':
@@ -140,8 +139,7 @@ private function accessId($document, string $accessor): void
140139
}
141140
}
142141

143-
/** @param array|object $document */
144-
private function accessNestedItem($document, string $accessor): void
142+
private function accessNestedItem(array|object $document, string $accessor): void
145143
{
146144
switch ($accessor) {
147145
case 'array':

examples/command_logger.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use MongoDB\Driver\Monitoring\CommandSucceededEvent;
1212

1313
use function assert;
14-
use function get_class;
1514
use function getenv;
1615
use function is_object;
1716
use function printf;
@@ -46,7 +45,7 @@ public function commandFailed(CommandFailedEvent $event): void
4645
printf("reply: %s\n", toJson($event->getReply()));
4746

4847
$exception = $event->getError();
49-
printf("exception: %s\n", get_class($exception));
48+
printf("exception: %s\n", $exception::class);
5049
printf("exception.code: %d\n", $exception->getCode());
5150
printf("exception.message: %s\n", $exception->getMessage());
5251
echo "\n";

examples/sdam_logger.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616
use MongoDB\Driver\Monitoring\TopologyClosedEvent;
1717
use MongoDB\Driver\Monitoring\TopologyOpeningEvent;
1818

19-
use function get_class;
2019
use function getenv;
2120
use function printf;
2221

2322
require __DIR__ . '/../vendor/autoload.php';
2423

25-
/** @param array|object $document */
26-
function toJSON($document): string
24+
function toJSON(array|object $document): string
2725
{
2826
return Document::fromPHP($document)->toRelaxedExtendedJSON();
2927
}
@@ -67,7 +65,7 @@ public function serverHeartbeatFailed(ServerHeartbeatFailedEvent $event): void
6765

6866
$error = $event->getError();
6967

70-
printf("error: %s(%d): %s\n", get_class($error), $error->getCode(), $error->getMessage());
68+
printf("error: %s(%d): %s\n", $error::class, $error->getCode(), $error->getMessage());
7169
echo "\n";
7270
}
7371

phpcs.xml.dist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<file>rector.php</file>
1818

1919
<!-- Target minimum supported PHP version -->
20-
<config name="php_version" value="70400"/>
20+
<config name="php_version" value="80100"/>
2121

2222
<!-- ****************************************** -->
2323
<!-- Import rules from doctrine/coding-standard -->
@@ -40,6 +40,8 @@
4040
<!-- **************************************** -->
4141
<exclude name="Generic.Formatting.MultipleStatementAlignment" />
4242
<exclude name="Squiz.Commenting.FunctionComment.ThrowsNoFullStop" />
43+
<exclude name="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat.DisallowedShortNullable" />
44+
<exclude name="SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion" />
4345

4446
<!-- Keep long typehints (for now) -->
4547
<exclude name="PSR12.Keywords.ShortFormTypeKeywords" />

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ private static function getVersion(): string
397397
if (self::$version === null) {
398398
try {
399399
self::$version = InstalledVersions::getPrettyVersion('mongodb/mongodb') ?? 'unknown';
400-
} catch (Throwable $t) {
400+
} catch (Throwable) {
401401
self::$version = 'error';
402402
}
403403
}

src/Codec/DecodeIfSupported.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,22 @@
2525
*/
2626
trait DecodeIfSupported
2727
{
28-
/**
29-
* @param mixed $value
30-
* @psalm-assert-if-true BSONType $value
31-
*/
32-
abstract public function canDecode($value): bool;
28+
/** @psalm-assert-if-true BSONType $value */
29+
abstract public function canDecode(mixed $value): bool;
3330

3431
/**
35-
* @param mixed $value
3632
* @psalm-param BSONType $value
3733
* @return mixed
3834
* @psalm-return NativeType
3935
* @throws UnsupportedValueException if the decoder does not support the value
4036
*/
41-
abstract public function decode($value);
37+
abstract public function decode(mixed $value);
4238

4339
/**
44-
* @param mixed $value
4540
* @return mixed
4641
* @psalm-return ($value is BSONType ? NativeType : $value)
4742
*/
48-
public function decodeIfSupported($value)
43+
public function decodeIfSupported(mixed $value)
4944
{
5045
return $this->canDecode($value) ? $this->decode($value) : $value;
5146
}

src/Codec/Decoder.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,29 @@ interface Decoder
2828
/**
2929
* Checks if the decoder supports a given value.
3030
*
31-
* @param mixed $value
3231
* @psalm-assert-if-true BSONType $value
3332
*/
34-
public function canDecode($value): bool;
33+
public function canDecode(mixed $value): bool;
3534

3635
/**
3736
* Decodes a given value. If the decoder does not support the value, it
3837
* should throw an exception.
3938
*
40-
* @param mixed $value
4139
* @psalm-param BSONType $value
4240
* @return mixed
4341
* @psalm-return NativeType
4442
* @throws UnsupportedValueException if the decoder does not support the value
4543
*/
46-
public function decode($value);
44+
public function decode(mixed $value);
4745

4846
/**
4947
* Decodes a given value if supported, otherwise returns the value as-is.
5048
*
5149
* The DecodeIfSupported trait provides a default implementation of this
5250
* method.
5351
*
54-
* @param mixed $value
5552
* @return mixed
5653
* @psalm-return ($value is BSONType ? NativeType : $value)
5754
*/
58-
public function decodeIfSupported($value);
55+
public function decodeIfSupported(mixed $value);
5956
}

src/Codec/DocumentCodec.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,15 @@
3030
interface DocumentCodec extends Codec
3131
{
3232
/**
33-
* @param mixed $value
3433
* @psalm-param Document $value
3534
* @psalm-return ObjectType
3635
* @throws UnsupportedValueException if the decoder does not support the value
3736
*/
38-
public function decode($value): object;
37+
public function decode(mixed $value): object;
3938

4039
/**
41-
* @param mixed $value
4240
* @psalm-param ObjectType $value
4341
* @throws UnsupportedValueException if the encoder does not support the value
4442
*/
45-
public function encode($value): Document;
43+
public function encode(mixed $value): Document;
4644
}

src/Codec/EncodeIfSupported.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,22 @@
2525
*/
2626
trait EncodeIfSupported
2727
{
28-
/**
29-
* @param mixed $value
30-
* @psalm-assert-if-true NativeType $value
31-
*/
32-
abstract public function canEncode($value): bool;
28+
/** @psalm-assert-if-true NativeType $value */
29+
abstract public function canEncode(mixed $value): bool;
3330

3431
/**
35-
* @param mixed $value
3632
* @psalm-param NativeType $value
3733
* @return mixed
3834
* @psalm-return BSONType
3935
* @throws UnsupportedValueException if the encoder does not support the value
4036
*/
41-
abstract public function encode($value);
37+
abstract public function encode(mixed $value);
4238

4339
/**
44-
* @param mixed $value
4540
* @return mixed
4641
* @psalm-return ($value is NativeType ? BSONType : $value)
4742
*/
48-
public function encodeIfSupported($value)
43+
public function encodeIfSupported(mixed $value)
4944
{
5045
return $this->canEncode($value) ? $this->encode($value) : $value;
5146
}

src/Codec/Encoder.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,29 @@ interface Encoder
2828
/**
2929
* Checks if the encoder supports a given value.
3030
*
31-
* @param mixed $value
3231
* @psalm-assert-if-true NativeType $value
3332
*/
34-
public function canEncode($value): bool;
33+
public function canEncode(mixed $value): bool;
3534

3635
/**
3736
* Encodes a given value. If the encoder does not support the value, it
3837
* should throw an exception.
3938
*
40-
* @param mixed $value
4139
* @psalm-param NativeType $value
4240
* @return mixed
4341
* @psalm-return BSONType
4442
* @throws UnsupportedValueException if the encoder does not support the value
4543
*/
46-
public function encode($value);
44+
public function encode(mixed $value);
4745

4846
/**
4947
* Encodes a given value if supported, otherwise returns the value as-is.
5048
*
5149
* The EncodeIfSupported trait provides a default implementation of this
5250
* method.
5351
*
54-
* @param mixed $value
5552
* @return mixed
5653
* @psalm-return ($value is NativeType ? BSONType : $value)
5754
*/
58-
public function encodeIfSupported($value);
55+
public function encodeIfSupported(mixed $value);
5956
}

0 commit comments

Comments
 (0)