Completed
Push — 16146-settings-to-admin ( e90069 )
by Shawn
05:56
created

ConfigAbstract   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 46
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A implementAllowable() 0 6 2
setup() 0 1 ?
A setConfigValues() 0 5 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: sdibble
5
 * Date: 12/7/2016
6
 * Time: 2:25 PM
7
 */
8
9
namespace SET\Handlers\DBConfigs;
10
11
12
/**
13
 * Class ConfigAbstract
14
 * @package SET\Handlers\DBConfigs
15
 */
16
abstract class ConfigAbstract
17
{
18
    /**
19
     * @var array
20
     */
21
    public $settings;
22
23
    public $allowable;
24
25
    /**
26
     *
27
     *
28
     * ConfigAbstract constructor.
29
     * @param array $settings
30
     */
31
    public function __construct($settings = [])
32
    {
33
        $this->settings = $settings;
34
    }
35
36
    public function implementAllowable()
37
    {
38
        foreach ($this->allowable as $configKey) {
39
            $this->setConfigValues($configKey);
40
        }
41
    }
42
43
    /**
44
     * All classes need to setup some kind of configuration data.
45
     * @return mixed
46
     */
47
    abstract public function setup();
48
49
50
    /**
51
     * First we set the value stored in the database. If there is no value, we go to what is in the config/env files.
52
     *
53
     * @param string $location
54
     * @param mixed $default
55
     */
56
    public function setConfigValues(string $location, $default = null)
57
    {
58
        $value = $default ?? $this->settings[$location] ?? config($location);
59
        config([$location => $value]);
60
    }
61
}