Completed
Pull Request — master (#2)
by Randall
04:53
created

ModuleServiceProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 16
c 0
b 0
f 0
dl 0
loc 44
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A publishMigrations() 0 6 2
A registerModules() 0 3 1
A registerProviders() 0 4 1
A registerModuleModel() 0 5 1
A provides() 0 3 1
A registerNamespaces() 0 8 1
1
<?php
2
3
namespace Rawilk\LaravelModules;
4
5
use Illuminate\Support\ServiceProvider;
6
use Rawilk\LaravelModules\Contracts\ModuleModel;
7
use Rawilk\LaravelModules\Contracts\Repository;
8
use Rawilk\LaravelModules\Providers\BootstrapServiceProvider;
9
use Rawilk\LaravelModules\Providers\ConsoleServiceProvider;
10
use Rawilk\LaravelModules\Providers\ContractServiceProvider;
11
12
abstract class ModuleServiceProvider extends ServiceProvider
13
{
14
    abstract protected function registerServices(): void;
15
16
    public function provides(): array
17
    {
18
        return [Repository::class, 'modules'];
19
    }
20
21
    protected function publishMigrations(): void
22
    {
23
        if (! class_exists('CreateModulesTable')) {
24
            $this->publishes([
25
                __DIR__ . '/../database/migrations/create_modules_table.php.stub' => database_path('migrations/' . date('Y_m_d_His') . '_create_modules_table.php')
26
            ], 'migrations');
27
        }
28
    }
29
30
    protected function registerModules(): void
31
    {
32
        $this->app->register(BootstrapServiceProvider::class);
33
    }
34
35
    protected function registerModuleModel(): void
36
    {
37
        $config = $this->app->config['modules.models'];
0 ignored issues
show
Bug introduced by
Accessing config on the interface Illuminate\Contracts\Foundation\Application suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
38
39
        $this->app->bind(ModuleModel::class, $config['module']);
40
    }
41
42
    protected function registerNamespaces(): void
43
    {
44
        $configPath = __DIR__ . '/../config/config.php';
45
46
        $this->mergeConfigFrom($configPath, 'modules');
47
        $this->publishes([
48
            $configPath => config_path('modules.php')
49
        ], 'config');
50
    }
51
52
    protected function registerProviders(): void
53
    {
54
        $this->app->register(ConsoleServiceProvider::class);
55
        $this->app->register(ContractServiceProvider::class);
56
    }
57
}
58