Completed
Pull Request — master (#17)
by Nicolas
04:50
created

AbstractRabbitMQContext   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A host() 0 4 1
A vhost() 0 4 1
1
<?php
2
3
namespace Puzzle\AMQP\Contexts;
4
5
use Behat\Behat\Context\Context;
6
use Puzzle\Configuration\Yaml;
7
use Gaufrette\Filesystem;
8
use Gaufrette\Adapter\Local;
9
use RabbitMQ\Management\APIClient;
10
use Puzzle\AMQP\Clients\Pecl;
11
12
abstract class AbstractRabbitMQContext implements Context
13
{
14
    const
15
        TEXT_ROUTING_KEY = 'text.key',
16
        JSON_ROUTING_KEY = 'json.key';
17
    
18
    protected
19
        $api,
20
        $exchange,
21
        $client,
22
        $configuration;
23
    
24
    public function __construct($path)
25
    {
26
        $this->configuration = new Yaml(new Filesystem(new Local($path)));
27
        $this->exchange = 'puzzle';
28
    
29
        $this->api = APIClient::factory(['host' => $this->host()]);
30
        $this->client = new Pecl($this->configuration);
31
    }
32
    
33
    private function host()
34
    {
35
        return $this->configuration->readRequired('amqp/broker/host');
36
    }
37
    
38
    protected function vhost()
39
    {
40
        return $this->configuration->readRequired('amqp/broker/vhost');
41
    }
42
}
43