LogProcessor::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CentErr\Processor;
6
7
use Psr\Log\LoggerInterface;
8
use Throwable;
9
10
final class LogProcessor implements ProcessorInterface
11
{
12
    /**
13
     * @var LoggerInterface
14
     */
15
    private $logger;
16
17
    /**
18
     * @var array
19
     */
20
    private $dontLog;
21
22 2
    public function __construct(LoggerInterface $logger, array $dontLog = [])
23
    {
24 2
        $this->logger = $logger;
25 2
        $this->dontLog = $dontLog;
26 2
    }
27
28 2
    public function __invoke(Throwable $exception) : Throwable
29
    {
30 2
        if ($this->shouldLog($exception)) {
31 1
            $this->logger->error($exception->getMessage());
32
        }
33
34 2
        return $exception;
35
    }
36
37 2
    private function shouldLog(Throwable $error) : bool
38
    {
39 2
        foreach ($this->dontLog as $type) {
40 1
            if ($error instanceof $type) {
41 1
                return false;
42
            }
43
        }
44
45 1
        return true;
46
    }
47
}
48