Link   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 121
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 3

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A setUrl() 0 6 1
A make() 0 4 1
A toHtml() 0 4 1
A getConfig() 0 4 1
A renderAttributes() 0 17 4
1
<?php namespace Arcanesoft\Core\Helpers\UI;
2
3
/**
4
 * Class     Link
5
 *
6
 * @package  Arcanesoft\Core\Helpers\UI
7
 * @author   ARCANEDEV <[email protected]>
8
 */
9
class Link extends AbstractClickable
10
{
11
    /* -----------------------------------------------------------------
12
     |  Properties
13
     | -----------------------------------------------------------------
14
     */
15
16
    /** @var string */
17
    protected $url;
18
19
    /* -----------------------------------------------------------------
20
     |  Constructor
21
     | -----------------------------------------------------------------
22
     */
23
24
    /**
25
     * LinkElement constructor.
26
     *
27
     * @param  string  $action
28
     * @param  string  $url
29
     * @param  array   $attributes
30
     * @param  bool    $disabled
31
     */
32 36
    public function __construct($action, $url, array $attributes = [], $disabled = false)
33
    {
34 36
        $this->setAction($action);
35 36
        $this->setUrl($url);
36 36
        $this->setAttributes($attributes);
37 36
        $this->setDisabled($disabled);
38 36
    }
39
40
    /* -----------------------------------------------------------------
41
     |  Getters & Setters
42
     | -----------------------------------------------------------------
43
     */
44
45
    /**
46
     * Set the link url.
47
     *
48
     * @param  string  $url
49
     *
50
     * @return \Arcanesoft\Core\Helpers\UI\Link
51
     */
52 36
    public function setUrl($url)
53
    {
54 36
        $this->url = $url;
55
56 36
        return $this;
57
    }
58
59
    /* -----------------------------------------------------------------
60
     |  Main Methods
61
     | -----------------------------------------------------------------
62
     */
63
64
    /**
65
     * Make link instance.
66
     *
67
     * @param  string  $action
68
     * @param  string  $url
69
     * @param  array   $attributes
70
     * @param  bool    $disabled
71
     *
72
     * @return self
73
     */
74 36
    public static function make($action, $url, array $attributes = [], $disabled = false)
75
    {
76 36
        return new static($action, $url, $attributes, $disabled);
77
    }
78
79
    /**
80
     * Get content as a string of HTML.
81
     *
82
     * @return string
83
     */
84 36
    public function toHtml()
85
    {
86 36
        return '<a'.$this->renderAttributes().'>'.$this->renderValue().'</a>';
87
    }
88
89
    /* -----------------------------------------------------------------
90
     |  Other Methods
91
     | -----------------------------------------------------------------
92
     */
93
94
    /**
95
     * Render the attributes.
96
     *
97
     * @return string
98
     */
99 36
    protected function renderAttributes()
100
    {
101 36
        $attributes = collect();
102 36
        $attributes->put('href',  $this->disabled ? 'javascript:void(0);' : $this->url);
103 36
        $attributes->put('class', $this->getStyleClass());
104
105 36
        if ($this->withTooltip) {
106
            // This is for Bootstrap
107 4
            $attributes->put('data-toggle', 'tooltip');
108 4
            $attributes->put('data-original-title', $this->getTitle());
109
        }
110
111 36
        if ($this->disabled)
112 2
            $attributes->put('disabled', 'disabled');
113
114 36
        return html()->attributes($attributes->merge($this->attributes)->toArray());
115
    }
116
117
    /**
118
     * Get the value from config.
119
     *
120
     * @param  string  $key
121
     * @param  mixed   $default
122
     *
123
     * @return mixed
124
     */
125 36
    protected function getConfig($key, $default = null)
126
    {
127 36
        return config("arcanesoft.core.ui.links.{$key}", $default);
128
    }
129
}
130