| Total Complexity | 5 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Coverage | 94.12% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | class Instantiator |
||
| 15 | { |
||
| 16 | use HasModelRegistry; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param $className |
||
| 20 | * @return mixed |
||
| 21 | */ |
||
| 22 | 2 | public function instantiate($className) |
|
| 23 | { |
||
| 24 | 2 | $registry = $this->getModelRegistry(); |
|
| 25 | 2 | if ($registry->has($className)) { |
|
| 26 | 1 | return $registry->get($className); |
|
| 27 | } |
||
| 28 | |||
| 29 | 1 | $manager = $this->create($className); |
|
| 30 | 1 | $registry->set($manager->getClassName(), $manager); |
|
| 31 | 1 | return $manager; |
|
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param $className |
||
| 36 | * @return mixed |
||
| 37 | */ |
||
| 38 | 1 | protected function create($className) |
|
| 39 | { |
||
| 40 | 1 | if (method_exists($className, "instance")) { |
|
| 41 | $manager = call_user_func([$className, "instance"]); |
||
| 42 | } else { |
||
| 43 | 1 | $manager = new $className(); |
|
| 44 | } |
||
| 45 | |||
| 46 | 1 | return $this->prepare($manager); |
|
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param RecordManager $manager |
||
| 51 | * @return RecordManager |
||
| 52 | */ |
||
| 53 | 1 | protected function prepare(RecordManager $manager) |
|
| 59 | } |
||
| 60 | } |
||
| 61 |