ErrorHandlerFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 18
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 11 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