Skip to content

Commit 040e0f4

Browse files
feat: fix method param types
1 parent 4d1c41b commit 040e0f4

File tree

7 files changed

+19
-13
lines changed

7 files changed

+19
-13
lines changed

src/Cursor/Cursor.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ public function disableTimeout(bool $flag = true)
133133
*
134134
* @see http://php.net/manual/pt_BR/class.mongodb-driver-readpreference.php
135135
*
136-
* @param int $mode preference mode that the Cursor will use
136+
* @param int|string $mode preference mode that the Cursor will use
137137
*
138138
* @see ReadPreference::class To get a glance of the constants available
139139
*
140140
* @return $this
141141
*/
142-
public function setReadPreference(int $mode)
142+
public function setReadPreference(int|string $mode): static
143143
{
144144
$this->params[1]['readPreference'] = new ReadPreference($mode);
145145

src/Cursor/SchemaCursor.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ public function disableTimeout(bool $flag = true)
154154
*
155155
* @see http://php.net/manual/pt_BR/class.mongodb-driver-readpreference.php
156156
*
157-
* @param int $mode preference mode that the Cursor will use
157+
* @param int|string $mode preference mode that the Cursor will use
158158
*
159159
* @see ReadPreference::class To get a glance of the constants available
160160
*
161161
* @return $this
162162
*/
163-
public function setReadPreference(int $mode)
163+
public function setReadPreference(int|string $mode): static
164164
{
165165
$this->params[1]['readPreference'] = new ReadPreference($mode);
166166

src/LegacyRecord.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Mongolid;
33

44
use Illuminate\Contracts\Container\BindingResolutionException;
5+
use MongoDB\BSON\Document;
56
use MongoDB\Collection;
67
use MongoDB\Driver\WriteConcern;
78
use MongoDB\Exception\BadMethodCallException;
@@ -16,6 +17,7 @@
1617
use Mongolid\Schema\DynamicSchema;
1718
use Mongolid\Schema\HasSchemaInterface;
1819
use Mongolid\Schema\Schema;
20+
use stdClass;
1921

2022
/**
2123
* This class was created to keep v2 compatibility.
@@ -380,10 +382,10 @@ public function getCollection(): Collection
380382
}
381383

382384
/**
383-
* @return array|object
385+
* @return array|stdClass|Document
384386
* @throws BindingResolutionException
385387
*/
386-
public function bsonSerialize(): object|array
388+
public function bsonSerialize(): array|stdClass|Document
387389
{
388390
return Container::make(ModelMapper::class)
389391
->map($this, array_merge($this->fillable, $this->guarded), $this->dynamic, $this->timestamps);

src/Model/AbstractModel.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Mongolid\Model;
33

44
use Illuminate\Contracts\Container\BindingResolutionException;
5+
use MongoDB\BSON\Document;
56
use MongoDB\Collection;
67
use MongoDB\Driver\WriteConcern;
78
use Mongolid\Connection\Connection;
@@ -11,6 +12,7 @@
1112
use Mongolid\Model\Exception\NoCollectionNameException;
1213
use Mongolid\Query\Builder;
1314
use Mongolid\Query\ModelMapper;
15+
use stdClass;
1416

1517
/**
1618
* The Mongolid\Model\Model base class will ensure to enable your model to
@@ -281,7 +283,7 @@ public function setWriteConcern(int $writeConcern): void
281283
/**
282284
* @throws BindingResolutionException
283285
*/
284-
public function bsonSerialize(): object|array
286+
public function bsonSerialize(): array|stdClass|Document
285287
{
286288
return Container::make(ModelMapper::class)
287289
->map($this, array_merge($this->fillable, $this->guarded), $this->dynamic, $this->timestamps);

tests/Unit/Cursor/CursorTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ public function testShouldSetReadPreferenceParameterAccordingly(): void
7676
{
7777
// Set
7878
$cursor = $this->getCursor();
79-
$mode = ReadPreference::RP_SECONDARY;
79+
$mode = ReadPreference::SECONDARY;
8080

8181
// Actions
8282
$cursor->setReadPreference($mode);
8383
$readPreferenceParameter = $this->getProtected($cursor, 'params')[1]['readPreference'];
84-
$result = $readPreferenceParameter->getMode();
84+
$result = $readPreferenceParameter->getModeString();
8585

8686
// Assertions
8787
$this->assertInstanceOf(ReadPreference::class, $readPreferenceParameter);
@@ -92,13 +92,13 @@ public function testShouldBeAbleToSetReadPreferenceAndCursorTimeoutTogether(): v
9292
{
9393
// Set
9494
$cursor = $this->getCursor();
95-
$mode = ReadPreference::RP_SECONDARY;
95+
$mode = ReadPreference::SECONDARY;
9696

9797
// Actions
9898
$cursor->setReadPreference($mode);
9999
$cursor->disableTimeout();
100100
$readPreferenceParameter = $this->getProtected($cursor, 'params')[1]['readPreference'];
101-
$result = $readPreferenceParameter->getMode();
101+
$result = $readPreferenceParameter->getModeString();
102102
$timeoutResult = $this->getProtected($cursor, 'params')[1]['noCursorTimeout'];
103103

104104
// Assertions

tests/Unit/Cursor/SchemaCursorTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ public function testShouldSetReadPreferenceParameterAccordingly()
8383
{
8484
// Arrange
8585
$cursor = $this->getCursor();
86-
$mode = ReadPreference::RP_SECONDARY;
86+
$mode = ReadPreference::SECONDARY;
8787
$cursor->setReadPreference($mode);
8888
$readPreferenceParameter = $this->getProtected($cursor, 'params')[1]['readPreference'];
8989

9090
// Assert
9191
$this->assertInstanceOf(ReadPreference::class, $readPreferenceParameter);
92-
$this->assertSame($readPreferenceParameter->getMode(), $mode);
92+
$this->assertSame($readPreferenceParameter->getModeString(), $mode);
9393
}
9494

9595
public function testShouldCountDocuments()

tests/Unit/Util/QueryBuilderTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public function testShouldPrepareQueryValue(
3030

3131
public function queryValueScenarios(): array
3232
{
33+
$objectId = new ObjectId('64e8963b1de34f08a40502e0');
34+
3335
return [
3436
'An array' => [
3537
'query' => ['age' => ['$gt' => 25]],

0 commit comments

Comments
 (0)