Completed
Push — master ( 537349...e26b4a )
by Westin
11:04
created

LogmaticFormatterFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 19 3
1
<?php
2
declare(strict_types=1);
3
4
namespace WShafer\PSR11MonoLog\Formatter;
5
6
use Monolog\Formatter\JsonFormatter;
7
use Monolog\Formatter\LogmaticFormatter;
8
use WShafer\PSR11MonoLog\FactoryInterface;
9
10
class LogmaticFormatterFactory implements FactoryInterface
11
{
12
    public function __invoke(array $options)
13
    {
14
        $batchMode     = (int)     ($options['batchMode']     ?? JsonFormatter::BATCH_MODE_JSON);
15
        $appendNewline = (boolean) ($options['appendNewline'] ?? true);
16
        $hostmane      = (string)  ($options['hostname'] ?? '');
17
        $appName       = (string)  ($options['appName'] ?? '');
18
19
        $formatter = new LogmaticFormatter($batchMode, $appendNewline);
20
21
        if (!empty($hostmane)) {
22
            $formatter->setHostname($hostmane);
23
        }
24
25
        if (!empty($appName)) {
26
            $formatter->setAppname($appName);
27
        }
28
29
        return $formatter;
30
    }
31
}
32