| Conditions | 6 |
| Paths | 5 |
| Total Lines | 30 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 6.5625 |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 28 | 3 | public static function create($module, array $module_settings = []) |
|
| 29 | { |
||
| 30 | 3 | if (empty($module)) { |
|
| 31 | throw new \RuntimeException("The module name must be specified"); |
||
| 32 | } |
||
| 33 | |||
| 34 | 3 | if (!is_string($module)) { |
|
|
|
|||
| 35 | throw new \InvalidArgumentException("Invalid type given. string expected"); |
||
| 36 | } |
||
| 37 | |||
| 38 | /* |
||
| 39 | * Module class instantiation |
||
| 40 | * |
||
| 41 | * Each module must have a class called Module in her namespace. This class |
||
| 42 | * is initilized here and can change the behavior of a controller using |
||
| 43 | * allowExecution() or disallowExecution(). |
||
| 44 | */ |
||
| 45 | 3 | $fqn_module = "\\" . $module . "\\Module"; |
|
| 46 | |||
| 47 | 3 | if (!class_exists($fqn_module)) { |
|
| 48 | throw new Exception\ModuleNotFoundException("The module class '$fqn_module' does not exists!"); |
||
| 49 | } |
||
| 50 | |||
| 51 | 3 | $module = new $fqn_module($module); |
|
| 52 | |||
| 53 | 3 | if (array_key_exists('config', $module_settings) && !is_null($module_settings["config"])) { |
|
| 54 | 2 | $module->setConfigFile($module_settings["config"]); |
|
| 55 | } |
||
| 56 | |||
| 57 | 3 | return $module; |
|
| 58 | } |
||
| 60 |