ExceptionFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 13
rs 10
cc 1
nc 1
nop 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