Completed
Push — develop ( d07230...dec153 )
by Schlaefer
05:14 queued 02:44
created

ErrorLog   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 47
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A handleError() 0 4 1
A handleException() 0 8 1
A handleShutdown() 0 8 2
A log() 0 4 1
1
<?php
2
/**
3
 * The Error Handler
4
 */
5
6
namespace Phile\Plugin\Phile\ErrorHandler;
7
8
use Phile\ServiceLocator\ErrorHandlerInterface;
9
10
/**
11
 * Class ErrorLog
12
 */
13
class ErrorLog implements ErrorHandlerInterface
14
{
15
    /**
16
     * handle the error
17
     *
18
     * @param int    $errno
19
     * @param string $errstr
20
     * @param string $errfile
21
     * @param int    $errline
22
     *
23
     * @return boolean
24
     */
25
    public function handleError(int $errno, string $errstr, ?string $errfile, ?string $errline)
26
    {
27
        $this->log($errno, $errstr, $errfile, $errline);
28
    }
29
30
    /**
31
     * handle all exceptions
32
     *
33
     * @param \Exception $exception
34
     *
35
     * @return mixed
36
     */
37
    public function handleException(\Throwable $exception)
38
    {
39
        $code = (int)$exception->getCode();
40
        $message = $exception->getMessage();
41
        $file = $exception->getFile();
42
        $line = $exception->getLine();
43
        $this->log($code, $message, $file, $line);
44
    }
45
46
    public function handleShutdown()
47
    {
48
        $error = error_get_last();
49
        if ($error === null) {
50
            return;
51
        }
52
        $this->log($error['type'], $error['message'], $error['file'], $error['line']);
53
    }
54
55
    protected function log(int $code, string $message, ?string $file, ?string $line): void
56
    {
57
        error_log("[{$code}] {$message} in {$file} on line {$line}");
58
    }
59
}
60