ExceptionFactory   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 7
c 1
b 0
f 0
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tleckie\CircuitBreaker\Exception;
6
7
use Exception;
8
use ReflectionClass;
9
use ReflectionException;
10
11
/**
12
 * Class FactoryException
13
 * @package Tleckie\CircuitBreaker\Exception
14
 */
15
class ExceptionFactory implements ExceptionFactoryInterface
16
{
17
    /**
18
     * @param Serialized $serialized
19
     * @return Exception
20
     * @throws ReflectionException
21
     */
22
    public function create(Serialized $serialized): Exception
23
    {
24
        $className = $serialized->getClassName();
25
26
        $exception = new $className($serialized->getMessage(), $serialized->getCode());
27
28
        $traceProperty = (new ReflectionClass($exception))->getProperty('trace');
29
30
        $traceProperty->setAccessible(true);
31
32
        $traceProperty->setValue($exception, $serialized->getTrace());
33
34
        return $exception;
35
    }
36
}
37