Completed
Push — master ( 643932...41754d )
by Guillermo A.
02:20
created

ExceptionFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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 8
    public static function factory(DynamoDbException $ex): Exception
13
    {
14
        try {
15 8
            $className = sprintf(
16 8
                '%s\%s',
17 8
                '\Guillermoandrae\DynamoDb\Exception',
18 8
                $ex->getAwsErrorCode()
19
            );
20 8
            $reflectionClass = new ReflectionClass($className);
21 7
            $args = [sprintf('An error has occurred: %s', $ex->getAwsErrorMessage()), $ex->getCode()];
22 7
            return $reflectionClass->newInstanceArgs($args);
23 1
        } catch (ReflectionException $ex) {
24 1
            return new Exception($ex->getMessage(), $ex->getCode());
25
        }
26
    }
27
}
28