Passed
Push — master ( 4f923e...f2cf92 )
by 世昌
01:48
created

Debug::getDefaultConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace nebula\component\debug;
3
4
use nebula\component\debug\Caller;
5
use nebula\component\debug\ConfigTrait;
6
use nebula\component\debug\ConfigInterface;
7
use nebula\component\debug\log\LoggerTrait;
8
use nebula\component\debug\attach\DumpTrait;
9
use nebula\component\debug\attach\AttachTrait;
10
use nebula\component\debug\log\LoggerInterface;
11
use nebula\component\debug\attach\DumpInterface;
12
use nebula\component\debug\log\LoggerAwareTrait;
13
use nebula\component\debug\attach\AttachInterface;
14
use nebula\component\debug\log\LoggerAwareInterface;
15
16
class Debug implements LoggerInterface, LoggerAwareInterface, DumpInterface, AttachInterface, ConfigInterface
17
{
18
    use LoggerTrait,LoggerAwareTrait,DumpTrait,AttachTrait,ConfigTrait;
19
20
    
21
22
    public function log(string $level, string $message, array $context = [])
23
    {
24
        $attribute = [];
25
        $attribute['message'] = $this->logger->interpolate($message, $context);
0 ignored issues
show
Bug introduced by
The method interpolate() does not exist on nebula\component\debug\log\LoggerInterface. It seems like you code against a sub-type of said class. However, the method does not exist in nebula\component\debug\log\AbstractLogger or nebula\component\debug\log\logger\NullLogger. Are you sure you never get one of those? ( Ignorable by Annotation )

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

25
        /** @scrutinizer ignore-call */ 
26
        $attribute['message'] = $this->logger->interpolate($message, $context);
Loading history...
26
        $attribute['level'] = $level;
27
        $caller = new Caller(debug_backtrace(), [__DIR__]);
28
        $trace = $caller->getCallerTrace();
29
        $attribute['file'] = $trace['file'];
30
        $attribute['line'] = $trace['line'];
31
        $this->logger->log($level, $this->interpolate($this->getConfig('log-format'), $context, $attribute), []);
0 ignored issues
show
Bug introduced by
It seems like $this->getConfig('log-format') can also be of type null; however, parameter $message of nebula\component\debug\Debug::interpolate() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

31
        $this->logger->log($level, $this->interpolate(/** @scrutinizer ignore-type */ $this->getConfig('log-format'), $context, $attribute), []);
Loading history...
32
    }
33
34
    public function getDefaultConfig():array
35
    {
36
        return [
37
            'log-format' => '%time-format% - %memory-format% [%level%] %file%:%line% %message%',
38
        ];
39
    }
40
}
41