Passed
Push — main ( 7d21ad...5ef848 )
by Seth
03:42
created

HasDynamicSettings::dynamicSetting()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SaasReady\Traits;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\MorphOne;
7
use SaasReady\Models\DynamicSetting;
0 ignored issues
show
Bug introduced by
The type SaasReady\Models\DynamicSetting 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...
8
9
/**
10
 * @mixin Model
11
 *
12
 * @property-read DynamicSetting|null $dynamicSetting
13
 */
14
trait HasDynamicSettings
15
{
16
    public function dynamicSetting(): MorphOne
17
    {
18
        return $this->morphOne(DynamicSetting::class, 'model');
0 ignored issues
show
Bug introduced by
It seems like morphOne() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

18
        return $this->/** @scrutinizer ignore-call */ morphOne(DynamicSetting::class, 'model');
Loading history...
19
    }
20
21
    /**
22
     * Get the setting from single level
23
     */
24
    public function getSetting(string $key, mixed $fallback = null): mixed
25
    {
26
        return $this->dynamicSetting?->getSetting($key, $fallback) ?? $fallback;
27
    }
28
29
    /**
30
     * Get the setting from 2 levels:
31
     * - First level: current instance
32
     * - Fallback level: global instance
33
     */
34
    public function getMultiLevelsSetting(string $key, mixed $fallback = null): mixed
35
    {
36
        return $this->dynamicSetting?->getSetting($key, $fallback)
37
            ?? DynamicSetting::getGlobal()?->getSetting($key, $fallback)
38
            ?? $fallback;
39
    }
40
}
41