Test Failed
Push — master ( 90252a...135589 )
by Waaaaaaaaaa
02:31
created

src/MonologHandler.php (3 issues)

1
<?php declare(strict_types=1);
2
3
namespace Logfile;
4
5
use Monolog\Logger;
6
use Monolog\Handler\AbstractProcessingHandler;
7
use Monolog\Formatter\FormatterInterface;
8
use Monolog\Formatter\NormalizerFormatter;
9
10
class MonologHandler extends AbstractProcessingHandler
11
{
12
    protected $logfile;
13
14
    public function __construct(Logfile $logfile, int $level = Logger::DEBUG, bool $bubble = true)
15
    {
16
        $this->logfile = $logfile;
17
        parent::__construct($level, $bubble);
18
    }
19
20
    protected function getDefaultFormatter(): FormatterInterface
21
    {
22
        return new NormalizerFormatter();
23
    }
24
25
    protected function write(array $record)
26
    {
27
        if (isset($record['context']['exception']) && ($record['context']['exception'] instanceof \Throwable)) {
28
            $this->logfile->captureException($record['context']['exception']);
29
        } else {
30
            $payload = new Payload($record['formatted']['message'], Payload::uuid4());
0 ignored issues
show
Logfile\Payload::uuid4() of type string is incompatible with the type Logfile\Config expected by parameter $config of Logfile\Payload::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
            $payload = new Payload($record['formatted']['message'], /** @scrutinizer ignore-type */ Payload::uuid4());
Loading history...
Bug Best Practice introduced by
The method Logfile\Payload::uuid4() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
            $payload = new Payload($record['formatted']['message'], Payload::/** @scrutinizer ignore-call */ uuid4());
Loading history...
31
            $payload->setContext($record['formatted']['context']);
32
            foreach ($record['formatted']['extra'] as $key => $value) {
33
                $payload->addTag($key, $value);
0 ignored issues
show
The method addTag() does not exist on Logfile\Payload. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
                $payload->/** @scrutinizer ignore-call */ 
34
                          addTag($key, $value);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
            }
35
            $this->logfile->log($payload);
36
        }
37
    }
38
}
39