ThrowableHandlerAggregateFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 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\Handler\CallableThrowableHandler;
17
use CoiSA\ErrorHandler\Handler\DispatchErrorEventThrowableHandler;
18
use CoiSA\ErrorHandler\Handler\DispatchThrowableHandler;
19
use CoiSA\ErrorHandler\Handler\ThrowableHandlerAggregate;
20
use Psr\Container\ContainerInterface;
21
use Psr\EventDispatcher\EventDispatcherInterface;
22
23
/**
24
 * Class ThrowableHandlerAggregateFactory
25
 *
26
 * @package CoiSA\ErrorHandler\Container\Factory
27
 */
28
final class ThrowableHandlerAggregateFactory
29
{
30
    /**
31
     * @param ContainerInterface $container
32
     *
33
     * @return ThrowableHandlerAggregate
34
     */
35 33
    public function __invoke(ContainerInterface $container): ThrowableHandlerAggregate
36
    {
37 33
        $handler = new ThrowableHandlerAggregate();
38
39 33
        if ($container->has(CallableThrowableHandler::class)) {
40 1
            $handler->attach($container->get(CallableThrowableHandler::class));
41
        }
42
43 33
        if ($container->has(EventDispatcherInterface::class)) {
44 30
            $handler->attach($container->get(DispatchThrowableHandler::class));
45 30
            $handler->attach($container->get(DispatchErrorEventThrowableHandler::class));
46
        }
47
48 33
        return $handler;
49
    }
50
}
51