LoggerTrait::setLogger()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * Copyright (c) 2010–2019 Ryan Parman <http://ryanparman.com>.
4
 * Copyright (c) 2016–2019 Contributors.
5
 *
6
 * http://opensource.org/licenses/Apache2.0
7
 */
8
9
declare(strict_types=1);
10
11
namespace SimplePie\UtilityPack\Mixin;
12
13
use Psr\Log\LoggerInterface;
14
use SimplePie\UtilityPack\Util\Types;
15
16
/**
17
 * Shared code for working with the logger.
18
 */
19
trait LoggerTrait
20
{
21
    /**
22
     * A PSR-3 logger.
23
     *
24
     * @var LoggerInterface
25
     */
26
    protected $logger;
0 ignored issues
show
Coding Style introduced by
Protected member variable "logger" must contain a leading underscore
Loading history...
27
28
    /**
29
     * Sets the PSR-3 logger.
30
     *
31
     * @param LoggerInterface $logger A PSR-3 compatible logger.
32
     */
33 1
    public function setLogger(LoggerInterface $logger): self
34
    {
35 1
        $this->logger = $logger;
36
37
        // What are we logging with?
38 1
        $this->logger->debug(\sprintf(
39 1
            'Class `%s` configured to use `%s`.',
40 1
            Types::getClassOrType($this),
41 1
            Types::getClassOrType($this->logger)
42
        ));
43
44 1
        return $this;
45
    }
46
47
    /**
48
     * Retrieves the PSR-3 logger.
49
     */
50 1
    public function getLogger(): LoggerInterface
51
    {
52 1
        return $this->logger;
53
    }
54
}
55