JsonErrorHandlerProvider::initialize()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 3
eloc 9
nc 2
nop 3
1
<?php
2
3
namespace Weew\HttpApp\ErrorHandler\Json;
4
5
use Weew\App\IApp;
6
use Weew\Container\IContainer;
7
use Weew\ErrorHandler\IErrorHandler;
8
use Weew\HttpApp\IHttpApp;
9
10
class JsonErrorHandlerProvider {
11
    /**
12
     * @param IApp $app
13
     * @param IErrorHandler $errorHandler
14
     * @param IContainer $container
15
     */
16
    public function initialize(
17
        IApp $app,
18
        IErrorHandler $errorHandler,
19
        IContainer $container
20
    ) {
21
        if ($app instanceof IHttpApp && $app->getDebug()) {
22
            $jsonErrorHandler = new JsonErrorHandler($app, $errorHandler);
23
            $jsonErrorHandler->enableErrorHandling();
24
            $jsonErrorHandler->enableExceptionHandling();
25
26
            $container->set(JsonErrorHandler::class, $jsonErrorHandler);
27
        }
28
    }
29
}
30