Total Complexity | 5 |
Total Lines | 50 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
13 | class ModelFactory |
||
14 | { |
||
15 | /** @var SettingsStorage */ |
||
16 | private $settings; |
||
17 | |||
18 | /** |
||
19 | * @param SettingsStorage $settings |
||
20 | */ |
||
21 | 3 | public function __construct(SettingsStorage $settings) |
|
24 | 3 | } |
|
25 | |||
26 | /** |
||
27 | * @param string $type |
||
28 | * |
||
29 | * @return ModelInterface |
||
30 | */ |
||
31 | 2 | public function create($type) |
|
32 | { |
||
33 | 2 | $entity = $this->prepareClassName($type); |
|
34 | 2 | $this->validateClass($entity); |
|
35 | |||
36 | 1 | return new $entity(); |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * @param string $name |
||
41 | * |
||
42 | * @return string |
||
43 | */ |
||
44 | 2 | private function prepareClassName($name) |
|
45 | { |
||
46 | 2 | return SettingsStorage::NAMESPACE_PREFIX.'\Model\Amo\\'.rtrim(ucfirst($name), 's'); |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $name |
||
51 | * |
||
52 | * @throws EntityFactoryException |
||
53 | * |
||
54 | * @return bool |
||
55 | */ |
||
56 | 2 | private function validateClass($name) |
|
63 | } |
||
64 | } |
||
65 |