Completed
Pull Request — master (#24)
by
unknown
06:24 queued 03:07
created

DateFormatter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A format() 0 4 1
A getDateFormat() 0 2 1
1
<?php
2
/**
3
 * @author Chris dePage <[email protected]>
4
 * @copyright 2009-2018 Vanilla Forums Inc.
5
 * @license MIT
6
 */
7
8
namespace Garden\Cli\Logger\Formatter;
9
10
/**
11
 * Class DateFormatter
12
 */
13
class DateFormatter implements FormatterInterface {
14
15
    /**
16
     * @var string The date format as passed to {@link strftime()}.
17
     */
18
    protected $dateFormat = '[%F %T]';
19
20
    /**
21
     * DateFormatter constructor.
22
     *
23
     * @param string $dateFormat The strftime()-compatible format.
24
     */
25
    public function __construct(string $dateFormat = '[%F %t]') {
26
        $this->dateFormat = $dateFormat;
27
    }
28
29
    /**
30
     * Get the date format as passed to {@link strftime()}.
31
     *
32
     * @return string Returns the strftime()-compatible format.
33
     */
34
    public function getDateFormat() {
35
        return $this->dateFormat;
36
    }
37
38
    /**
39
     * Format one or more of the components of the log entry.
40
     *
41
     * @param int|string $time The time of the log entry.
42
     * @param string $logLevel The level of the message.
43
     * @param int $indentLevel The nesting level of the message.
44
     * @param string $message The message.
45
     * @param float|null|string $duration The duration to add to the message.
46
     *
47
     * @return array
48
     */
49
    public function format($time, string $logLevel, int $indentLevel, string $message, $duration) {
50
        $time = strftime($this->getDateFormat(), $time);
0 ignored issues
show
Bug introduced by
It seems like $time can also be of type string; however, parameter $timestamp of strftime() does only seem to accept integer, 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

50
        $time = strftime($this->getDateFormat(), /** @scrutinizer ignore-type */ $time);
Loading history...
51
52
        return [$time, $logLevel, $indentLevel, $message, $duration];
53
    }
54
}
55