BaseAction   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 11
c 1
b 0
f 0
dl 0
loc 55
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getUrl() 0 10 4
A getCurrentUrl() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace Itstructure\GridView\Actions;
4
5
use Closure;
6
use Itstructure\GridView\Traits\{Configurable, Attributable};
7
8
/**
9
 * Class BaseAction.
10
 * @package Itstructure\GridView\Actions
11
 *
12
 * @property string $url
13
 */
14
abstract class BaseAction
15
{
16
    use Configurable, Attributable;
17
18
    const BOOTSTRAP_COL_WIDTH = 4;
19
20
    /**
21
     * @var string|Closure|null
22
     */
23
    protected $url;
24
25
    /**
26
     * BaseButton constructor.
27
     * @param array $config
28
     */
29
    public function __construct(array $config = [])
30
    {
31
        $this->loadConfig($config);
32
    }
33
34
    /**
35
     * @param $row
36
     * @param int $bootstrapColWidth
37
     * @return mixed
38
     */
39
    abstract public function render($row, int $bootstrapColWidth = self::BOOTSTRAP_COL_WIDTH);
40
41
    /**
42
     * Build url for some actions.
43
     * @param $row
44
     */
45
    abstract protected function buildUrl($row);
46
47
    /**
48
     * @param $row
49
     * @return mixed|string
50
     */
51
    protected function getUrl($row)
52
    {
53
        if ($this->url instanceof Closure) {
0 ignored issues
show
introduced by
$this->url is never a sub-type of Closure.
Loading history...
54
            return call_user_func($this->url, $row);
55
56
        } else if (!is_null($this->url) && is_string($this->url)) {
0 ignored issues
show
introduced by
The condition is_string($this->url) is always true.
Loading history...
introduced by
The condition is_null($this->url) is always false.
Loading history...
57
            return $this->url;
58
        }
59
60
        return $this->buildUrl($row);
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    protected function getCurrentUrl()
67
    {
68
        return url()->current();
69
    }
70
}
71