Passed
Push — master ( da797a...38c1ce )
by Gombos
03:26
created

AbstractSettingsManager::has()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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 Glorand\Model\Settings\Exceptions\ModelSettingsException;
7
use Glorand\Model\Settings\Traits\HasSettings;
8
use Illuminate\Database\Eloquent\Model;
9
10
/**
11
 * Class AbstractSettingsManager
12
 * @package Glorand\Model\Settings\Managers
13
 */
14
abstract class AbstractSettingsManager implements SettingsManagerContract
15
{
16
    /** @var \Illuminate\Database\Eloquent\Model */
17
    protected $model;
18
19
    /**
20
     * AbstractSettingsManager constructor.
21
     * @param \Illuminate\Database\Eloquent\Model $model
22
     * @throws \Glorand\Model\Settings\Exceptions\ModelSettingsException
23
     */
24 17
    public function __construct(Model $model)
25
    {
26 17
        $this->model = $model;
27 17
        if (!in_array(HasSettings::class, class_uses_recursive($this->model))) {
28 1
            throw new ModelSettingsException('Wrong model, missing HasSettings trait.');
29
        }
30 16
    }
31
32
    /**
33
     * @return array
34
     */
35 16
    public function all(): array
36
    {
37 16
        return $this->model->getSettingsValue();
38
    }
39
40
    /**
41
     * @param string $path
42
     * @return bool
43
     */
44 2
    public function has(string $path): bool
45
    {
46 2
        return array_has($this->all(), $path);
0 ignored issues
show
Deprecated Code introduced by
The function array_has() has been deprecated: Arr::has() should be used directly instead. Will be removed in Laravel 5.9. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

46
        return /** @scrutinizer ignore-deprecated */ array_has($this->all(), $path);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
47
    }
48
49
    /**
50
     * @param string|null $path
51
     * @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...
52
     * @return array|mixed
53
     */
54 4
    public function get(string $path = null, $default = null)
55
    {
56 4
        return $path ? array_get($this->all(), $path, $default) : $this->all();
0 ignored issues
show
Deprecated Code introduced by
The function array_get() has been deprecated: Arr::get() should be used directly instead. Will be removed in Laravel 5.9. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

56
        return $path ? /** @scrutinizer ignore-deprecated */ array_get($this->all(), $path, $default) : $this->all();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
57
    }
58
59
    /**
60
     * @param string $path
61
     * @param mixed $value
62
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
63
     */
64 2
    public function update(string $path, $value): SettingsManagerContract
65
    {
66 2
        return $this->set($path, $value);
67
    }
68
}
69