Passed
Push — master ( 960c3d...9abe92 )
by Maxim
04:08
created

LoggerService::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace WebComplete\core\utils\logger;
4
5
use Monolog\Logger;
6
use Psr\Log\LoggerInterface;
7
use WebComplete\core\utils\container\ContainerInterface;
8
use WebComplete\mvc\ApplicationConfig;
0 ignored issues
show
Bug introduced by
The type WebComplete\mvc\ApplicationConfig was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class LoggerService
11
{
12
13
    /**
14
     * @var ContainerInterface
15
     */
16
    protected $container;
17
    /**
18
     * @var ApplicationConfig
19
     */
20
    protected $config;
21
    protected $scope = [];
22
23
    /**
24
     * @param ApplicationConfig $config
25
     * @param ContainerInterface $container
26
     */
27
    public function __construct(ApplicationConfig $config, ContainerInterface $container)
28
    {
29
        $this->config = $config;
30
        $this->container = $container;
31
    }
32
33
    /**
34
     * @param string $name
35
     *
36
     * @return LoggerInterface
37
     */
38
    public function get(string $name): LoggerInterface
39
    {
40
        if (!isset($this->scope[$name])) {
41
            $this->scope[$name] = $this->create($name);
42
        }
43
44
        return $this->scope[$name];
45
    }
46
47
    /**
48
     * @param string $name
49
     *
50
     * @return LoggerInterface
51
     */
52
    protected function create(string $name): LoggerInterface
53
    {
54
        $configLogger = $this->config['logger'];
55
        $handlers = (array)($configLogger[$name] ?? []);
56
        return new Logger($name, $handlers);
57
    }
58
}
59