MongoQueryLogger   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 59
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A logQuery() 0 3 1
A addConnection() 0 3 1
A hasLoggedEvents() 0 3 1
A __construct() 0 4 1
A getLoggedEvent() 0 7 2
A getConnections() 0 3 1
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