TranslatableServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 56
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 10 1
A register() 0 7 1
A getMigrationFileName() 0 11 1
1
<?php
2
3
namespace LaTevaWeb\Translatable;
4
5
use Illuminate\Filesystem\Filesystem;
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\ServiceProvider;
8
9
class TranslatableServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Indicates if loading of the provider is deferred.
13
     *
14
     * @var bool
15
     */
16
    protected $defer = false;
17
18
    /**
19
     * Bootstrap services.
20
     *
21
     * @return void
22
     */
23 9
    public function boot(Filesystem $filesystem)
24
    {
25 9
        $this->publishes([
26 9
            __DIR__.'/../config/latevaweb-translatable.php' => config_path('latevaweb-translatable.php'),
27 9
        ], 'config');
28
29 9
        $this->publishes([
30 9
            __DIR__.'/../database/migrations/create_translations_tables.php.stub' => $this->getMigrationFileName($filesystem),
31 9
        ], 'migrations');
32 9
    }
33
34
    /**
35
     * Register the service provider.
36
     *
37
     * @return void
38
     */
39 9
    public function register()
40
    {
41 9
        $this->mergeConfigFrom(
42 9
            __DIR__.'/../config/latevaweb-translatable.php',
43 9
            'latevaweb-translatable'
44
        );
45 9
    }
46
47
    /**
48
     * Returns existing migration file if found, else uses the current timestamp.
49
     *
50
     * @param Filesystem $filesystem
51
     * @return string
52
     */
53 9
    protected function getMigrationFileName(Filesystem $filesystem): string
54
    {
55 9
        $timestamp = date('Y_m_d_His');
56
57 9
        return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR)
58
            ->flatMap(function ($path) use ($filesystem) {
59 9
                return $filesystem->glob($path.'*_create_translations_tables.php');
60 9
            })
61 9
            ->push($this->app->databasePath()."/migrations/{$timestamp}_create_translations_tables.php")
62 9
            ->first();
63
    }
64
}
65