Passed
Branch master (8a6725)
by Michał
02:20
created

LogStatic::setOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 1
1
<?php
2
3
namespace SimpleLog;
4
5
class LogStatic
6
{
7
    /**
8
     * @var null|Log
9
     */
10
    protected static $instance;
11
12
    /**
13
     * log event information into file
14
     *
15
     * @param string $level
16
     * @param array|string $message
17
     * @param array $context
18
     * @param array $params
19
     * @return Log
20
     */
21 1
    public static function log($level, $message, array $context = [], array $params = [])
22
    {
23 1
        self::init($params);
24 1
        return self::$instance->log($level, $message, $context);
0 ignored issues
show
Bug introduced by
The method log() 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

24
        return self::$instance->/** @scrutinizer ignore-call */ log($level, $message, $context);

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...
25
    }
26
27
    /**
28
     * log event information into file
29
     *
30
     * @param array|string $message
31
     * @param array $context
32
     * @param array $params
33
     * @return Log
34
     */
35 1
    public static function makeLog($message, array $context = [], array $params = [])
36
    {
37 1
        self::init($params);
38 1
        return self::$instance->makeLog($message, $context);
39
    }
40
41
    /**
42
     * set log option for all future executions of makeLog
43
     *
44
     * @param string $key
45
     * @param mixed $val
46
     * @return Log
47
     */
48 2
    public static function setOption($key, $val)
49
    {
50 2
        self::init();
51 2
        return self::$instance->setOption($key, $val);
52
    }
53
54
    /**
55
     * return all configuration or only given key value
56
     *
57
     * @param null|string $key
58
     * @return array|mixed
59
     */
60 2
    public static function getOption($key = null)
61
    {
62 2
        self::init();
63 2
        return self::$instance->getOption($key);
64
    }
65
66
    /**
67
     * create Log object if not exists
68
     *
69
     * @param array $params
70
     */
71 2
    protected static function init(array $params = [])
72
    {
73 2
        if (is_null(self::$instance)) {
74 1
            self::$instance = new Log($params);
75 1
        }
76 2
    }
77
}
78