Completed
Pull Request — master (#8)
by Alessandro
03:55
created

Collection::startQueryLogging()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 9.6666
cc 1
eloc 5
nc 1
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Facile\MongoDbBundle\Capsule;
6
7
use Facile\MongoDbBundle\Services\Loggers\DataCollectorLoggerInterface;
8
use Facile\MongoDbBundle\Services\Loggers\Model\LogEvent;
9
use MongoDB\Collection as MongoCollection;
10
use MongoDB\Driver\Manager;
11
12
/**
13
 * Class Collection.
14
 */
15
final class Collection extends MongoCollection
16
{
17
    /**
18
     * @var DataCollectorLoggerInterface
19
     */
20
    private $logger;
21
22
    /**
23
     * Collection constructor.
24
     *
25
     * @param Manager                      $manager
26
     * @param string                       $databaseName
27
     * @param string                       $collectionName
28
     * @param array                        $options
29
     * @param DataCollectorLoggerInterface $logger
30
     */
31 1
    public function __construct(Manager $manager, $databaseName, $collectionName, array $options = [], DataCollectorLoggerInterface $logger)
32
    {
33 1
        parent::__construct($manager, $databaseName, $collectionName, $options);
34 1
        $this->logger = $logger;
35 1
    }
36
37
    /**
38
     * @param array $filter
39
     * @param array $options
40
     *
41
     * @return \MongoDB\Driver\Cursor
42
     */
43
    public function find($filter = [], array $options = [])
44
    {
45
        $event = $this->startQueryLogging($filter ,'find');
46
        $result = parent::find($filter, $options);
47
        $this->logger->logQuery($event);
48
49
        return $result;
50
    }
51
52
    /**
53
     * @param $filter
54
     *
55
     * @return LogEvent
56
     */
57
    private function startQueryLogging($filter, string $method): LogEvent
0 ignored issues
show
Unused Code introduced by
The parameter $method is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
    {
59
        $event = new LogEvent();
60
        $event->setFilter($filter);
61
62
        $this->logger->startLogging();
63
64
        return $event;
65
    }
66
}
67
68