Completed
Push — 16.x ( e18d3d...f36db0 )
by Tim
02:26
created

GenericLogHandlerFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 52
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A factory() 0 15 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Loggers\ErrorLogHandlerFactory
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Martin Eisenführer <[email protected]>
15
 * @copyright 2020 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Loggers;
22
23
use TechDivision\Import\Utils\ConfigurationUtil;
24
use TechDivision\Import\Utils\ConfigurationKeys;
25
use TechDivision\Import\Configuration\ConfigurationInterface;
26
use TechDivision\Import\Configuration\Logger\HandlerConfigurationInterface;
27
28
/**
29
 * Error Log Handler factory implementation.
30
 *
31
 * @author    Martin Eisenführer <[email protected]>
32
 * @copyright 2020 TechDivision GmbH <[email protected]>
33
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
34
 * @link      https://github.com/techdivision/import
35
 * @link      http://www.techdivision.com
36
 */
37
class GenericLogHandlerFactory implements HandlerFactoryInterface
38
{
39
40
    /**
41
     * The log level to use.
42
     *
43
     * @var string
44
     */
45
    protected $defaultLogLevel;
46
47
    /**
48
     * The log level to use.
49
     *
50
     * @var string
51
     */
52
    protected $handlerClassName;
53
54
    /**
55
     * Initialize the processor with the actual configuration instance
56
     *
57
     * @param ConfigurationInterface $configuration    the actual configuration instance
58
     * @param string                 $handlerClassName Classname for monolog Logger handler
59
     */
60
    public function __construct(ConfigurationInterface $configuration, $handlerClassName)
61
    {
62
        $this->defaultLogLevel = $configuration->getLogLevel();
63
        $this->handlerClassName = $handlerClassName;
64
    }
65
66
    /**
67
     * Creates a new formatter instance based on the passed configuration.
68
     *
69
     * @param \TechDivision\Import\Configuration\Logger\HandlerConfigurationInterface $handlerConfiguration The handler configuration
70
     *
71
     * @return \Monolog\Handler\HandlerInterface The handler instance
72
     */
73
    public function factory(HandlerConfigurationInterface $handlerConfiguration)
74
    {
75
76
        // load the params
77
        $params = $handlerConfiguration->getParams();
78
79
        // set the default log level, if not already set explicitly
80
        if (!isset($params[ConfigurationKeys::LEVEL])) {
81
            $params[ConfigurationKeys::LEVEL] = $this->defaultLogLevel;
82
        }
83
84
        // create and return the handler instance
85
        $reflectionClass = new \ReflectionClass($this->handlerClassName);
86
        return $reflectionClass->newInstanceArgs(ConfigurationUtil::prepareConstructorArgs($reflectionClass, $params));
87
    }
88
}
89