Completed
Push — master ( 56725d...0ac998 )
by Freek
01:35
created

HasEndpoints::collectionEndpoints()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Spatie\LaravelEndpointResources;
4
5
use Illuminate\Support\Arr;
6
7
trait HasEndpoints
8
{
9 View Code Duplication
    public function endpoints(string $controller = null, $parameters = null): EndpointResource
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
10
    {
11
        $endPointResource = new EndpointResource($this->resource, EndpointResourceType::LOCAL);
0 ignored issues
show
Bug introduced by
The property resource does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
12
13
        if ($controller !== null) {
14
            $endPointResource->addController($controller, Arr::wrap($parameters));
15
        }
16
17
        return $endPointResource;
18
    }
19
20 View Code Duplication
    public static function collectionEndpoints(string $controller = null, $parameters = null): EndpointResource
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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
    {
22
        $endPointResource = new EndpointResource(null, EndpointResourceType::GLOBAL);
23
24
        if ($controller !== null) {
25
            $endPointResource->addController($controller, Arr::wrap($parameters));
26
        }
27
28
        return $endPointResource;
29
    }
30
31
    public static function meta()
32
    {
33
        return [];
34
    }
35
36
    public static function collection($resource)
37
    {
38
        if ($meta = self::meta()) {
39
            return parent::collection($resource)->additional([
40
                'meta' => $meta,
41
            ]);
42
        }
43
44
        return parent::collection($resource);
45
    }
46
47
    public static function make(...$parameters)
48
    {
49
        if ($meta = self::meta()) {
50
            return parent::make(...$parameters)->additional([
51
                'meta' => $meta,
52
            ]);
53
        }
54
55
        return parent::make(...$parameters);
56
    }
57
}
58