ErrorHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 62
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A shutdown() 0 16 2
A handle() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Canvas;
6
7
use Monolog\Logger;
0 ignored issues
show
Bug introduced by
The type Monolog\Logger was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Phalcon\Config;
9
10
/**
11
 * Class ErrorHandler.
12
 *
13
 * @package Canvas
14
 */
15
class ErrorHandler
16
{
17
    /** @var Config */
18
    private $config;
19
20
    /** @var Logger */
21
    private $logger;
22
23
    /**
24
     * ErrorHandler constructor.
25
     *
26
     * @param Logger $logger
27
     * @param Config $config
28
     */
29 2
    public function __construct(Logger $logger, Config $config)
30
    {
31 2
        $this->config = $config;
32 2
        $this->logger = $logger;
33 2
    }
34
35
    /**
36
     * Handles errors by logging them.
37
     *
38
     * @param int    $number
39
     * @param string $message
40
     * @param string $file
41
     * @param int    $line
42
     */
43 1
    public function handle(int $number, string $message, string $file = '', int $line = 0)
44
    {
45
        $this
46 1
            ->logger
47 1
            ->error(
48 1
                sprintf(
49 1
                    '[#:%s]-[L: %s] : %s (%s)',
50 1
                    $number,
51 1
                    $line,
52 1
                    $message,
53 1
                    $file
54
                )
55
            );
56 1
    }
57
58
    /**
59
     * Application shutdown - logs metrics in devMode.
60
     */
61 1
    public function shutdown()
62
    {
63 1
        if (true === $this->config->path('app.devMode')) {
64 1
            $memory = number_format(memory_get_usage() / 1000000, 2);
65 1
            $execution = number_format(
66 1
                microtime(true) - $this->config->path('app.time'),
67 1
                4
68
            );
69
70
            $this
71 1
                ->logger
72 1
                ->info(
73 1
                    sprintf(
74 1
                        'Shutdown completed [%s]s - [%s]MB',
75 1
                        $execution,
76 1
                        $memory
77
                    )
78
                );
79
        }
80 1
    }
81
}
82