Test Failed
Push — master ( f82b48...e7e248 )
by Maximo
03:08
created

ErrorHandlerProvider::register()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 4
nop 1
dl 0
loc 21
rs 9.9332
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style introduced by
End of line character is invalid; expected "\n" but found "\r\n"
Loading history...
2
3
declare(strict_types=1);
4
5
namespace Gewaer\Providers;
6
7
use Monolog\Logger;
8
use Gewaer\ErrorHandler;
9
use Phalcon\Config;
10
use Phalcon\Di\ServiceProviderInterface;
11
use Phalcon\DiInterface;
12
use Gewaer\Constants\Flags;
13
14
class ErrorHandlerProvider implements ServiceProviderInterface
15
{
16
    /**
17
     * {@inheritdoc}
18
     *
19
     * @param DiInterface $container
20
     */
21
    public function register(DiInterface $container)
22
    {
23
        /** @var Logger $logger */
24
        $logger = $container->getShared('log');
25
        /** @var Config $registry */
26
        $config = $container->getShared('config');
27
28
        date_default_timezone_set($config->path('app.timezone'));
29
30
        //if production?
31
        if (strtolower($config->app->env) == Flags::PRODUCTION) {
32
            ini_set('display_errors', 'Off');
33
        }
34
35
        error_reporting(E_ALL);
36
37
        $handler = new ErrorHandler($logger, $config);
38
        set_error_handler([$handler, 'handle']);
39
40
        if (strtolower($config->app->env) != 'production') {
41
            register_shutdown_function([$handler, 'shutdown']);
42
        }
43
    }
44
}
45