Passed
Push — master ( 762407...a7439c )
by Roy
04:51 queued 03:09
created

ModulizeServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultConfigFilePath() 0 3 1
A loadTranslations() 0 6 1
A boot() 0 13 1
A register() 0 17 1
1
<?php
2
3
namespace LaravelModulize\Providers;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Filesystem\Filesystem;
7
use LaravelModulize\Services\Modulizer;
8
use LaravelModulize\Services\ModulizerRepository;
9
use LaravelModulize\Contracts\ModulizerRepositoryInterface;
10
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
11
12
/**
13
 * Service provider
14
 */
15
class ModulizeServiceProvider extends BaseServiceProvider
16
{
17
    /**
18
     * Bootstrap the application services.
19
     *
20
     * @return void
21
     */
22
    public function boot()
23
    {
24
        $this->app->get('modulizer')->bootstrapFileLoaders();
25
26
        $this->loadMigrationsFrom($this->app->get(ModulizerRepository::class)->migrations);
27
28
        $this->loadTranslations(
29
            collect($this->app->get(ModulizerRepository::class)->translations)
30
        );
31
32
        $this->publishes([
33
            $this->getDefaultConfigFilePath('modulizer') => config_path('modulizer.php'),
34
        ], 'config');
35
    }
36
37
    /**
38
     * Register the application services.
39
     *
40
     * @return void
41
     */
42
    public function register()
43
    {
44
        $this->app->singleton(ModulizerRepository::class, function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

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

44
        $this->app->singleton(ModulizerRepository::class, function (/** @scrutinizer ignore-unused */ $app) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
            return new ModulizerRepository(new Filesystem());
46
        });
47
48
        $this->app->bind(
49
            ModulizerRepositoryInterface::class,
50
            ModulizerRepository::class
51
        );
52
53
        $this->app->singleton('modulizer', function ($app) {
54
            return $app->make(Modulizer::class);
55
        });
56
57
        $this->mergeConfigFrom(
58
            $this->getDefaultConfigFilePath('modulizer'), 'modulizer'
59
        );
60
    }
61
62
    /**
63
     * Get default configuration file path
64
     *
65
     * @return string
66
     */
67
    public function getDefaultConfigFilePath($configName)
68
    {
69
        return realpath(__DIR__ . "/../config/{$configName}.php");
70
    }
71
72
    protected function loadTranslations(Collection $translations)
73
    {
74
        $translations->each(function ($translationsFile) {
75
            $this->loadTranslationsFrom(
76
                $translationsFile->path,
77
                $translationsFile->namespace
78
            );
79
        });
80
    }
81
}
82