1 | <?php |
||||||||
2 | |||||||||
3 | namespace VGirol\JsonApi\Resources; |
||||||||
4 | |||||||||
5 | use Illuminate\Database\Eloquent\Model; |
||||||||
6 | use Illuminate\Http\Request; |
||||||||
7 | use VGirol\JsonApiConstant\Members; |
||||||||
8 | |||||||||
9 | trait IsRelationship |
||||||||
10 | { |
||||||||
11 | /** |
||||||||
12 | * Transform the resource into an array used as relationship. |
||||||||
13 | * |
||||||||
14 | * @param Request $request |
||||||||
15 | * @param Model $model Parent model instance |
||||||||
16 | * @param string $relationshipName |
||||||||
17 | * |
||||||||
18 | * @return array |
||||||||
19 | */ |
||||||||
20 | public function asRelationship($request, $model, string $relationshipName): array |
||||||||
21 | { |
||||||||
22 | $data = [(self::$wrap ?? Members::DATA) => $this->toArray($request)]; |
||||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||||
23 | |||||||||
24 | $this->setRelationshipMeta($request, $model); |
||||||||
25 | $this->setRelationshipLinks($request, $model, $relationshipName); |
||||||||
26 | |||||||||
27 | return array_merge_recursive($data, $this->additional); |
||||||||
28 | } |
||||||||
29 | |||||||||
30 | /** |
||||||||
31 | * Could be overloaded |
||||||||
32 | * |
||||||||
33 | * @param Request $request |
||||||||
34 | * @param Model $model Parent model instance |
||||||||
35 | * |
||||||||
36 | * @return void |
||||||||
37 | */ |
||||||||
38 | protected function setRelationshipMeta($request, $model) |
||||||||
0 ignored issues
–
show
The parameter
$model is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$request is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||
39 | { |
||||||||
40 | // $this->addRelationshipMeta('key', 'value'); |
||||||||
41 | } |
||||||||
42 | |||||||||
43 | /** |
||||||||
44 | * Could be overloaded |
||||||||
45 | * |
||||||||
46 | * @param Request $request |
||||||||
47 | * @param Model $model Parent model instance |
||||||||
48 | * @param string $relationshipName |
||||||||
49 | * |
||||||||
50 | * @return void |
||||||||
51 | */ |
||||||||
52 | protected function setRelationshipLinks($request, $model, string $relationshipName) |
||||||||
0 ignored issues
–
show
The parameter
$request is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||||
53 | { |
||||||||
54 | $this->addRelationshipLink(Members::LINK_SELF, $this->getRelationshipSelfLink($model, $relationshipName)); |
||||||||
0 ignored issues
–
show
It seems like
getRelationshipSelfLink() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() It seems like
addRelationshipLink() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
55 | $this->addRelationshipLink(Members::LINK_RELATED, $this->getRelationshipRelatedLink($model, $relationshipName)); |
||||||||
0 ignored issues
–
show
It seems like
getRelationshipRelatedLink() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||||
56 | } |
||||||||
57 | } |
||||||||
58 |