Issues (115)

src/Resources/IsRelationship.php (7 issues)

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
It seems like toArray() 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 ignore-call  annotation

22
        $data = [(self::$wrap ?? Members::DATA) => $this->/** @scrutinizer ignore-call */ toArray($request)];
Loading history...
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 ignore-unused  annotation

38
    protected function setRelationshipMeta($request, /** @scrutinizer ignore-unused */ $model)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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 ignore-unused  annotation

38
    protected function setRelationshipMeta(/** @scrutinizer ignore-unused */ $request, $model)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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 ignore-unused  annotation

52
    protected function setRelationshipLinks(/** @scrutinizer ignore-unused */ $request, $model, string $relationshipName)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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 ignore-call  annotation

54
        $this->addRelationshipLink(Members::LINK_SELF, $this->/** @scrutinizer ignore-call */ getRelationshipSelfLink($model, $relationshipName));
Loading history...
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 ignore-call  annotation

54
        $this->/** @scrutinizer ignore-call */ 
55
               addRelationshipLink(Members::LINK_SELF, $this->getRelationshipSelfLink($model, $relationshipName));
Loading history...
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 ignore-call  annotation

55
        $this->addRelationshipLink(Members::LINK_RELATED, $this->/** @scrutinizer ignore-call */ getRelationshipRelatedLink($model, $relationshipName));
Loading history...
56
    }
57
}
58