Configurable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 43
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A config() 0 4 1
A getConfigKey() 0 4 1
A makeConfig() 0 6 1
1
<?php
2
3
namespace Signifly\Configurable;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Arr;
7
8
trait Configurable
9
{
10
    /**
11
     * Cached config instances.
12
     *
13
     * @var array
14
     */
15
    protected $cachedConfigs = [];
16
17
    /**
18
     * Get a Config value object.
19
     *
20
     * @return Config
21
     */
22
    public function config()
23
    {
24
        return $this->makeConfig($this, $this->getConfigKey());
25
    }
26
27
    /**
28
     * Get the config database key.
29
     *
30
     * @return string
31
     */
32
    public function getConfigKey()
33
    {
34
        return 'config';
35
    }
36
37
    /**
38
     * Create a new Config instance.
39
     *
40
     * @param  Model  $model
41
     * @param  string $key
42
     * @return Config
43
     */
44
    protected function makeConfig(Model $model, string $key)
45
    {
46
        return Arr::get($this->cachedConfigs, $key, function () use ($key, $model) {
47
            return $this->cachedConfigs[$key] = new Config($model, $key);
48
        });
49
    }
50
}
51