AbstractWidget   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 162
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 162
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getReloadTimeout() 0 4 1
A setReloadTimeout() 0 6 1
A getId() 0 4 1
A setId() 0 6 1
A getParams() 0 4 1
A setParams() 0 6 1
A getParam() 0 4 1
A setParam() 0 6 1
A getContainer() 0 4 1
A setContainer() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Widgets\Models;
6
7
abstract class AbstractWidget
8
{
9
    /**
10
     * The number of seconds before each reload.
11
     *
12
     * @var float
13
     */
14
    protected $reloadTimeout;
15
16
    /**
17
     * The unique id of the widget being called.
18
     *
19
     * @var string
20
     */
21
    protected $id;
22
23
    /**
24
     * Array of widget parameters.
25
     *
26
     * @var array
27
     */
28
    protected $params = [];
29
30
    /**
31
     * The widget container template.
32
     *
33
     * @var string
34
     */
35
    protected $container = 'rinvex/widgets::container';
36
37
    /**
38
     * Constructor.
39
     *
40
     * @param array $params
41
     */
42
    public function __construct(array $params = [])
43
    {
44
        $this->params = $params;
45
        $this->id = spl_object_hash($this);
46
    }
47
48
    /**
49
     * Get the widget reload timeout.
50
     *
51
     * @return float|null
52
     */
53
    public function getReloadTimeout()
54
    {
55
        return $this->reloadTimeout;
56
    }
57
58
    /**
59
     * Set the widget reload timeout.
60
     *
61
     * @param float $reloadTimeout
62
     *
63
     * @return $this
64
     */
65
    public function setReloadTimeout(float $reloadTimeout)
66
    {
67
        $this->reloadTimeout = $reloadTimeout;
68
69
        return $this;
70
    }
71
72
    /**
73
     * Get the widget id.
74
     *
75
     * @return string
76
     */
77
    public function getId(): string
78
    {
79
        return $this->id;
80
    }
81
82
    /**
83
     * Set the widget id.
84
     *
85
     * @param string $id
86
     *
87
     * @return $this
88
     */
89
    public function setId(string $id)
90
    {
91
        $this->id = $id;
92
93
        return $this;
94
    }
95
96
    /**
97
     * Get the widget params.
98
     *
99
     * @return array
100
     */
101
    public function getParams(): array
102
    {
103
        return $this->params;
104
    }
105
106
    /**
107
     * Set the widget params.
108
     *
109
     * @param array $params
110
     *
111
     * @return $this
112
     */
113
    public function setParams(array $params)
114
    {
115
        $this->params = $params;
116
117
        return $this;
118
    }
119
120
    /**
121
     * Get a widget param.
122
     *
123
     * @return mixed
124
     */
125
    public function getParam(string $key)
126
    {
127
        return $this->param[$key] ?? null;
0 ignored issues
show
Bug introduced by
The property param does not seem to exist. Did you mean params?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
128
    }
129
130
    /**
131
     * Set a widget param.
132
     *
133
     * @param mixed $key
134
     * @param mixed $value
135
     *
136
     * @return $this
137
     */
138
    public function setParam($key, $value)
139
    {
140
        $this->params[$key] = $value;
141
142
        return $this;
143
    }
144
145
    /**
146
     * Get the widget container.
147
     *
148
     * @return string
149
     */
150
    public function getContainer(): string
151
    {
152
        return $this->container;
153
    }
154
155
    /**
156
     * Set the widget container.
157
     *
158
     * @param string $container
159
     *
160
     * @return $this
161
     */
162
    public function setContainer(string $container)
163
    {
164
        $this->container = $container;
165
166
        return $this;
167
    }
168
}
169