MonologPlugin   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 25
c 3
b 0
f 0
dl 0
loc 83
rs 10
wmc 11

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getDependedPlugins() 0 4 1
A createHandlerResolverFactory() 0 5 1
A provideDependencies() 0 3 1
A createLoggerFactory() 0 4 1
A getLoggerFactory() 0 3 1
A getLoggerAdapterName() 0 3 1
A createHandlerProvider() 0 7 2
A createHandlerConfigurationFactory() 0 5 1
A createHandlerFactory() 0 5 1
A getHandlerConfigurationClassCollection() 0 4 1
1
<?php
2
3
/*
4
 *  This file is part of the Micro framework package.
5
 *
6
 *  (c) Stanislau Komar <[email protected]>
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 Micro\Plugin\Logger\Monolog;
13
14
use Micro\Component\DependencyInjection\Container;
15
use Micro\Framework\Kernel\Plugin\ConfigurableInterface;
16
use Micro\Framework\Kernel\Plugin\DependencyProviderInterface;
17
use Micro\Framework\Kernel\Plugin\PluginConfigurationTrait;
18
use Micro\Framework\Kernel\Plugin\PluginDependedInterface;
19
use Micro\Plugin\Logger\Business\Factory\LoggerFactoryInterface;
20
use Micro\Plugin\Logger\LoggerPlugin;
21
use Micro\Plugin\Logger\Monolog\Business\Factory\LoggerFactory;
0 ignored issues
show
Bug introduced by
The type Micro\Plugin\Logger\Mono...s\Factory\LoggerFactory 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...
22
use Micro\Plugin\Logger\Monolog\Business\Handler\HandlerFactory;
23
use Micro\Plugin\Logger\Monolog\Business\Handler\HandlerFactoryInterface;
24
use Micro\Plugin\Logger\Monolog\Business\Handler\HandlerProvider;
25
use Micro\Plugin\Logger\Monolog\Business\Handler\HandlerProviderInterface;
26
use Micro\Plugin\Logger\Monolog\Business\Handler\HandlerResolverFactory;
27
use Micro\Plugin\Logger\Monolog\Business\Handler\HandlerResolverFactoryInterface;
28
use Micro\Plugin\Logger\Monolog\Configuration\Handler\HandlerConfigurationFactory;
29
use Micro\Plugin\Logger\Monolog\Configuration\Handler\HandlerConfigurationFactoryInterface;
30
use Micro\Plugin\Logger\Monolog\Configuration\Handler\HandlerConfigurationInterface;
31
use Micro\Plugin\Logger\Monolog\Configuration\Handler\Type\HandlerStreamConfiguration;
32
use Micro\Plugin\Logger\Monolog\Configuration\Logger\MonologPluginConfigurationInterface;
33
use Micro\Plugin\Logger\Plugin\LoggerProviderPluginInterface;
34
35
/**
36
 * @author Stanislau Komar <[email protected]>
37
 *
38
 * @method MonologPluginConfigurationInterface configuration()
39
 */
40
class MonologPlugin implements DependencyProviderInterface, PluginDependedInterface, LoggerProviderPluginInterface, ConfigurableInterface
41
{
42
    use PluginConfigurationTrait;
43
44
    private ?HandlerProviderInterface $handlerProvider = null;
45
46
    private Container $container;
47
48
    /**
49
     * {@inheritDoc}
50
     */
51
    public function provideDependencies(Container $container): void
52
    {
53
        $this->container = $container;
54
    }
55
56
    /**
57
     * {@inheritDoc}
58
     */
59
    protected function createLoggerFactory(): LoggerFactoryInterface
60
    {
61
        return new LoggerFactory(
62
            $this->createHandlerResolverFactory()
63
        );
64
    }
65
66
    protected function createHandlerProvider(): HandlerProviderInterface
67
    {
68
        if (!$this->handlerProvider) {
69
            $this->handlerProvider = new HandlerProvider($this->createHandlerFactory());
70
        }
71
72
        return $this->handlerProvider;
73
    }
74
75
    protected function createHandlerFactory(): HandlerFactoryInterface
76
    {
77
        return new HandlerFactory(
78
            $this->container,
79
            $this->createHandlerConfigurationFactory()
80
        );
81
    }
82
83
    protected function createHandlerConfigurationFactory(): HandlerConfigurationFactoryInterface
84
    {
85
        return new HandlerConfigurationFactory(
86
            $this->configuration(),
87
            $this->getHandlerConfigurationClassCollection()
88
        );
89
    }
90
91
    protected function createHandlerResolverFactory(): HandlerResolverFactoryInterface
92
    {
93
        return new HandlerResolverFactory(
94
            $this->configuration(),
95
            $this->createHandlerProvider()
96
        );
97
    }
98
99
    /**
100
     * @return iterable<class-string<HandlerConfigurationInterface>>
101
     */
102
    protected function getHandlerConfigurationClassCollection(): iterable
103
    {
104
        return [
105
            HandlerStreamConfiguration::class,
106
        ];
107
    }
108
109
    public function getLoggerFactory(): LoggerFactoryInterface
110
    {
111
        return $this->createLoggerFactory();
112
    }
113
114
    public function getLoggerAdapterName(): string
115
    {
116
        return 'monolog';
117
    }
118
119
    public function getDependedPlugins(): iterable
120
    {
121
        return [
122
            LoggerPlugin::class,
123
        ];
124
    }
125
}
126