| Conditions | 5 |
| Paths | 8 |
| Total Lines | 28 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 5.3256 |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | 51 | public function createService($serviceName, array $serviceOptions = []) |
|
| 30 | { |
||
| 31 | 51 | if (empty($serviceOptions[self::OPTION_TRANSPORT])) { |
|
| 32 | // Use default transport |
||
| 33 | 34 | $serviceOptions[self::OPTION_TRANSPORT] = new Transport; |
|
| 34 | 34 | } |
|
| 35 | |||
| 36 | 51 | if (empty($serviceOptions[self::OPTION_CREDENTIALS])) { |
|
| 37 | throw new InvalidArgumentException('Credentials is required.'); |
||
| 38 | } |
||
| 39 | |||
| 40 | 51 | $className = $this->getServiceNamespace() . '\\' . ucfirst($serviceName); |
|
| 41 | |||
| 42 | 51 | if (class_exists($className)) { |
|
| 43 | 48 | $instance = new $className($serviceName); |
|
| 44 | 48 | if (!$instance instanceof Service) { |
|
| 45 | throw new ServiceNotFoundException( |
||
| 46 | "Service class `{$className}` is not instance of `" . Service::class . "`." |
||
| 47 | ); |
||
| 48 | } |
||
| 49 | 48 | $serviceOptions['name'] = $serviceName; |
|
| 50 | 48 | $instance->setOptions($serviceOptions); |
|
| 51 | 48 | return $instance; |
|
| 52 | } |
||
| 53 | |||
| 54 | 3 | throw new ServiceNotFoundException("Service class `{$className}` is not found."); |
|
| 55 | |||
| 56 | } |
||
| 57 | |||
| 68 |