LoggerUtils   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 88.46%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 13
eloc 25
c 2
b 0
f 0
dl 0
loc 51
ccs 23
cts 26
cp 0.8846
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A defaultLoggerFormatter() 0 3 1
B toLogLevelValue() 0 24 11
A defaultDateTimeFormatter() 0 3 1
1
<?php
2
3
namespace WebStream\Log;
4
5
use WebStream\Exception\Extend\LoggerException;
0 ignored issues
show
Bug introduced by
The type WebStream\Exception\Extend\LoggerException 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
7
/**
8
 * LoggerUtils
9
 * @author Ryuichi Tanaka
10
 * @since 2015/12/26
11
 * @version 0.7
12
 */
13
trait LoggerUtils
14
{
15
    /**
16
     * デフォルトロガーフォーマッタ
17
     * @return string デフォルトロガーフォーマッタ
18
     */
19
    public function defaultLoggerFormatter()
20
    {
21
        return '[%d{' . $this->defaultDateTimeFormatter() . '.%f}][%5L] %m';
22
    }
23
24
    /**
25
     * デフォルトDateTimeフォーマッタ
26
     * @return string デフォルトDateTimeフォーマッタ
27 2
     */
28
    public function defaultDateTimeFormatter()
29 2
    {
30
        return "%Y-%m-%d %H:%M:%S";
31
    }
32
33
    /**
34
     * ログレベルを数値に変換
35
     * ログレベルはWebStream独自、PSR-3両方対応
36
     * @param string ログレベル文字列
0 ignored issues
show
Documentation Bug introduced by
The doc comment ログレベル文字列 at position 0 could not be parsed: Unknown type name 'ログレベル文字列' at position 0 in ログレベル文字列.
Loading history...
37
     * @throws LoggerException
38
     * @return int ログレベル数値
39 141
     */
40
    public function toLogLevelValue(string $level)
41 141
    {
42 141
        switch (strtolower($level)) {
43 28
            case 'debug':
44 113
                return 1;
45 25
            case 'info':
46 88
                return 2;
47 11
            case 'notice':    // PSR-3
48 77
                return 3;
49 66
            case 'warn':
50 22
            case 'warning':   // PSR-3
51 55
                return 4;
52 11
            case 'error':
53 44
                return 5;
54 11
            case 'critical':  // PSR-3
55 33
                return 6;
56 11
            case 'alert':     // PSR-3
57 22
                return 7;
58 11
            case 'emergency': // PSR-3
59 11
                return 8;
60 11
            case 'fatal':
61
                return 9;
62
            default:
63
                throw new LoggerException("Undefined log level: $level");
64
        }
65
    }
66
}
67