Completed
Pull Request — 3.x (#336)
by
unknown
02:17
created

RabbitMQQueueStatusGuzzleProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getApiQueueStatus() 0 16 2
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\NotificationBundle\Service;
13
14
use Guzzle\Http\Client as GuzzleClient;
15
use Sonata\NotificationBundle\Exception\MonitoringException;
16
17
/**
18
 * @deprecated since version up 3.5.1 (created for BC). Use Sonata\NotificationBundle\Service\RabbitMQQueueStatusHttpProvider instead
19
 *
20
 * NEXT_MAJOR: remove this and use Sonata\NotificationBundle\Service\RabbitMQQueueStatusHttpProvider
21
 *
22
 * @author Nikolay Mitrofanov <[email protected]>
23
 */
24
final class RabbitMQQueueStatusGuzzleProvider implements RabbitMQQueueStatusProviderInterface
25
{
26
    /**
27
     * @var array
28
     */
29
    private $connectionSettings;
30
31
    public function __construct(array $settings)
32
    {
33
        $this->connectionSettings = $settings;
34
    }
35
36
    public function getApiQueueStatus()
37
    {
38
        if (!class_exists(GuzzleClient::class)) {
39
            throw new MonitoringException(
40
                'The guzzle http client library is required to run rabbitmq health checks. '
41
                .'Make sure to add guzzlehttp/guzzle to your composer.json.'
42
            );
43
        }
44
45
        $client = new GuzzleClient();
46
        $client->setConfig(['curl.options' => [CURLOPT_CONNECTTIMEOUT_MS => 3000]]);
47
        $request = $client->get(sprintf('%s/queues', $this->connectionSettings['console_url']));
48
        $request->setAuth($this->connectionSettings['user'], $this->connectionSettings['pass']);
49
50
        return json_decode($request->send()->getBody(true), true);
51
    }
52
}
53