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

MongoLogger::getLoggedEvent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 6
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