Passed
Push — master ( a569b2...1b7ab6 )
by Christian
03:49
created

MageServiceProvider::permissionBindings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
ccs 10
cts 10
cp 1
crap 1
rs 9.9666
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
9
class MageServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap the application services.
13
     */
14 74
    public function boot()
15
    {
16 74
        $this->publishes($this->migrations(), 'mage-migrations');
17 74
    }
18
19
    /**
20
     * Register the application services.
21
     */
22 74
    public function register()
23
    {
24 74
        $this->mergeConfigFrom(
25 74
            __DIR__.'/../config/config.php',
26 74
            'mage'
27
        );
28
29 74
        $this->mergeConfigFrom(
30 74
            __DIR__.'/../config/permission.php',
31 74
            'permission'
32
        );
33
34 74
        $this->mergeConfigFrom(
35 74
            __DIR__.'/../config/auth.providers.php',
36 74
            'auth.providers'
37
        );
38
39 74
        $this->mergeConfigFrom(
40 74
            __DIR__.'/../config/auth.guards.php',
41 74
            'auth.guards'
42
        );
43
44 74
        $this->mergeConfigFrom(
45 74
            __DIR__.'/../config/translation-loader.php',
46 74
            'translation-loader'
47
        );
48
49 74
        $this->app->register(BindingServiceProvider::class);
50 74
    }
51
52 74
    public function migrations()
53
    {
54 74
        $migrations = [];
55
56 74
        $filesystem = new Filesystem();
57 74
        $source = __DIR__.'/database/migrations/';
58 74
        $destination = $this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR;
59
60 74
        foreach ($filesystem->files($source) as $index => $file) {
61 74
            $sourceFileName = $file->getFilename();
62 74
            $migrationName = substr($sourceFileName, 18, strlen($sourceFileName));
63
64 74
            $fileExists = 0 != count($filesystem->glob($destination.'*'.$migrationName));
65
66 74
            if (! $fileExists) {
67 1
                $destinationFileName = date('Y_m_d').'_'.str_pad($index, 6, '0').'_'.$migrationName;
68 74
                $migrations[$source.$sourceFileName] = $destination.$destinationFileName;
69
            }
70
        }
71
72 74
        return $migrations;
73
    }
74
}
75