Passed
Push — master ( 2e496e...4c080f )
by Alexander
03:20 queued 01:17
created

PsrTarget   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 31
ccs 10
cts 10
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getLogger() 0 3 1
A export() 0 5 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Log;
6
7
use Psr\Log\LoggerInterface;
8
9
/**
10
 * PsrTarget is a log target which simply passes messages to another PSR-3 compatible logger.
11
 */
12
final class PsrTarget extends Target
13
{
14
    /**
15
     * @var LoggerInterface The logger instance to be used for messages processing.
16
     */
17
    private LoggerInterface $logger;
18
19
    /**
20
     * Sets the PSR-3 logger used to save messages of this target.
21
     *
22
     * @param LoggerInterface $logger The logger instance.
23
     */
24 8
    public function __construct(LoggerInterface $logger)
25
    {
26 8
        $this->logger = $logger;
27 8
        parent::__construct();
28 8
    }
29
30
    /**
31
     * @return LoggerInterface The logger instance.
32
     */
33 8
    public function getLogger(): LoggerInterface
34
    {
35 8
        return $this->logger;
36
    }
37
38 8
    public function export(): void
39
    {
40 8
        foreach ($this->getMessages() as $message) {
41 8
            [$level, $text, $context] = $message;
42 8
            $this->logger->log($level, $text, $context);
43
        }
44 8
    }
45
}
46