Completed
Pull Request — master (#8)
by Alessandro
02:54
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
    /**
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