Skip to content

Commit 6fe2c02

Browse files
authored
Use Stringable interface explicitly (#1762)
1 parent 45c88ac commit 6fe2c02

File tree

7 files changed

+18
-10
lines changed

7 files changed

+18
-10
lines changed

rector.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector;
88
use Rector\Php70\Rector\StmtsAwareInterface\IfIssetToCoalescingRector;
99
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
10+
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
11+
use Rector\Php80\Rector\Class_\StringableForToStringRector;
1012
use Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector;
1113
use Rector\Renaming\Rector\Cast\RenameCastRector;
1214
use Rector\Renaming\ValueObject\RenameCast;
@@ -18,11 +20,8 @@
1820
__DIR__ . '/tests',
1921
__DIR__ . '/tools',
2022
])
21-
->withPhpSets(php74: true)
23+
->withPhpSets(php80: true)
2224
->withComposerBased(phpunit: true)
23-
->withRules([
24-
ChangeSwitchToMatchRector::class,
25-
])
2625
// All classes are public API by default, unless marked with @internal.
2726
->withConfiguredRule(RemoveAnnotationRector::class, ['api'])
2827
// Fix PHP 8.5 deprecations
@@ -42,6 +41,10 @@
4241
ChangeSwitchToMatchRector::class => [
4342
__DIR__ . '/tests/SpecTests/Operation.php',
4443
],
44+
ClassPropertyAssignToConstructorPromotionRector::class,
45+
StringableForToStringRector::class => [
46+
__DIR__ . '/src/Model/IndexInput.php',
47+
],
4548
])
4649
// phpcs:enable
4750
->withImportNames(importNames: false, removeUnusedImports: true);

src/Client.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,14 @@
4747
use MongoDB\Operation\ListDatabases;
4848
use MongoDB\Operation\Watch;
4949
use stdClass;
50+
use Stringable;
5051
use Throwable;
5152

5253
use function array_diff_key;
5354
use function is_array;
5455
use function is_string;
5556

56-
class Client
57+
class Client implements Stringable
5758
{
5859
public const DEFAULT_URI = 'mongodb://127.0.0.1/';
5960

src/Collection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
use MongoDB\Operation\UpdateSearchIndex;
7070
use MongoDB\Operation\Watch;
7171
use stdClass;
72+
use Stringable;
7273

7374
use function array_diff_key;
7475
use function array_intersect_key;
@@ -78,7 +79,7 @@
7879
use function is_bool;
7980
use function strlen;
8081

81-
class Collection
82+
class Collection implements Stringable
8283
{
8384
private const DEFAULT_TYPE_MAP = [
8485
'array' => BSONArray::class,

src/Database.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@
5151
use MongoDB\Operation\RenameCollection;
5252
use MongoDB\Operation\Watch;
5353
use stdClass;
54+
use Stringable;
5455
use Throwable;
5556

5657
use function is_array;
5758
use function is_bool;
5859
use function strlen;
5960

60-
class Database
61+
class Database implements Stringable
6162
{
6263
private const DEFAULT_TYPE_MAP = [
6364
'array' => BSONArray::class,

src/Model/IndexInfo.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use ArrayAccess;
2121
use MongoDB\Exception\BadMethodCallException;
22+
use Stringable;
2223

2324
use function array_key_exists;
2425
use function array_search;
@@ -38,7 +39,7 @@
3839
* @see https://mongodb.com/docs/manual/reference/method/db.collection.createIndex/
3940
* @template-implements ArrayAccess<string, mixed>
4041
*/
41-
class IndexInfo implements ArrayAccess
42+
class IndexInfo implements ArrayAccess, Stringable
4243
{
4344
/** @param array $info Index info */
4445
public function __construct(private array $info)

src/Model/IndexInput.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use MongoDB\BSON\Serializable;
2121
use MongoDB\Exception\InvalidArgumentException;
2222
use stdClass;
23+
use Stringable;
2324

2425
use function is_float;
2526
use function is_int;
@@ -38,7 +39,7 @@
3839
* @see https://github.com/mongodb/specifications/blob/master/source/enumerate-indexes.md
3940
* @see https://mongodb.com/docs/manual/reference/method/db.collection.createIndex/
4041
*/
41-
final class IndexInput implements Serializable
42+
final class IndexInput implements Serializable, Stringable
4243
{
4344
/**
4445
* @param array $index Index specification

tests/Model/BSONIteratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class BSONIteratorTest extends TestCase
1919
#[DataProvider('provideTypeMapOptionsAndExpectedDocuments')]
2020
public function testValidValues(?array $typeMap, array $expectedDocuments): void
2121
{
22-
$binaryString = implode(array_map(
22+
$binaryString = implode('', array_map(
2323
fn ($input) => (string) Document::fromPHP($input),
2424
[
2525
['_id' => 1, 'x' => ['foo' => 'bar']],

0 commit comments

Comments
 (0)