Completed
Push — master ( cd1493...0fdab2 )
by Michael
02:22
created

MonologServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 39.66%

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 2
c 5
b 0
f 2
lcom 0
cbo 6
dl 0
loc 116
ccs 23
cts 58
cp 0.3966
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 104 2
1
<?php
2
3
namespace Stats\Providers;
4
5
use Joomla\DI\Container;
6
use Joomla\DI\ServiceProviderInterface;
7
use Monolog\Handler\StreamHandler;
8
use Monolog\Logger;
9
use Monolog\Processor\PsrLogMessageProcessor;
10
use Monolog\Processor\WebProcessor;
11
use Psr\Log\LoggerInterface;
12
13
/**
14
 * Monolog service provider
15
 *
16
 * @since  1.0
17
 */
18
class MonologServiceProvider implements ServiceProviderInterface
19
{
20
	/**
21
	 * Registers the service provider with a DI container.
22
	 *
23
	 * @param   Container  $container  The DI container.
24
	 *
25
	 * @return  void
26
	 *
27
	 * @since   1.0
28
	 */
29 1
	public function register(Container $container)
30
	{
31
		// Register the PSR-3 processor
32 1
		$container->share(
33 1
			'monolog.processor.psr3',
34
			function ()
35
			{
36
				return new PsrLogMessageProcessor;
37
			}
38 1
		);
39
40
		// Register the web processor
41 1
		$container->share(
42 1
			'monolog.processor.web',
43
			function ()
44
			{
45
				return new WebProcessor;
46
			}
47 1
		);
48
49
		// Register the web application handler
50 1
		$container->share(
51 1
			'monolog.handler.application',
52
			function (Container $container)
53
			{
54
				/** @var \Joomla\Registry\Registry $config */
55
				$config = $container->get('config');
56
57
				$level = strtoupper($config->get('log.application', $config->get('log.level', 'error')));
58
59
				return new StreamHandler(
60
					APPROOT . '/logs/stats.log',
61
					constant('\\Monolog\\Logger::' . $level)
62
				);
63
			}
64 1
		);
65
66
		// Register the database handler
67 1
		$container->share(
68 1
			'monolog.handler.database',
69
			function (Container $container)
70
			{
71
				/** @var \Joomla\Registry\Registry $config */
72
				$config = $container->get('config');
73
74
				// If database debugging is enabled then force the logger's error level to DEBUG, otherwise use the level defined in the app config
75
				$level = $config->get('database.debug', false) ? 'DEBUG' : strtoupper($config->get('log.database', $config->get('log.level', 'error')));
76
77
				return new StreamHandler(
78
					APPROOT . '/logs/stats.log',
79
					constant('\\Monolog\\Logger::' . $level)
80
				);
81
			}
82 1
		);
83
84
		// Register the web application Logger
85 1
		$container->share(
86 1
			'monolog.logger.application',
87
			function (Container $container)
88
			{
89
				return new Logger(
90
					'Application',
91
					[
92
						$container->get('monolog.handler.application')
93
					],
94
					[
0 ignored issues
show
Documentation introduced by
array($container->get('monolog.processor.web')) is of type array<integer,*,{"0":"*"}>, but the function expects a array<integer,callable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
95
						$container->get('monolog.processor.web')
96
					]
97
				);
98
			}
99 1
		);
100
101
		// Register the CLI application Logger
102 1
		$container->share(
103 1
			'monolog.logger.cli',
104
			function (Container $container)
105
			{
106
				return new Logger(
107
					'Application',
108
					[
109
						$container->get('monolog.handler.application')
110
					]
111
				);
112
			}
113 1
		);
114
115
		// Register the database Logger
116 1
		$container->share(
117 1
			'monolog.logger.database',
118
			function (Container $container)
119
			{
120
				return new Logger(
121
					'Database',
122
					[
123
						$container->get('monolog.handler.database')
124
					],
125
					[
0 ignored issues
show
Documentation introduced by
array($container->get('m...onolog.processor.web')) is of type array<integer,*,{"0":"*","1":"*"}>, but the function expects a array<integer,callable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
126
						$container->get('monolog.processor.psr3'),
127
						$container->get('monolog.processor.web')
128
					]
129
				);
130
			}
131 1
		);
132 1
	}
133
}
134