Completed
Push — master ( ab1e55...3d4e36 )
by Freek
09:25 queued 07:31
created

helpers.php ➔ fractal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
use Spatie\Fractalistic\Fractal;
4
use League\Fractal\Serializer\SerializerAbstract;
5
6
if (! function_exists('fractal')) {
7
    /**
8
     * @param null|mixed $data
9
     * @param null|callable|\League\Fractal\TransformerAbstract $transformer
10
     * @param null|\League\Fractal\Serializer\SerializerAbstract $serializer
11
     *
12
     * @return \Spatie\Fractalistic\Fractal
13
     */
14
    function fractal($data = null, $transformer = null, $serializer = null)
0 ignored issues
show
Best Practice introduced by
The function fractal() has been defined more than once; this definition is ignored, only the first definition in helpers.php (L13-18) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
15
    {
16
        $fractal = Fractal::create($data, $transformer, $serializer);
17
18
        $serializer = config('laravel-fractal.default_serializer');
19
20
        if (! empty($serializer)) {
21
            if ($serializer instanceof SerializerAbstract) {
22
                $fractal->serializeWith($serializer);
23
            } else {
24
                $fractal->serializeWith(new $serializer());
25
            }
26
        }
27
28
        return $fractal;
29
    }
30
}
31