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