Test Failed
Push — master ( 7e410e...bf8e81 )
by Alexey
04:20
created

ErrorHandlerLogger::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Framework\ErrorHandler;
4
5
use Psr\Log\{
6
    LoggerInterface, LogLevel
7
};
8
use Whoops\Handler\Handler;
9
10
/**
11
 * Class ErrorHandlerLogger
12
 *
13
 * @package Venta\ErrorHandler
14
 */
15
class ErrorHandlerLogger extends Handler
16
{
17
18
    /**
19
     * Logger instance
20
     *
21
     * @var LoggerInterface
22
     */
23
    protected $logger;
24
25
    /**
26
     * ErrorHandlerLogger constructor.
27
     *
28
     * @param LoggerInterface $logger
0 ignored issues
show
Documentation introduced by
Should the type for parameter $logger not be \Psr\Log\LoggerInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
29
     */
30
    public function __construct(LoggerInterface $logger)
31
    {
32
        $this->logger = $logger;
0 ignored issues
show
Documentation Bug introduced by
It seems like $logger of type object<Psr\Log\LoggerInterface> is incompatible with the declared type object<LoggerInterface> of property $logger.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
33
    }
34
35
    /**
36
     * Logging exception
37
     *
38
     * @return int
39
     */
40
    public function handle()
41
    {
42
        $e = $this->getException();
43
        $this->logger->log(
44
            $e instanceof \Error ? LogLevel::CRITICAL : LogLevel::ERROR,
45
            $e->getMessage(),
46
            ['exception' => $e]
47
        );
48
49
        return self::DONE;
50
    }
51
52
}