Passed
Push — master ( 442a9a...3948f8 )
by Dāvis
05:23
created

Script/Security/Logger/Monolog.php (2 issues)

1
<?php
2
3
namespace Sludio\HelperBundle\Script\Security\Logger;
4
5
use Monolog\Handler\StreamHandler;
0 ignored issues
show
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
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 = \SLUDIO_HELPER)
11
    {
12
        self::getType($type);
13
14
        try {
15
            $log = self::registerLog($vendor);
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) {
25
            return null;
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
    private static function registerLog($vendor)
40
    {
41
        $log = new Logger($vendor);
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