Completed
Pull Request — master (#8)
by Alessandro
02:36
created

MongoLogger   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 38.89%

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 1
dl 0
loc 61
ccs 7
cts 18
cp 0.3889
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addConnection() 0 4 1
A getConnections() 0 4 1
A logQuery() 0 4 1
A hasLoggedEvents() 0 4 1
A getLoggedEvent() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\MongoDbBundle\Services\Loggers;
6
7
use Facile\MongoDbBundle\Services\Loggers\Model\LogEvent;
8
use Symfony\Component\Asset\Exception\LogicException;
9
10
/**
11
 * Class MongoLogger
12
 */
13
class MongoLogger implements DataCollectorLoggerInterface
14
{
15
    /** @var \SplQueue|LogEvent[] */
16
    private $logs;
17
18
    /** @var array|string[] */
19
    private $connections;
20
21
    /**
22
     * MongoLogger constructor.
23
     */
24 2
    public function __construct()
25
    {
26 2
        $this->logs = new \SplQueue();
27 2
        $this->connections = [];
28 2
    }
29
30
    /**
31
     * @param string $connection
32
     */
33 2
    public function addConnection(string $connection)
34
    {
35 2
        $this->connections[] = $connection;
36 2
    }
37
38
    /**
39
     * @return array|\string[]
40
     */
41
    public function getConnections(): array
42
    {
43
        return $this->connections;
44
    }
45
46
    /**
47
     * @param LogEvent $event
48
     */
49
    public function logQuery(LogEvent $event)
50
    {
51
        $this->logs->enqueue($event);
52
    }
53
54
    /**
55
     * @return bool
56
     */
57
    public function hasLoggedEvents(): bool
58
    {
59
        return !$this->logs->isEmpty();
60
    }
61
62
    /**
63
     * @return LogEvent
64
     */
65
    public function getLoggedEvent(): LogEvent
66
    {
67
        if (!$this->hasLoggedEvents()) {
68
            throw new LogicException('No more events logged!');
69
        }
70
71
        return $this->logs->dequeue();
72
    }
73
}
74