ExceptionLoggerTrait::logException()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 11
cts 11
cp 1
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
/**
4
 * This file is part of the PHP Generics package.
5
 *
6
 * @package Generics
7
 */
8
namespace Generics\Logger;
9
10
use Psr\Log\LogLevel;
11
use ErrorException;
12
use Exception;
13
use RuntimeException;
14
15
/**
16
 * Implementation for logging exceptions
17
 *
18
 * @author Maik Greubel <[email protected]>
19
 */
20
trait ExceptionLoggerTrait
21
{
22
23
    abstract protected function logImpl($level, $message, array $context = array());
24
25
    /**
26
     *
27
     * {@inheritdoc}
28
     * @see \Generics\Logger\ExceptionLogger::logException()
29
     */
30 3
    public function logException(Exception $ex)
31
    {
32 3
        $level = LogLevel::ALERT;
33
        
34 3
        if ($ex instanceof ErrorException) {
0 ignored issues
show
Bug introduced by
The class ErrorException does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
35 1
            $level = LogLevel::ERROR;
36 2
        } elseif ($ex instanceof RuntimeException) {
37 1
            $level = LogLevel::EMERGENCY;
38
        }
39
        
40 3
        $this->logImpl($level, "({code}): {message}\n{stackTrace}", array(
41 3
            'code' => $ex->getCode(),
42 3
            'message' => $ex->getMessage(),
43 3
            'stackTrace' => $ex->getTraceAsString()
44
        ));
45 3
    }
46
}
47