ContextReplacementProcessor   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
c 2
b 0
f 1
lcom 0
cbo 1
dl 0
loc 32
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 4 1
B getReplacements() 0 16 6
1
<?php
2
3
namespace Oqq\Minc\Log\Processor;
4
5
use Oqq\Minc\Log\Record;
6
7
/**
8
 * @author Eric Braun <[email protected]>
9
 */
10
class ContextReplacementProcessor implements ProcessorInterface
11
{
12
    /**
13
     * @inheritdoc
14
     */
15 12
    public function process(Record $record)
16
    {
17 12
        $record->setMessage(strtr($record->getMessage(), $this->getReplacements($record)));
18 12
    }
19
20
    /**
21
     * @param Record $record
22
     *
23
     * @return array
24
     */
25 12
    protected function getReplacements(Record $record)
26
    {
27 12
        $replacements = [];
28
29 12
        foreach ($record->getContext() as $key => $val) {
30 11
            if (null === $val || is_scalar($val) || method_exists($val, '__toString')) {
31 11
                $replacements['{'.$key.'}'] = $val;
32 11
            } elseif (is_object($val)) {
33 1
                $replacements['{'.$key.'}'] = '[object '.get_class($val).']';
34 1
            } else {
35 1
                $replacements['{'.$key.'}'] = '['.gettype($val).']';
36
            }
37 12
        }
38
39 12
        return $replacements;
40
    }
41
}
42