Passed
Push — master ( 9b369b...9fe481 )
by Dāvis
04:59
created

Monolog   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A registerLog() 0 7 1
A log() 0 15 3
A getType() 0 4 2
1
<?php
2
3
namespace Sludio\HelperBundle\Script\Security\Logger;
4
5
use Monolog\Handler\StreamHandler;
0 ignored issues
show
Bug introduced by
The type Monolog\Handler\StreamHandler 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...
6
use Monolog\Logger;
0 ignored issues
show
Bug introduced by
The type Monolog\Logger 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...
7
8
class Monolog
9
{
10
    public static function log($message, array $context = [], $type = 'info', $level = 0)
11
    {
12
        self::getType($type);
13
14
        try {
15
            $log = self::registerLog();
16
            $debug = \debug_backtrace()[$level];
17
            $details = [
18
                $debug['file'],
19
                $debug['line'],
20
            ];
21
            $context = !empty($context) ? \array_merge($context, $details) : $details;
22
23
            $log->{strtolower($type)}($message, $context);
24
        } catch (\Exception $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
25
26
        }
27
    }
28
29
    private static function getType(&$type)
30
    {
31
        if (!\array_key_exists(\strtoupper($type), Logger::getLevels())) {
32
            $type = Logger::getLevelName(Logger::INFO);
33
        }
34
    }
35
36
    /**
37
     * @throws \Exception
38
     */
39
    public static function registerLog()
40
    {
41
        $log = new Logger('sludio_helper');
42
        $directory = date('Y-m-j').'_vendor';
43
        $log->pushHandler(new StreamHandler(sprintf(getcwd().'/../app/logs/vendor/%s.log', $directory)));
44
45
        return $log;
46
    }
47
}
48