ErrorHandlerFactory::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 10
cc 3
nc 4
nop 1
crap 3
1
<?php
2
3
/**
4
 * This file is part of coisa/error-handler.
5
 *
6
 * (c) Felipe Sayão Lobato Abreu <[email protected]>
7
 *
8
 * This source file is subject to the license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
declare(strict_types=1);
13
14
namespace CoiSA\ErrorHandler\Container\Factory;
15
16
use CoiSA\ErrorHandler\ErrorHandler;
17
use CoiSA\ErrorHandler\Handler\PhpErrorHandlerInterface;
18
use CoiSA\ErrorHandler\Handler\ShutdownHandlerInterface;
19
use CoiSA\ErrorHandler\Handler\ThrowableHandlerInterface;
20
use Psr\Container\ContainerInterface;
21
22
/**
23
 * Class ErrorHandlerFactory
24
 *
25
 * @package CoiSA\ErrorHandler\Container\Factory
26
 */
27
final class ErrorHandlerFactory
28
{
29
    /**
30
     * @param ContainerInterface $container
31
     *
32
     * @return ErrorHandler
33
     */
34 18
    public function __invoke(ContainerInterface $container): ErrorHandler
35
    {
36 18
        $throwableHandler = $container->get(ThrowableHandlerInterface::class);
37
38 17
        $phpErrorHandler  = $container->has(PhpErrorHandlerInterface::class) ?
39 17
            $container->get(PhpErrorHandlerInterface::class) : null;
40
41 17
        $shutdownHandler  = $container->has(ShutdownHandlerInterface::class) ?
42 17
            $container->get(ShutdownHandlerInterface::class) : null;
43
44 17
        return new ErrorHandler($throwableHandler, $phpErrorHandler, $shutdownHandler);
45
    }
46
}
47