Passed
Push — master ( 07e0f1...85dc69 )
by Attila
02:46
created

getDefaultSubModuleConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
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
    private function loadSubModules(array $modules): void
22
    {
23
        foreach ($modules as $module => $configuration) {
24
            if (is_int($module) && is_string($configuration)) { // means no configuration was set for module
25
                $module = $configuration;
26
                $configuration = $this->getDefaultSubModuleConfiguration();
27
            } else {
28
                $configuration = array_merge(
29
                    $this->getDefaultSubModuleConfiguration(),
30
                    is_array($configuration) ? $configuration : []
31
                );
32
                $configuration = array_replace_recursive($configuration, $this->getCascadeModuleConfiguration());
0 ignored issues
show
Bug introduced by
It seems like getCascadeModuleConfiguration() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
                $configuration = array_replace_recursive($configuration, $this->/** @scrutinizer ignore-call */ getCascadeModuleConfiguration());
Loading history...
33
            }
34
35
            $this->concord->registerModule($module, $configuration);
36
        }
37
    }
38
39
    #[ArrayShape(['implicit' => "bool", 'migrations' => "mixed", 'views' => "mixed", 'routes' => "mixed"])] private function getDefaultSubModuleConfiguration(): array
40
    {
41
        return [
42
            'implicit' => true,
43
            'migrations' => $this->areMigrationsEnabled(),
0 ignored issues
show
Bug introduced by
It seems like areMigrationsEnabled() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
            'migrations' => $this->/** @scrutinizer ignore-call */ areMigrationsEnabled(),
Loading history...
44
            'views' => $this->areViewsEnabled(),
0 ignored issues
show
Bug introduced by
It seems like areViewsEnabled() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
            'views' => $this->/** @scrutinizer ignore-call */ areViewsEnabled(),
Loading history...
45
            'routes' => $this->areRoutesEnabled()
0 ignored issues
show
Bug introduced by
It seems like areRoutesEnabled() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
            'routes' => $this->/** @scrutinizer ignore-call */ areRoutesEnabled()
Loading history...
46
        ];
47
    }
48
}
49