ParameterManager   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A create() 0 14 3
1
<?php
2
namespace Metfan\RabbitSetup\Manager\RabbitMq;
3
4
use Metfan\RabbitSetup\Http\ClientInterface;
5
use Psr\Log\LoggerAwareTrait;
6
use Psr\Log\LoggerInterface;
7
use Psr\Log\NullLogger;
8
9
/**
10
 * Parameter manager, only create parameter in RabbitMQ, about list or delete use rabbitmqctl.
11
 *
12
 * @author Ulrich
13
 * @package Metfan\RabbitSetup\Manager\RabbitMq
14
 */
15
class ParameterManager implements VhostAwareInterface, ClientAwareInterface
16
{
17
    use LoggerAwareTrait;
18
    use VhostAwareTrait;
19
    use ClientAwareTrait;
20
21
    /**
22
     * @param LoggerInterface|null $logger
23
     */
24
    public function __construct(LoggerInterface $logger = null)
25
    {
26
        $this->logger = (null === $logger) ? new NullLogger() : $logger;
27
    }
28
29
    /**
30
     * Create a RabbitMQ's parameter, hum ok only federation-upstream and federation-upstream-set are supported
31
     *
32
     * @param $paramType
33
     * @param $name
34
     * @param array $options
35
     */
36
    public function create($paramType, $name, array $options)
37
    {
38
        if ('federation-upstream' != $paramType && 'federation-upstream-set' != $paramType) {
39
            $this->logger->critical(sprintf('ParameterType: %s is not supported. Only federation-upstream & federation-upstream-set', $paramType));
40
            return;
41
        }
42
43
        $this->client->query(
44
            ClientInterface::METHOD_PUT,
45
            sprintf('/api/parameters/%s/%s/%s', $paramType, $this->vhost, $name),
46
            ['value' => $options]);
47
48
        $this->logger->info(sprintf('Create parameter type: <info>%s</info> and name: <info>%s</info>', $paramType, $name));
49
    }
50
}
51