8000 [Refactor] Amend return type for existing relationships method · AxonDivisionDev/laravel-json-api@c2dcb65 · GitHub
[go: up one dir, main page]

Skip to content

Commit c2dcb65

Browse files
committed
[Refactor] Amend return type for existing relationships method
1 parent 0239e95 commit c2dcb65

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

docs/basics/validators.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ Content-Type: application/vnd.api+json
4141
4242
{
4343
"errors": [
44-
[
44+
{
4545
"title": "Non-Compliant JSON API Document",
4646
"status": "400",
4747
"detail": "The member id must be a string.",
4848
"source": {
4949
"pointer": "/data/id"
5050
}
51-
]
51+
}
5252
]
5353
}
5454
```
@@ -273,9 +273,9 @@ class Validators extends AbstractValidators
273273

274274
/**
275275
* @param \App\Post $record
276-
* @return \Illuminate\Support\Collection
276+
* @return iterable
277277
*/
278-
protected function existingRelationships($record): Collection
278+
protected function existingRelationships($record): iterable
279279
{
280280
return [
281281
'author' => [

src/Validation/AbstractValidators.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,12 @@ protected function updateData($record, array $document): array
330330
$resource['attributes'] = $this->extractAttributes(
331331
$record,
332332
$resource['attributes'] ?? []
333-
)->all();
333+
);
334334

335335
$resource['relationships'] = $this->extractRelationships(
336336
$record,
337337
$resource['relationships'] ?? []
338-
)->all();
338+
);
339339
}
340340

341341
return $resource;
@@ -363,34 +363,34 @@ protected function mustValidateExisting($record, array $document): bool
363363
*
364364
* @param $record
365365
* @param array $new
366-
* @return Collection
366+
* @return array
367367
*/
368-
protected function extractAttributes($record, array $new): Collection
368+
protected function extractAttributes($record, array $new): array
369369
{
370-
return $this->existingAttributes($record)->merge($new);
370+
return collect($this->existingAttributes($record))->merge($new)->all();
371371
}
372372

373373
/**
374374
* Get any existing attributes for the provided record.
375375
*
376376
* @param $record
377-
* @return Collection
377+
* @return iterable
378378
*/
379-
protected function existingAttributes($record): Collection
379+
protected function existingAttributes($record): iterable
380380
{
381-
return collect($this->container->getSchema($record)->getAttributes($record));
381+
return $this->container->getSchema($record)->getAttributes($record);
382382
}
383383

384384
/**
385385
* Extract relationships for a resource update.
386386
*
387387
* @param $record
388388
* @param array $new
389-
* @return Collection
389+
* @return array
390390
*/
391-
protected function extractRelationships($record, array $new): Collection
391+
protected function extractRelationships($record, array $new): array
392392
{
393-
return $this->existingRelationships($record)->merge($new);
393+
return collect($this->existingRelationships($record))->merge($new)->all();
394394
}
395395

396396
/**
@@ -401,11 +401,11 @@ protected function extractRelationships($record, array $new): Collection
401401
* to add existing relationship data.
402402
*
403403
* @param $record
404-
* @return Collection
404+
* @return iterable
405405
*/
406-
protected function existingRelationships($record): Collection
406+
protected function existingRelationships($record): iterable
407407
{
408-
return collect();
408+
return [];
409409
}
410410

411411
/**

0 commit comments

Comments
 (0)
0