Completed
Push — master ( 8a8686...f224a8 )
by Ruben
01:10
created

HasEndpoints::collection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Spatie\LaravelResourceEndpoints;
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\LaravelResourceEndpoints\EndpointResource
15
     */
16
    public function endpoints($controller = null, $parameters = null): EndpointResource
17
    {
18
        return EndpointResource::create($this->resource, EndpointResourceType::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
21
    /**
22
     * @param string|Closure|null|array $controller
23
     * @param null $parameters
24
     *
25
     * @return \Spatie\LaravelResourceEndpoints\EndpointResource
26
     */
27
    public static function collectionEndpoints($controller = null, $parameters = null): EndpointResource
28
    {
29
        return EndpointResource::create(null, EndpointResourceType::COLLECTION)->endpoint($controller, $parameters);
30
    }
31
}
32