StringHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A handler() 0 13 6
1
<?php
2
3
namespace Tleckie\Log\Formatter\Handler;
4
5
/**
6
 * Class StringHandler
7
 *
8
 * @package Tleckie\Log\Formatter\Handler
9
 * @author  Teodoro Leckie Westberg <[email protected]>
10
 */
11
class StringHandler extends Handler
12
{
13
    /**
14
     * @param mixed $message
15
     * @param array $context
16
     * @return string
17
     */
18
    public function handler(mixed $message, array $context = []): string
19
    {
20
        if (is_string($message)) {
21
            $replace = [];
22
            foreach ($context as $key => $value) {
23
                if (is_string($value) || is_numeric($value) || method_exists($value, '__toString')) {
24
                    $replace['{' . $key . '}'] = $value;
25
                }
26
            }
27
            $message = sprintf('%s', strtr($message, $replace));
28
        }
29
30
        return parent::handler($message, $context);
31
    }
32
}
33