MageServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 65
ccs 34
cts 34
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A register() 0 28 1
A migrations() 0 22 3
1
<?php
2
3
namespace Omatech\Mage\Core;
4
5
use Illuminate\Filesystem\Filesystem;
6
use Illuminate\Support\ServiceProvider;
7
use Omatech\Mage\Core\Providers\BindingServiceProvider;
8
use Omatech\Mage\Core\Providers\HelperServiceProvider;
9
use Omatech\Mage\Core\Providers\TranslatorServiceProvider;
10
11
class MageServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Bootstrap the application services.
15
     */
16 82
    public function boot()
17
    {
18 82
        $this->publishes($this->migrations(), 'mage-migrations');
19 82
    }
20
21
    /**
22
     * Register the application services.
23
     */
24 82
    public function register()
25
    {
26 82
        parent::register();
27
28 82
        $this->mergeConfigFrom(
29 82
            __DIR__.'/../config/config.php',
30 82
            'mage'
31
        );
32
33 82
        $this->mergeConfigFrom(
34 82
            __DIR__.'/../config/permission.php',
35 82
            'permission'
36
        );
37
38 82
        $this->mergeConfigFrom(
39 82
            __DIR__.'/../config/auth.providers.php',
40 82
            'auth.providers'
41
        );
42
43 82
        $this->mergeConfigFrom(
44 82
            __DIR__.'/../config/translation-loader.php',
45 82
            'translation-loader'
46
        );
47
48 82
        $this->app->register(BindingServiceProvider::class);
49 82
        $this->app->register(TranslatorServiceProvider::class);
50 82
        $this->app->register(HelperServiceProvider::class);
51 82
    }
52
53 82
    public function migrations()
54
    {
55 82
        $migrations = [];
56
57 82
        $filesystem = new Filesystem();
58 82
        $source = __DIR__.'/database/migrations/';
59 82
        $destination = $this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR;
60
61 82
        foreach ($filesystem->files($source) as $index => $file) {
62 82
            $sourceFileName = $file->getFilename();
63 82
            $migrationName = substr($sourceFileName, 18, strlen($sourceFileName));
64
65 82
            $fileExists = 0 != count($filesystem->glob($destination.'*'.$migrationName));
66
67 82
            if (! $fileExists) {
68 1
                $destinationFileName = date('Y_m_d').'_'.str_pad($index, 6, '0').'_'.$migrationName;
69 1
                $migrations[$source.$sourceFileName] = $destination.$destinationFileName;
70
            }
71
        }
72
73 82
        return $migrations;
74
    }
75
}
76