Passed
Push — master ( 30c0cd...ead992 )
by Бабичев
02:21
created

ReadableService::getSettingFloat()   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 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 3
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Bavix\Settings\Services;
4
5
use Bavix\Settings\Models\Setting;
6
use Illuminate\Database\Eloquent\Model;
7
8
class ReadableService
9
{
10
11
    /**
12
     * @param Model $model
13
     * @param string $key
14
     * @return Setting|null
15
     */
16 6
    public function getSetting(Model $model, string $key): ?Setting
17
    {
18 6
        foreach ($model->settings as $setting) {
19 6
            if ($setting->key === $key) {
20 6
                return $setting;
21
            }
22
        }
23
24 1
        return null;
25
    }
26
27
    /**
28
     * @param Model $model
29
     * @param string $key
30
     * @param int|null $default
31
     * @return int|null
32
     */
33 1
    public function getSettingInt(Model $model, string $key, ?int $default = null): ?int
34
    {
35 1
        return $this->getSetting($model, $key)->value ?? $default;
0 ignored issues
show
Bug introduced by
The property value does not seem to exist on Bavix\Settings\Models\Setting. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
36
    }
37
38
    /**
39
     * @param Model $model
40
     * @param string $key
41
     * @param float|null $default
42
     * @return float|null
43
     */
44 1
    public function getSettingFloat(Model $model, string $key, ?float $default = null): ?float
45
    {
46 1
        return $this->getSetting($model, $key)->value ?? $default;
0 ignored issues
show
Bug introduced by
The property value does not seem to exist on Bavix\Settings\Models\Setting. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
47
    }
48
49
    /**
50
     * @param Model $model
51
     * @param string $key
52
     * @param bool|null $default
53
     * @return bool|null
54
     */
55 1
    public function getSettingBool(Model $model, string $key, ?bool $default = null): ?bool
56
    {
57 1
        return $this->getSetting($model, $key)->value ?? $default;
0 ignored issues
show
Bug introduced by
The property value does not seem to exist on Bavix\Settings\Models\Setting. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
58
    }
59
60
    /**
61
     * @param Model $model
62
     * @param string $key
63
     * @param string|null $default
64
     * @return string|null
65
     */
66 1
    public function getSettingString(Model $model, string $key, ?string $default = null): ?string
67
    {
68 1
        return $this->getSetting($model, $key)->value ?? $default;
0 ignored issues
show
Bug introduced by
The property value does not seem to exist on Bavix\Settings\Models\Setting. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
69
    }
70
71
    /**
72
     * @param Model $model
73
     * @param string $key
74
     * @param array|null $default
75
     * @return array|null
76
     */
77 1
    public function getSettingArray(Model $model, string $key, ?array $default = null): ?array
78
    {
79 1
        return $this->getSetting($model, $key)->value ?? $default;
0 ignored issues
show
Bug introduced by
The property value does not seem to exist on Bavix\Settings\Models\Setting. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
80
    }
81
82
}
83