LogPackage   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 16
c 3
b 0
f 0
dl 0
loc 32
ccs 15
cts 15
cp 1
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A addToContainer() 0 25 6
1
<?php declare(strict_types=1);
2
3
namespace Bone\Log;
4
5
use Barnacle\Container;
6
use Barnacle\RegistrationInterface;
7
use Psr\Log\LoggerInterface;
8
9
class LogPackage implements RegistrationInterface
10
{
11
    /**
12
     * @param Container $c
13
     * @return array
14
     * @throws \Exception
15
     */
16 1
    public function addToContainer(Container $c)
17
    {
18 1
        if ($c->has('display_errors')) {
19 1
            ini_set('display_errors', (string) $c->get('display_errors'));
20
        }
21
22 1
        if ($c->has('error_reporting')) {
23 1
            error_reporting($c->get('error_reporting'));
24
        }
25
26 1
        if ($c->has('error_log')) {
27 1
            $errorLog = $c->get('error_log');
28 1
            if (!file_exists($errorLog)) {
29 1
                file_put_contents($errorLog, '');
30 1
                chmod($errorLog, 0775);
31
            }
32 1
            ini_set('error_log', $errorLog);
33
        }
34
35 1
        if ($c->has('log')) {
36
            $c[LoggerInterface::class] = $c->factory(function (Container $c) {
37 1
                $config = $c->get('log');
38 1
                $loggerFactory = new LoggerFactory();
39
40 1
                return $loggerFactory->createLoggers($config);
41 1
            });
42
        }
43 1
    }
44
}
45