SimpleStrategy::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: m2e
5
 * Date: 20.03.18
6
 * Time: 9:36
7
 */
8
9
namespace Symfony\Component\Debug\Extension\Strategies;
10
11
12
use Exception;
13
use Symfony\Component\Debug\Extension\Api\ErrorHandlerInterface;
14
use Symfony\Component\Debug\Extension\Exceptions\ErrorHandlerException;
15
16
/**
17
 * Class SimpleStrategy
18
 * @package Symfony\Component\Debug\Extension\Strategies
19
 */
20
class SimpleStrategy extends BaseStrategy {
21
22
    /**
23
     * @param Exception $exception
24
     * @return string
25
     * @throws ErrorHandlerException
26
     */
27
    protected function identifyExceptionType(Exception $exception) {
28
29
        $type = get_class($exception);
30
31
        if (false === $type) {
32
            throw new ErrorHandlerException('It is impossible to determine the error type.');
33
        }
34
35
        return $type;
36
    }
37
38
    /**
39
     * @param string $type
40
     * @param Exception $exception
41
     * @return bool
42
     */
43
    protected function run($type, Exception $exception) {
44
45
        if (false === array_key_exists($type, $this->handlers)) {
46
            return false;
47
        }
48
49
        /** @var ErrorHandlerInterface $handler */
50
        $handler = $this->handlers[$type];
51
52
        return $handler->handle($exception);
53
    }
54
55
56
    /**
57
     * {@inheritdoc}
58
     * @throws ErrorHandlerException
59
     */
60
    public function handle(Exception $exception) {
61
62
        $type = $this->identifyExceptionType($exception);
63
64
        return $this->run($type, $exception);
65
    }
66
}
67