LoadsSubmodules   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 17
c 2
b 0
f 0
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultSubModuleConfiguration() 0 7 1
A loadSubModules() 0 15 5
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Contains the LoadsSubmodules 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
use JetBrains\PhpStorm\ArrayShape;
18
19
trait LoadsSubmodules
20
{
21
    use HasModuleConfig;
22
23
    private function loadSubModules(array $modules): void
24
    {
25
        foreach ($modules as $module => $configuration) {
26
            if (is_int($module) && is_string($configuration)) { // means no configuration was set for module
27
                $module = $configuration;
28
                $configuration = $this->getDefaultSubModuleConfiguration();
29
            } else {
30
                $configuration = array_merge(
31
                    $this->getDefaultSubModuleConfiguration(),
32
                    is_array($configuration) ? $configuration : []
33
                );
34
                $configuration = array_replace_recursive($configuration, $this->getCascadeModuleConfiguration());
35
            }
36
37
            $this->concord->registerModule($module, $configuration);
38
        }
39
    }
40
41
    #[ArrayShape(['implicit' => "bool", 'migrations' => "mixed", 'views' => "mixed", 'routes' => "mixed"])] private function getDefaultSubModuleConfiguration(): array
42
    {
43
        return [
44
            'implicit' => true,
45
            'migrations' => $this->areMigrationsEnabled(),
46
            'views' => $this->areViewsEnabled(),
47
            'routes' => $this->areRoutesEnabled()
48
        ];
49
    }
50
}
51