Completed
Push — master ( 6acfe1...0042b2 )
by Radu
11:51 queued 10s
created

AbstractFileLogger::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 13
rs 10
cc 3
nc 3
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WebServCo\Framework\Log;
6
7
use WebServCo\Framework\Exceptions\LoggerException;
8
9
abstract class AbstractFileLogger extends AbstractLogger
10
{
11
    protected string $channel;
12
    protected string $logDir;
13
    protected string $logPath;
14
15
    public function __construct(string $channel, string $logDir)
16
    {
17
        $this->channel = $channel;
18
        $this->logDir = $logDir;
19
20
        if (empty($this->logDir)) {
21
            throw new LoggerException(\sprintf('Log directory not set for channel "%s".', $channel));
22
        }
23
24
        if (!\is_writable($this->logDir)) {
25
            throw new LoggerException(\sprintf('Log directory not writeable: %s.', $this->logDir));
26
        }
27
        $this->logPath = \sprintf('%s%s.log', $this->logDir, $this->channel);
28
    }
29
30
    public function clear(): bool
31
    {
32
        return (bool) \file_put_contents($this->logPath, null);
33
    }
34
}
35