Passed
Push — master ( 8be542...031438 )
by Alexander
10:57
created

FileRotatorProvider::register()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Provider;
6
7
use Yiisoft\Di\Container;
8
use Yiisoft\Di\Support\ServiceProvider;
9
use Yiisoft\Log\Target\File\FileRotator;
10
use Yiisoft\Log\Target\File\FileRotatorInterface;
11
12
final class FileRotatorProvider extends ServiceProvider
13
{
14
    private int $maxFileSize;
15
    private int $maxFiles;
16
    private ?int $fileMode;
17
    private ?bool $rotateByCopy;
18
19
    public function __construct(
20
        int $maxFileSize = 10,
21
        int $maxFiles = 5,
22
        ?int $fileMode = null,
23
        ?bool $rotateByCopy = null
24
    ) {
25
        $this->maxFileSize = $maxFileSize;
26
        $this->maxFiles = $maxFiles;
27
        $this->fileMode = $fileMode;
28
        $this->rotateByCopy = $rotateByCopy;
29
    }
30
31
    public function register(Container $container): void
32
    {
33
        $container->set(FileRotatorInterface::class, function () {
34
35
            return new FileRotator($this->maxFileSize, $this->maxFiles, $this->fileMode, $this->rotateByCopy);
36
        });
37
    }
38
}
39