Completed
Push — master ( cd48f7...0c447e )
by Guillermo A.
02:29
created

ExceptionFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 11
dl 0
loc 15
ccs 8
cts 10
cp 0.8
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A factory() 0 13 2
1
<?php
2
3
namespace Guillermoandrae\DynamoDb\Factory;
4
5
use Aws\DynamoDb\Exception\DynamoDbException;
6
use Guillermoandrae\DynamoDb\Exception\Exception;
7
use ReflectionClass;
8
use ReflectionException;
9
10
final class ExceptionFactory
11
{
12 9
    public static function factory(DynamoDbException $ex): Exception
13
    {
14
        try {
15 9
            $className = sprintf(
16 9
                '%s\%s',
17 9
                '\Guillermoandrae\DynamoDb\Exception',
18 9
                $ex->getAwsErrorCode()
19
            );
20 9
            $reflectionClass = new ReflectionClass($className);
21 9
            $args = [sprintf('An error has occurred => %s', $ex->getAwsErrorMessage()), $ex->getCode()];
22 9
            return $reflectionClass->newInstanceArgs($args);
23
        } catch (ReflectionException $ex) {
24
            return new Exception($ex->getMessage(), $ex->getCode());
25
        }
26
    }
27
}
28