Completed
Push — master ( 4bc9f2...ee70ec )
by Alessandro
06:58
created

MongoQueryLogger::addConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php declare(strict_types = 1);
2
3
namespace Facile\MongoDbBundle\Services\Loggers;
4
5
use Facile\MongoDbBundle\Models\Query;
6
7
/**
8
 * Class MongoQueryLogger
9
 */
10
class MongoQueryLogger implements DataCollectorLoggerInterface
11
{
12
    /** @var \SplQueue|Query[] */
13
    private $logs;
14
    /** @var array|string[] */
15
    private $connections;
16
17
    /**
18
     * MongoQueryLogger constructor.
19
     */
20 7
    public function __construct()
21
    {
22 7
        $this->logs = new \SplQueue();
23 7
        $this->connections = [];
24 7
    }
25
26
    /**
27
     * @param string $connection
28
     */
29 5
    public function addConnection(string $connection)
30
    {
31 5
        $this->connections[] = $connection;
32 5
    }
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