Test Failed
Pull Request — master (#2)
by
unknown
04:16
created

TranslatableServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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
    public function boot(Filesystem $filesystem)
24
    {
25
        $this->publishes([
26
            __DIR__.'/../config/latevaweb-translatable.php' => config_path('latevaweb-translatable.php'),
27
        ], 'config');
28
29
        $this->publishes([
30
            __DIR__.'/../database/migrations/create_translations_tables.php.stub' => $this->getMigrationFileName($filesystem),
31
        ], 'migrations');
32
    }
33
34
    /**
35
     * Register the service provider.
36
     *
37
     * @return void
38
     */
39
    public function register()
40
    {
41
        $this->mergeConfigFrom(
42
            __DIR__.'/../config/latevaweb-translatable.php',
43
            'latevaweb-translatable'
44
        );
45
    }
46
47
    /**
48
     * Returns existing migration file if found, else uses the current timestamp.
49
     *
50
     * @param Filesystem $filesystem
51
     * @return string
52
     */
53
    protected function getMigrationFileName(Filesystem $filesystem): string
54
    {
55
        $timestamp = date('Y_m_d_His');
56
57
        return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR)
58
            ->flatMap(function ($path) use ($filesystem) {
59
                return $filesystem->glob($path.'*_create_robots_tables.php');
60
            })
61
            ->push($this->app->databasePath()."/migrations/{$timestamp}_create_robots_tables.php")
62
            ->first();
63
    }
64
}
65