RotateServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

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

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 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
        if ($this->app->runningInConsole()) {
20
            $this->publishes([
21
                __DIR__.'/../config/rotate.php' => $this->app->configPath('rotate.php'),
22
            ], 'config');
23
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