Completed
Push — master ( 9b3fe3...b82616 )
by Hong
06:10 queued 03:55
created

DefaultFormatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 0 12 2
A getEol() 0 8 2
1
<?php
2
3
/**
4
 * Phoole (PHP7.2+)
5
 *
6
 * @category  Library
7
 * @package   Phoole\Logger
8
 * @copyright Copyright (c) 2019 Hong Zhang
9
 */
10
declare(strict_types=1);
11
12
namespace Phoole\Logger\Formatter;
13
14
use Phoole\Logger\Entry\LogEntryInterface;
15
16
/**
17
 * DefaultFormatter
18
 *
19
 * @package Phoole\Logger
20
 */
21
class DefaultFormatter implements FormatterInterface
22
{
23
    /**
24
     * {@inheritDoc}
25
     */
26
    public function format(LogEntryInterface $entry): string
27
    {
28
        $context = $entry->getContext();
29
30
        $mesg = '';
31
        if (isset($context['__channel'])) {
32
            $mesg .= '[' . strtoupper($context['__channel']) . '] ';
33
        }
34
        $mesg .= $entry . $this->getEol();
35
36
        return  $mesg;
37
    }
38
   
39
    /**
40
     * Get EOL char base on the platform WIN or UNIX
41
     *
42
     * @return string
43
     */
44
    protected function getEol(): string
45
    {
46
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
47
            return "\r\n";
48
        } else {
49
            return "\n";
50
        }
51
    }
52
}
53