Passed
Pull Request — master (#18)
by Cesar
10:54
created

RotateServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A registerSchedule() 0 11 2
A register() 0 3 1
A boot() 0 13 2
1
<?php
2
3
namespace Cesargb\LaravelLog;
4
5
use Illuminate\Console\Scheduling\Schedule;
6
use Illuminate\Support\ServiceProvider;
7
8
class RotateServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Bootstrap the application services.
12
     *
13
     * @return void
14
     */
15
    public function boot()
16
    {
17
        $this->publishes([
18
            __DIR__.'/../config/rotate.php' => config_path('rotate.php'),
19
        ], 'config');
20
21
        if ($this->app->runningInConsole()) {
22
            $this->commands([
23
                Commands\Rotate::class,
24
                Commands\RotateFile::class,
25
            ]);
26
27
            $this->registerSchedule();
28
        }
29
    }
30
31
    /**
32
     * Register the application services.
33
     *
34
     * @return void
35
     */
36
    public function register()
37
    {
38
        $this->mergeConfigFrom(__DIR__.'/../config/rotate.php', 'rotate');
39
    }
40
41
    private function registerSchedule()
42
    {
43
        if (!config('rotate.schedule.enable', true)) {
44
            return;
45
        }
46
47
        $this->callAfterResolving(Schedule::class, function (Schedule $schedule) {
48
            $cronOldVersion = config('rotate.logs_rotate_schedule', '0 0 * * *');
49
            $cron = config('rotate.schedule.cron', $cronOldVersion);
50
51
            $schedule->command('rotate:logs')->cron($cron);
52
        });
53
    }
54
}
55