Completed
Push — master ( cac190...51e389 )
by WEBEWEB
01:21
created

AbstractProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getLogger() 0 3 1
A logInfo() 0 6 2
A setLogger() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2020 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\Core\Provider;
13
14
use Psr\Log\LoggerInterface;
15
use WBW\Library\Core\Model\Attribute\BooleanDebugTrait;
16
17
/**
18
 * Abstract provider.
19
 *
20
 * @author webeweb <https://github.com/webeweb>
21
 * @package WBW\Library\Core\Provider
22
 * @abstract
23
 */
24
abstract class AbstractProvider {
25
26
    use BooleanDebugTrait;
27
28
    /**
29
     * Logger.
30
     *
31
     * @var LoggerInterface
32
     */
33
    private $logger;
34
35
    /**
36
     * Constructor.
37
     *
38
     * @param LoggerInterface|null $logger The logger.
39
     */
40
    protected function __construct(LoggerInterface $logger = null) {
41
        $this->setLogger($logger);
42
    }
43
44
    /**
45
     * Get the logger.
46
     *
47
     * @return LoggerInterface Returns the logger.
48
     */
49
    public function getLogger() {
50
        return $this->logger;
51
    }
52
53
    /**
54
     * Log an info.
55
     *
56
     * @param string $message The message.
57
     * @param array $context The context.
58
     * @return AbstractProvider Returns this provider.
59
     */
60
    protected function logInfo($message, array $context) {
61
        if (null !== $this->getLogger()) {
62
            $this->getLogger()->info($message, $context);
63
        }
64
        return $this;
65
    }
66
67
    /**
68
     * Set the logger.
69
     *
70
     * @param LoggerInterface $logger The logger.
71
     * @return AbstractProvider Returns this provider.
72
     */
73
    protected function setLogger(LoggerInterface $logger = null) {
74
        $this->logger = $logger;
75
        return $this;
76
    }
77
78
}