Completed
Push — master ( d9d1e2...b73c31 )
by Ruben
01:14
created

HasLinks   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A links() 0 10 3
A collectionLinks() 0 4 1
1
<?php
2
3
namespace Spatie\ResourceLinks;
4
5
use Closure;
6
7
/** @mixin \Illuminate\Http\Resources\Json\JsonResource */
8
trait HasLinks
9
{
10
    /**
11
     * @param string|Closure|null|array $controller
12
     * @param null $parameters
13
     *
14
     * @return \Spatie\ResourceLinks\LinkResource
15
     */
16
    public function links($controller = null, $parameters = null): LinkResource
17
    {
18
        $resource = LinkResource::create($this->resource, LinkResourceType::ITEM)->link($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, 'withCollectionLinks') && $this->withCollectionLinks === true) {
0 ignored issues
show
Bug introduced by
The property withCollectionLinks 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->withCollectionLinks();
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 collectionLinks($controller = null, $parameters = null): LinkResource
34
    {
35
        return LinkResource::create(null, LinkResourceType::COLLECTION)->link($controller, $parameters);
36
    }
37
}
38