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

HasModuleConfig::getCascadeModuleConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 2
nc 2
nop 0
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