Completed
Push — master ( b01d16...d9d1e2 )
by Ruben
03:30
created

HasEndpoints::collectionEndpoints()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Spatie\ResourceLinks;
4
5
use Closure;
6
7
/** @mixin \Illuminate\Http\Resources\Json\JsonResource */
8
trait HasEndpoints
9
{
10
    /**
11
     * @param string|Closure|null|array $controller
12
     * @param null $parameters
13
     *
14
     * @return \Spatie\ResourceLinks\LinkResource
15
     */
16
    public function endpoints($controller = null, $parameters = null): LinkResource
17
    {
18
        $resource = LinkResource::create($this->resource, LinkResourceType::ITEM)->endpoint($controller, $parameters);
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...
19
20
        if (property_exists($this, 'mergeCollectionEndpoints') && $this->mergeCollectionEndpoints === true) {
0 ignored issues
show
Bug introduced by
The property mergeCollectionEndpoints 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...
21
            $resource->mergeCollectionEndpoints();
22
        }
23
24
        return $resource;
25
    }
26
27
    /**
28
     * @param string|Closure|null|array $controller
29
     * @param null $parameters
30
     *
31
     * @return \Spatie\ResourceLinks\LinkResource
32
     */
33
    public static function collectionEndpoints($controller = null, $parameters = null): LinkResource
34
    {
35
        return LinkResource::create(null, LinkResourceType::COLLECTION)->endpoint($controller, $parameters);
36
    }
37
}
38