Passed
Push — master ( 2ab9ec...990ee9 )
by Attila
49:42
created

HasModuleConfig   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
eloc 9
c 2
b 0
f 0
dl 0
loc 41
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A areModelsEnabled() 0 3 1
A areViewsEnabled() 0 3 1
A areRoutesEnabled() 0 3 1
A config() 0 5 2
A areMigrationsEnabled() 0 3 1
A getCascadeModuleConfiguration() 0 5 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Contains the HasModuleConfig trait.
7
 *
8
 * @copyright   Copyright (c) 2021 Attila Fulop
9
 * @author      Attila Fulop
10
 * @license     MIT
11
 * @since       2021-11-11
12
 *
13
 */
14
15
namespace Konekt\Concord\Concerns;
16
17
trait HasModuleConfig
18
{
19
    public function config(string $key = null, $default = null): mixed
20
    {
21
        $key = $key ? sprintf('%s.%s', $this->getId(), $key) : $this->getId();
22
23
        return config($key, $default);
24
    }
25
26
    public function areMigrationsEnabled(): bool
27
    {
28
        return (bool) $this->config('migrations', true);
29
    }
30
31
    public function areModelsEnabled(): bool
32
    {
33
        return (bool) $this->config('models', true);
34
    }
35
36
    public function areViewsEnabled(): bool
37
    {
38
        return (bool) $this->config('views', true);
39
    }
40
41
    public function areRoutesEnabled(): bool
42
    {
43
        return (bool) $this->config('routes', true);
44
    }
45
46
    abstract public function getId(): string;
47
48
    /**
49
     * Returns the "cascade" configuration: the "apply to all submodules" config override array
50
     *
51
     * @return array
52
     */
53
    protected function getCascadeModuleConfiguration(): array
54
    {
55
        $result = $this->config('cascade_config', []);
56
57
        return is_array($result) ? $result : [];
58
    }
59
}
60