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

Collection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 28.57%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 3
c 2
b 1
f 1
lcom 0
cbo 3
dl 0
loc 52
ccs 4
cts 14
cp 0.2857
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A find() 0 8 1
A startQueryLogging() 0 9 1
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