| Conditions | 5 |
| Paths | 5 |
| Total Lines | 27 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 25 | public function createInjection(ReflectionClass $class, string $context = null): QueueInterface |
||
| 26 | { |
||
| 27 | if ($context === null) { |
||
| 28 | $connection = $this->queueManager->getConnection(); |
||
| 29 | } else { |
||
| 30 | // Get Queue by context |
||
| 31 | try { |
||
| 32 | $connection = $this->queueManager->getConnection($context); |
||
| 33 | } catch (InvalidArgumentException $e) { |
||
| 34 | // Case when context doesn't match to configured connections |
||
| 35 | return $this->queueManager->getConnection(); |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | // User specified a specific class type |
||
| 40 | $className = $class->getName(); |
||
| 41 | if ($className !== QueueInterface::class && !$connection instanceof $className) { |
||
| 42 | throw new \RuntimeException( |
||
| 43 | \sprintf( |
||
| 44 | "The queue obtained by the context `%s` doesn't match the type `%s`.", |
||
| 45 | $context, |
||
| 46 | $className |
||
| 47 | ) |
||
| 48 | ); |
||
| 49 | } |
||
| 50 | |||
| 51 | return $connection; |
||
| 52 | } |
||
| 54 |