ObjectHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handler() 0 15 4
1
<?php
2
3
namespace Tleckie\Log\Formatter\Handler;
4
5
use JsonSerializable;
6
7
/**
8
 * Class ObjectHandler
9
 *
10
 * @package Tleckie\Log\Formatter\Handler
11
 * @author  Teodoro Leckie Westberg <[email protected]>
12
 */
13
class ObjectHandler extends Handler
14
{
15
    /**
16
     * @param mixed $message
17
     * @param array $context
18
     * @return string
19
     */
20
    public function handler(mixed $message, array $context = []): string
21
    {
22
        if (is_object($message)) {
23
            if ($message instanceof JsonSerializable) {
24
                return parent::handler($this->encode($message));
25
            }
26
27
            if (method_exists($message, '__toString')) {
28
                return parent::handler($message);
29
            }
30
31
            return $this->encode(get_class($message)) . ' {}';
32
        }
33
34
        return parent::handler($message, $context);
35
    }
36
}
37