Passed
Push — dev ( 0dbbcc...f29cfd )
by Janko
10:15
created

StuLogger::logf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Stu\Module\Logging;
4
5
use Monolog\Handler\StreamHandler;
6
use Monolog\Logger;
7
use Stu\Config\Init;
8
use Stu\Module\Config\StuConfigInterface;
9
10
class StuLogger
11
{
12
    private static ?Logger $logger = null;
13
14
    public static function log(string $message): void
15
    {
16
        $method = LoggerEnum::LEVEL_METHODS[LoggerEnum::LEVEL_INFO];
0 ignored issues
show
Bug introduced by
The type Stu\Module\Logging\LoggerEnum 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...
17
        self::getLogger()->$method($message);
18
    }
19
20
    /** @param string|int|float $args */
21
    public static function logf(string $information, ...$args): void
22
    {
23
        self::log(vsprintf(
24
            $information,
25
            $args
26
        ));
27
    }
28
29
    private static function getLogger(): Logger
30
    {
31
        if (self::$logger === null) {
32
            self::$logger = new Logger('stu');
33
            self::$logger->pushHandler(
0 ignored issues
show
Bug introduced by
The method pushHandler() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
            self::$logger->/** @scrutinizer ignore-call */ 
34
                           pushHandler(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
                new StreamHandler(
35
                    Init::getContainer()
36
                        ->get(StuConfigInterface::class)
37
                        ->getDebugSettings()
38
                        ->getLogfilePath()
39
                ),
40
            );
41
        }
42
43
        return self::$logger;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::logger could return the type null which is incompatible with the type-hinted return Monolog\Logger. Consider adding an additional type-check to rule them out.
Loading history...
44
    }
45
}
46