Completed
Push — master ( 80d940...616322 )
by Ryan
12:16
created

LoggerTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 40
c 0
b 0
f 0
wmc 2
lcom 0
cbo 2
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setLogger() 0 13 1
A getLogger() 0 4 1
1
<?php
2
/**
3
 * Copyright (c) 2017 Ryan Parman <http://ryanparman.com>.
4
 * Copyright (c) 2017 Contributors.
5
 *
6
 * http://opensource.org/licenses/Apache2.0
7
 */
8
9
declare(strict_types=1);
10
11
namespace SimplePie\Mixin;
12
13
use Psr\Log\LoggerInterface;
14
use Skyzyx\UtilityPack\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;
27
28
    /**
29
     * Sets the PSR-3 logger.
30
     *
31
     * @param LoggerInterface $logger
32
     *
33
     * @return self
34
     */
35
    public function setLogger(LoggerInterface $logger)
36
    {
37
        $this->logger = $logger;
38
39
        // What are we logging with?
40
        $this->logger->debug(\sprintf(
41
            'Class `%s` configured to use `%s`.',
42
            Types::getClassOrType($this),
43
            Types::getClassOrType($this->logger)
44
        ));
45
46
        return $this;
47
    }
48
49
    /**
50
     * Retrieves the PSR-3 logger.
51
     *
52
     * @return LoggerInterface
53
     */
54
    public function getLogger(): LoggerInterface
55
    {
56
        return $this->logger;
57
    }
58
}
59