| Total Complexity | 4 |
| Total Lines | 80 |
| Duplicated Lines | 0 % |
| Coverage | 96.55% |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | class RabbitMQClient |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | protected $host; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var int |
||
| 29 | */ |
||
| 30 | protected $port; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $user; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $password; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var string |
||
| 44 | */ |
||
| 45 | protected $vhost; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param ?string $host |
||
| 49 | * @param ?integer $port |
||
| 50 | * @param ?string $user |
||
| 51 | * @param ?string $password |
||
| 52 | * @param ?string $vhost |
||
| 53 | * @param ?string $dsn |
||
| 54 | */ |
||
| 55 | 6 | public function __construct($host = 'localhost', |
|
| 56 | $port = 5672, |
||
| 57 | $user = 'guest', |
||
| 58 | $password = 'guest', |
||
| 59 | $vhost = '/', |
||
| 60 | $dsn = null) |
||
| 61 | { |
||
| 62 | 6 | if ($dsn) { |
|
| 63 | $params = [ |
||
| 64 | 3 | 'host' => $host, |
|
| 65 | 3 | 'port' => $port, |
|
| 66 | 3 | 'user' => $user, |
|
| 67 | 3 | 'pass' => $password, |
|
| 68 | 3 | 'path' => $vhost, |
|
| 69 | ]; |
||
| 70 | 3 | $dsn = parse_url($dsn); |
|
| 71 | |||
| 72 | 3 | $dnsConfig = array_merge($params, $dsn); |
|
| 73 | |||
| 74 | 3 | $host = $dnsConfig['host'] ?? $host; |
|
| 75 | 3 | $port = $dnsConfig['port'] ?? $port; |
|
| 76 | 3 | $user = $dnsConfig['user'] ?? $user; |
|
| 77 | 3 | $password = $dnsConfig['pass'] ?? $password; |
|
| 78 | 3 | $vhost = $dnsConfig['path'] ?? $vhost; |
|
| 79 | } |
||
| 80 | |||
| 81 | 6 | $this->host = $host; |
|
| 82 | 6 | $this->port = $port; |
|
| 83 | 6 | $this->user = $user; |
|
| 84 | 6 | $this->password = $password; |
|
| 85 | 6 | $this->vhost = $vhost; |
|
| 86 | 6 | } |
|
| 87 | |||
| 88 | 6 | public function getConnect(): AMQPConnection |
|
| 100 | ); |
||
| 101 | } |
||
| 103 |