Passed
Pull Request — master (#1)
by Gombos
01:47
created

AbstractSettingsManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Glorand\Model\Settings\Managers;
4
5
use Glorand\Model\Settings\Contracts\SettingsManagerContract;
6
use Illuminate\Database\Eloquent\Model;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Eloquent\Model was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
abstract class AbstractSettingsManager implements SettingsManagerContract
9
{
10
    /** @var \Illuminate\Database\Eloquent\Model */
11
    protected $model;
12
13
    /**
14
     * AbstractSettingsManager constructor.
15
     * @param \Illuminate\Database\Eloquent\Model $model
16
     */
17
    public function __construct(Model $model)
18
    {
19
        $this->model = $model;
20
    }
21
22
    /**
23
     * @return array
24
     */
25
    public function all(): array
26
    {
27
        if (!is_null($this->model->settings)) {
28
            return $this->model->settings;
29
        } else {
30
            return [];
31
        }
32
    }
33
34
    /**
35
     * @param string $path
36
     * @return bool
37
     */
38
    public function has(string $path): bool
39
    {
40
        return array_has($this->all(), $path);
41
    }
42
43
    /**
44
     * @param string|null $path
45
     * @param null $default
1 ignored issue
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $default is correct as it would always require null to be passed?
Loading history...
46
     * @return array|mixed
47
     */
48
    public function get(string $path = null, $default = null)
49
    {
50
        return $path ? array_get($this->all(), $path, $default) : $this->all();
51
    }
52
53
    /**
54
     * @param string $path
55
     * @param mixed $value
56
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
57
     */
58
    public function update(string $path, $value): SettingsManagerContract
59
    {
60
        return $this->set($path, $value);
61
    }
62
}
63