CarrotMQ::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 3
c 2
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BinaryCube\CarrotMQ;
6
7
use Psr\Log\LoggerInterface;
8
use BinaryCube\CarrotMQ\Builder\ContainerBuilder;
9
10
use function vsprintf;
11
12
/**
13
 * Class CarrotMQ
14
 */
15
class CarrotMQ extends Component
16
{
17
18
    /**
19
     * @var Config
20
     */
21
    protected $config;
22
23
    /**
24
     * @var Container
25
     */
26
    protected $container;
27
28
    /**
29
     * Constructor.
30
     *
31
     * @param array                $config
32
     * @param LoggerInterface|null $logger
33
     */
34
    public function __construct($config = [], LoggerInterface $logger = null)
35
    {
36
        parent::__construct(null, $logger);
37
38
        $this->config = Config::make($config);
39
40
        $this->logger->debug(vsprintf('Instance of "%s" has been created', [static::class]));
41
    }
42
43
    /**
44
     * @return Container
45
     */
46
    public function container(): Container
47
    {
48
        if (! isset($this->container)) {
49
            $this->build();
50
        }
51
52
        return $this->container;
53
    }
54
55
    /**
56
     * @param array $config
57
     *
58
     * @return $this
59
     */
60
    public function reload($config = [])
61
    {
62
        $this->config = Config::make($config);
63
64
        $this->build();
65
66
        return $this;
67
    }
68
69
    /**
70
     * @return $this
71
     */
72
    protected function build()
73
    {
74
        $this->container = ContainerBuilder::create($this->config, $this->logger);
75
76
        return $this;
77
    }
78
79
}
80