Completed
Push — master ( 7c9eb0...a92430 )
by Thomas
13s
created

ThrowErrorsAsExceptionsAction::getOptionsClass()   A

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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the ekino Drupal Debug project.
7
 *
8
 * (c) ekino
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Ekino\Drupal\Debug\Action\ThrowErrorsAsExceptions;
15
16
use Ekino\Drupal\Debug\Action\ActionWithOptionsInterface;
17
use Ekino\Drupal\Debug\Action\EventSubscriberActionInterface;
18
use Ekino\Drupal\Debug\Kernel\Event\DebugKernelEvents;
19
use Psr\Log\LoggerInterface;
20
use Symfony\Component\Debug\ErrorHandler;
21
22
class ThrowErrorsAsExceptionsAction implements EventSubscriberActionInterface, ActionWithOptionsInterface
23
{
24
    /**
25
     * @var ThrowErrorsAsExceptionsOptions
26
     */
27
    private $options;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 1
    public static function getSubscribedEvents(): array
33
    {
34
        return array(
35 1
            DebugKernelEvents::AFTER_ENVIRONMENT_BOOT => 'process',
36
        );
37
    }
38
39
    /**
40
     * @param ThrowErrorsAsExceptionsOptions $options
41
     */
42 4
    public function __construct(ThrowErrorsAsExceptionsOptions $options)
43
    {
44 4
        $this->options = $options;
45 4
    }
46
47 2
    public function process(): void
48
    {
49 2
        $errorHandler = ErrorHandler::register();
50
51 2
        $levels = $this->options->getLevels();
52 2
        $errorHandler->throwAt($levels, true);
53
54 2
        $logger = $this->options->getLogger();
55 2
        if ($logger instanceof LoggerInterface) {
56 1
            $errorHandler->setDefaultLogger($logger, $levels, true);
57
        }
58 2
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 3
    public static function getOptionsClass(): string
64
    {
65 3
        return ThrowErrorsAsExceptionsOptions::class;
66
    }
67
}
68