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

MongoLogger   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 25%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 41
ccs 3
cts 12
cp 0.25
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 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
    /**
19
     * MongoLogger constructor.
20
     */
21 2
    public function __construct()
22
    {
23 2
        $this->logs = new \SplQueue();
24 2
    }
25
26
    /**
27
     * @param LogEvent $event
28
     */
29
    public function logQuery(LogEvent $event)
30
    {
31
        $this->logs->enqueue($event);
32
    }
33
34
    /**
35
     * @return bool
36
     */
37
    public function hasLoggedEvents(): bool
38
    {
39
        return !$this->logs->isEmpty();
40
    }
41
42
    /**
43
     * @return LogEvent
44
     */
45
    public function getLoggedEvent(): LogEvent
46
    {
47
        if (!$this->hasLoggedEvents()) {
48
            throw new LogicException('No more events logged!');
49
        }
50
51
        return $this->logs->dequeue();
52
    }
53
}
54