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

Rotate::file()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Cesargb\LaravelLog;
4
5
use Cesargb\LaravelLog\Events\RotateHasFailed;
6
use Cesargb\LaravelLog\Events\RotateWasSuccessful;
7
use Cesargb\Log\Rotation;
8
9
class Rotate
10
{
11
    public function files(array $filenames)
12
    {
13
        array_walk($filenames, function ($filename) {
14
            $this->file($filename);
15
        });
16
    }
17
18
    public function file(string $filename, array $options = []): bool
19
    {
20
        return $this->buildRotateDefault($options)->rotate($filename);
21
    }
22
23
    private function buildRotateDefault(array $options = []): Rotation
24
    {
25
        return new Rotation(array_merge(
26
            [
27
                'files' => config('rotate.log_max_files', 366),
28
                'compress' => config('rotate.log_compress_files', true),
29
                'then' => function ($filenameRotated, $filename) {
30
                    event(new RotateWasSuccessful($filename, $filenameRotated));
31
                },
32
                'catch' => function ($error) {
33
                    event(new RotateHasFailed('', $error));
34
                },
35
            ],
36
           $options
37
        ));
38
    }
39
}
40