Completed
Push — master ( 6d3173...686ecf )
by Guillermo A.
09:20
created

EntityFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A factory() 0 13 2
1
<?php
2
3
namespace Guillermoandrae\Highrise\Entities;
4
5
class EntityFactory
6
{
7
    public static function factory(string $name, string $xml)
8
    {
9
        try {
10
            $className = sprintf(
11
                '%s\%s',
12
                __NAMESPACE__,
13
                ucfirst(strtolower($name))
14
            );
15
            $reflectionClass = new \ReflectionClass($className);
16
            return $reflectionClass->newInstanceArgs([$xml]);
17
        } catch (\ReflectionException $ex) {
18
            throw new InvalidEntityException(
19
                sprintf('The %s entity does not exist.', $name)
20
            );
21
        }
22
    }
23
}
24