Test Setup Failed
Push — v2 ( 74186a...c94b75 )
by Alexander
06:56
created

OverridesFractal::callIncludeMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Flugg\Responder\Transformers\Concerns;
4
5
use League\Fractal\Scope;
6
7
/**
8
 * A trait to be used by a transformer to override Fractal's transformer methods.
9
 *
10
 * @package flugger/laravel-responder
11
 * @author  Alexander Tømmerås <[email protected]>
12
 * @license The MIT License
13
 */
14
trait OverridesFractal
15
{
16
    /**
17
     * Overrides Fractal's getter for available includes.
18
     *
19
     * @return array
20
     */
21
    public function getAvailableIncludes()
22
    {
23
        return $this->availableIncludes;
24
    }
25
26
    /**
27
     * Overrides Fractal's getter for default includes.
28
     *
29
     * @return array
30
     */
31
    public function getDefaultIncludes()
32
    {
33
        return array_keys($this->with);
34
    }
35
36
    /**
37
     * Overrides Fractal's method for including a relation.
38
     *
39
     * @param  \League\Fractal\Scope $scope
40
     * @param  string                $relation
41
     * @param  mixed                 $data
42
     * @return \League\Fractal\Resource\ResourceInterface|false
43
     */
44
    protected function callIncludeMethod(Scope $scope, $relation, $data)
45
    {
46
        $parameters = $this->getScopedParameters($scope, $relation);
0 ignored issues
show
Bug introduced by
It seems like getScopedParameters() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
47
        $resource = $this->makeResource($relation, $data, $parameters);
0 ignored issues
show
Bug introduced by
It seems like makeResource() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
48
49
        return $resource;
50
    }
51
}