Skip to content

Commit 4b7e157

Browse files
committed
#1930 update parameter type
1 parent 84d1283 commit 4b7e157

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

src/Relations/EmbedsMany.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Illuminate\Pagination\LengthAwarePaginator;
1010
use Illuminate\Pagination\Paginator;
1111
use MongoDB\BSON\ObjectID;
12+
use MongoDB\Driver\Exception\LogicException;
13+
use MongoDB\Laravel\Eloquent\Model as MongoDBModel;
1214

1315
use function array_key_exists;
1416
use function array_values;
@@ -195,10 +197,15 @@ public function destroy($ids = [])
195197
/**
196198
* Delete all embedded models.
197199
*
198-
* @return int
200+
* @param null $id
201+
*
202+
* @throws LogicException|\Throwable
203+
*
204+
* @note The $id is not used to delete embedded models.
199205
*/
200-
public function delete()
206+
public function delete($id = null): int
201207
{
208+
throw_if($id !== null, new LogicException('The id parameter should not be used.'));
202209
// Overwrite the local key with an empty array.
203210
$result = $this->query->update([$this->localKey => []]);
204211

@@ -224,9 +231,9 @@ public function detach($ids = [])
224231
/**
225232
* Save alias.
226233
*
227-
* @return Model
234+
* @return MongoDBModel
228235
*/
229-
public function attach(Model $model)
236+
public function attach(MongoDBModel $model)
230237
{
231238
return $this->save($model);
232239
}

src/Relations/EmbedsOne.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
use Illuminate\Database\Eloquent\Model;
88
use MongoDB\BSON\ObjectID;
9+
use MongoDB\Driver\Exception\LogicException;
10+
use Throwable;
11+
12+
use function throw_if;
913

1014
class EmbedsOne extends EmbedsOneOrMany
1115
{
@@ -133,10 +137,16 @@ public function dissociate()
133137
/**
134138
* Delete all embedded models.
135139
*
136-
* @return int
140+
* @param ?string $id
141+
*
142+
* @throws LogicException|Throwable
143+
*
144+
* @note The $id is not used to delete embedded models.
137145
*/
138-
public function delete()
146+
public function delete($id = null): int
139147
{
148+
throw_if($id !== null, new LogicException('The id parameter should not be used.'));
149+
140150
return $this->performDelete();
141151
}
142152

src/Relations/EmbedsOneOrMany.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
use Illuminate\Database\Eloquent\Collection;
99
use Illuminate\Database\Eloquent\Model as EloquentModel;
1010
use Illuminate\Database\Eloquent\Relations\Relation;
11+
use Illuminate\Database\Query\Expression;
12+
use MongoDB\Driver\Exception\LogicException;
1113
use MongoDB\Laravel\Eloquent\Model;
14+
use Throwable;
1215

1316
use function array_merge;
1417
use function count;
1518
use function is_array;
19+
use function throw_if;
1620

1721
abstract class EmbedsOneOrMany extends Relation
1822
{
@@ -99,10 +103,16 @@ public function get($columns = ['*'])
99103
/**
100104
* Get the number of embedded models.
101105
*
102-
* @return int
106+
* @param Expression|string $columns
107+
*
108+
* @throws LogicException|Throwable
109+
*
110+
* @note The $column parameter is not used to count embedded models.
103111
*/
104-
public function count()
112+
public function count($columns = '*'): int
105113
{
114+
throw_if($columns !== '*', new LogicException('The columns parameter should not be used.'));
115+
106116
return count($this->getEmbedded());
107117
}
108118

@@ -392,8 +402,8 @@ public function getQualifiedForeignKeyName()
392402
/**
393403
* Get the name of the "where in" method for eager loading.
394404
*
395-
* @param \Illuminate\Database\Eloquent\Model $model
396-
* @param string $key
405+
* @param EloquentModel $model
406+
* @param string $key
397407
*
398408
* @return string
399409
*/

0 commit comments

Comments
 (0)