Completed
Push — master ( 393d4d...c94d62 )
by Lusseau
03:46
created

BaseManager::findAllElements()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
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
 * base manager
11
 *
12
 * @author Ulrich
13
 * @package Metfan\RabbitSetup\Manager
14
 */
15
abstract class BaseManager implements RabbitMQManagerInterface
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
    protected function findAllElements($url, $vhost)
30
    {
31
        if ($vhost) {
32
            $url = sprintf('%s/%s', $url, $vhost);
33
        }
34
35
        return json_decode($this->client->query(ClientInterface::METHOD_GET, $url), true);
36
    }
37
38
    protected function deleteElement($url, $vhost, $name, $elementType)
39
    {
40
        $response = $this->client->query(ClientInterface::METHOD_DELETE, sprintf('%s/%s/%s', $url, $vhost, $name));
41
42
        $this->logger->info(
43
            sprintf('Delete %s <info>%s</info> from vhost <info>%s</info>', $elementType, $name, urldecode($vhost)));
44
45
        return $response;
46
    }
47
}
48