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

getDefaultModuleConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A BaseBoxServiceProvider::publishOwnMigrationsInASeparateGroup() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Contains the BaseBoxServiceProvider class.
7
 *
8
 * @copyright   Copyright (c) 2016 Attila Fulop
9
 * @author      Attila Fulop
10
 * @license     MIT
11
 * @since       2016-12-29
12
 *
13
 */
14
15
namespace Konekt\Concord;
16
17
use Konekt\Concord\Concerns\LoadsSubmodules;
18
19
abstract class BaseBoxServiceProvider extends BaseServiceProvider
20
{
21
    use LoadsSubmodules;
22
23
    protected $configFileName = 'box.php';
24
25
    protected static $_kind = 'box';
26
27
    public function register()
28
    {
29
        parent::register();
30
31
        $modules = $this->config("modules", []);
32
33
        if (is_array($modules)) {
34
            $this->loadSubModules($modules);
35
        }
36
    }
37
38
    public function boot()
39
    {
40
        parent::boot();
41
42
        $this->publishOwnMigrationsInASeparateGroup();
43
        $this->publishAllSubModuleMigrations();
44
    }
45
46
    /**
47
     * Returns the "cascade" configuration: the "apply to all submodules" config override array
48
     *
49
     * @return array
50
     */
51
    protected function getCascadeModuleConfiguration(): array
52
    {
53
        $result = $this->config('cascade_config', []);
54
55
        return is_array($result) ? $result : [];
56
    }
57
58
    private function publishAllSubModuleMigrations(): void
59
    {
60
        $folder = '/' . $this->convention->migrationsFolder();
61
        $moduleMigrationPaths = [
62
            $this->getBasePath() . $folder => database_path('migrations')
63
        ];
64
        foreach ($this->config("modules", []) as $moduleClass => $config) {
65
            $module = $this->concord->module($this->getModuleId($moduleClass));
66
            $moduleMigrationPaths[$module->getBasePath() . $folder] = database_path('migrations');
67
        }
68
69
        $this->publishes($moduleMigrationPaths, 'migrations');
70
    }
71
72
    private function publishOwnMigrationsInASeparateGroup()
73
    {
74
        $this->publishes([
75
            $this->getBasePath() . '/' . $this->convention->migrationsFolder() =>
76
                database_path('migrations')
77
        ], 'own-migrations-only');
78
    }
79
}
80