Transformer::getEagerLoads()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 5
Ratio 38.46 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 5
loc 13
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
1
<?php
2
3
namespace NavJobs\Transmit;
4
5
use League\Fractal\Resource\Item;
6
use League\Fractal\Resource\NullResource;
7
use League\Fractal\TransformerAbstract;
8
9
abstract class Transformer extends TransformerAbstract
10
{
11
    /**
12
     * Returns the includes that are available for eager loading.
13
     *
14
     * @param array|string $requestedIncludes Array of csv string
15
     *
16
     * @return $this
17
     */
18
    public function getEagerLoads($requestedIncludes)
19
    {
20 View Code Duplication
        if (is_string($requestedIncludes)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
            $requestedIncludes = array_map(function ($value) {
22
                return trim($value);
23
            }, explode(',', $requestedIncludes));
24
        }
25
26
        $availableRequestedIncludes = array_intersect($this->getAvailableIncludes(), $requestedIncludes);
27
        $defaultIncludes = $this->getDefaultIncludes();
28
29
        return array_merge($availableRequestedIncludes, $defaultIncludes);
30
    }
31
32
    /**
33
     * Create a new item resource object.
34
     *
35
     * @param mixed                        $data
36
     * @param TransformerAbstract|callable $transformer
37
     * @param string                       $resourceKey
38
     *
39
     * @return Item
40
     */
41
    protected function item($data, $transformer, $resourceKey = null)
42
    {
43
        if (!$data) {
44
            return new NullResource();
45
        }
46
47
        return new Item($data, $transformer, $resourceKey);
48
    }
49
}
50