Completed
Pull Request — master (#95)
by Matthew
01:22
created

HasCustomProperties   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 51
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\ServerMonitor\Models\Concerns;
4
5
use Illuminate\Support\Arr;
6
7
trait HasCustomProperties
8
{
9
    public function hasCustomProperty(string $propertyName): bool
10
    {
11
        return Arr::has(($this->custom_properties, $propertyName);
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected ','
Loading history...
12
    }
13
14
    /**
15
     * @param string $propertyName
16
     * @param mixed $default
17
     *
18
     * @return mixed
19
     */
20
    public function getCustomProperty(string $propertyName, $default = null)
21
    {
22
        return Arr::get($this->custom_properties, $propertyName, $default);
23
    }
24
25
    /**
26
     * @param string $name
27
     * @param mixed $value
28
     *
29
     * @return $this
30
     */
31
    public function setCustomProperty(string $name, $value)
32
    {
33
        $customProperties = $this->custom_properties;
34
35
        Arr::set($customProperties, $name, $value);
36
37
        $this->custom_properties = $customProperties;
38
39
        return $this;
40
    }
41
42
    /**
43
     * @param string $name
44
     *
45
     * @return $this
46
     */
47
    public function forgetCustomProperty(string $name)
48
    {
49
        $customProperties = $this->custom_properties;
50
51
        Arr::forget($customProperties, $name);
52
53
        $this->custom_properties = $customProperties;
54
55
        return $this;
56
    }
57
}
58