Cancelled
Push — master ( 33a3bb...e2379a )
by Dāvis
05:55
created

Monolog::log()   B

Complexity

Conditions 5
Paths 24

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 13
nc 24
nop 5
dl 0
loc 19
rs 8.8571
c 0
b 0
f 0
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, $vendor = null)
11
    {
12
        if ($vendor === null) {
13
            $vendor = \defined('SLUDIO_HELPER') ? SLUDIO_HELPER : 'vendor';
14
        }
15
        self::getType($type);
16
17
        try {
18
            $log = self::registerLog($vendor);
19
            $debug = \debug_backtrace()[$level];
20
            $details = [
21
                $debug['file'],
22
                $debug['line'],
23
            ];
24
            $context = !empty($context) ? \array_merge($context, $details) : $details;
25
26
            $log->{strtolower($type)}($message, $context);
27
        } catch (\Exception $exception) {
28
            return null;
29
        }
30
    }
31
32
    private static function getType(&$type)
33
    {
34
        if (!\array_key_exists(\strtoupper($type), Logger::getLevels())) {
35
            $type = Logger::getLevelName(Logger::INFO);
36
        }
37
    }
38
39
    /**
40
     * @throws \Exception
41
     */
42
    private static function registerLog($vendor)
43
    {
44
        $log = new Logger($vendor);
45
        $directory = date('Y-m-j').'_vendor';
46
        $log->pushHandler(new StreamHandler(sprintf(getcwd().'/../app/logs/vendor/%s.log', $directory)));
47
48
        return $log;
49
    }
50
}
51