Passed
Pull Request — master (#18)
by Cesar
02:33
created

RotateServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

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

2 Methods

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