Completed
Push — master ( 1885f1...3cadef )
by wen
02:55
created

Link   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 33
rs 10
c 2
b 0
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUrl() 0 9 2
A setUrl() 0 6 1
A toArray() 0 9 1
1
<?php
2
3
4
namespace Sco\Admin\View\Columns;
5
6
class Link extends Column
7
{
8
    protected $template = '<router-link to="value.url">{{value.title}}</router-link>';
9
10
    private $url;
11
12
    public function getUrl()
13
    {
14
        if ($this->url) {
15
            return $this->url;
16
        }
17
        $model = app('admin.components')->get(get_class($this->getModel()))->getName();
18
        $id = $this->getModel()->getKey();
19
        return route('admin.model.edit', [$model, $id]);
20
    }
21
22
    public function setUrl($value)
23
    {
24
        $this->url = $value;
25
26
        return $this;
27
    }
28
29
    public function toArray()
30
    {
31
        return parent::toArray() + [
32
                'value' => [
33
                    'url'   => $this->getUrl(),
34
                    'title' => $this->getModelValue(),
35
                ],
36
            ];
37
    }
38
}
39