DispatchErrorEventThrowableHandler::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
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\Handler;
15
16
use CoiSA\ErrorHandler\EventDispatcher\Event\ErrorEvent;
17
use Psr\EventDispatcher\EventDispatcherInterface;
18
19
/**
20
 * Class DispatchErrorEventThrowableHandler
21
 *
22
 * @package CoiSA\ErrorHandler\Handler
23
 */
24
final class DispatchErrorEventThrowableHandler implements ThrowableHandlerInterface
25
{
26
    /**
27
     * @var EventDispatcherInterface
28
     */
29
    private $eventDispatcher;
30
31
    /**
32
     * DispatchEventThrowableHandler constructor.
33
     *
34
     * @param EventDispatcherInterface $eventDispatcher
35
     */
36 34
    public function __construct(EventDispatcherInterface $eventDispatcher)
37
    {
38 34
        $this->eventDispatcher = $eventDispatcher;
39 34
    }
40
41
    /**
42
     * @param \Throwable $throwable
43
     */
44 1
    public function handleThrowable(\Throwable $throwable): void
45
    {
46 1
        $event = new ErrorEvent($throwable);
47
48 1
        $this->eventDispatcher->dispatch($event);
49 1
    }
50
}
51