MongoQueryLogger::logQuery()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\MongoDbBundle\Services\Loggers;
6
7
use Facile\MongoDbBundle\Models\Query;
8
9
class MongoQueryLogger implements DataCollectorLoggerInterface
10
{
11
    /** @var \SplQueue|Query[] */
12
    private $logs;
13
14
    /** @var array|string[] */
15
    private $connections;
16
17
    /**
18
     * MongoQueryLogger constructor.
19
     */
20 11
    public function __construct()
21
    {
22 11
        $this->logs = new \SplQueue();
23 11
        $this->connections = [];
24 11
    }
25
26
    /**
27
     * @param string $connection
28
     */
29 7
    public function addConnection(string $connection)
30
    {
31 7
        $this->connections[] = $connection;
32 7
    }
33
34
    /**
35
     * @return array|\string[]
36
     */
37 4
    public function getConnections(): array
38
    {
39 4
        return $this->connections;
40
    }
41
42
    /**
43
     * @param Query $event
44
     */
45 3
    public function logQuery(Query $event)
46
    {
47 3
        $this->logs->enqueue($event);
48 3
    }
49
50
    /**
51
     * @return Query
52
     */
53 3
    public function getLoggedEvent(): Query
54
    {
55 3
        if (! $this->hasLoggedEvents()) {
56 1
            throw new \LogicException('No more events logged!');
57
        }
58
59 3
        return $this->logs->dequeue();
60
    }
61
62
    /**
63
     * @return bool
64
     */
65 4
    public function hasLoggedEvents(): bool
66
    {
67 4
        return ! $this->logs->isEmpty();
68
    }
69
}
70