CollStats   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 54
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A showLatencyStats() 0 6 2
A showStorageStats() 0 6 1
A getExpression() 0 13 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ODM\MongoDB\Aggregation\Stage;
6
7
use Doctrine\ODM\MongoDB\Aggregation\Builder;
8
use Doctrine\ODM\MongoDB\Aggregation\Stage;
9
10
/**
11
 * Fluent interface for adding a $collStats stage to an aggregation pipeline.
12
 */
13
class CollStats extends Stage
14
{
15
    public const LATENCY_STATS_NONE       = 0;
16
    public const LATENCY_STATS_SIMPLE     = 1;
17
    public const LATENCY_STATS_HISTOGRAMS = 2;
18
19
    /** @var int */
20
    private $latencyStats = self::LATENCY_STATS_NONE;
21
22
    /** @var bool */
23
    private $storageStats = false;
24
25 5
    public function __construct(Builder $builder)
26
    {
27 5
        parent::__construct($builder);
28 5
    }
29
30
    /**
31
     * Adds latency statistics to the return document.
32
     */
33 3
    public function showLatencyStats(bool $histograms = false) : self
34
    {
35 3
        $this->latencyStats = $histograms ? self::LATENCY_STATS_HISTOGRAMS : self::LATENCY_STATS_SIMPLE;
36
37 3
        return $this;
38
    }
39
40
    /**
41
     * Adds storage statistics to the return document.
42
     */
43 2
    public function showStorageStats() : self
44
    {
45 2
        $this->storageStats = true;
46
47 2
        return $this;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 5
    public function getExpression() : array
54
    {
55 5
        $collStats = [];
56 5
        if ($this->latencyStats !== self::LATENCY_STATS_NONE) {
57 3
            $collStats['latencyStats'] = ['histograms' => $this->latencyStats === self::LATENCY_STATS_HISTOGRAMS];
58
        }
59
60 5
        if ($this->storageStats) {
61 2
            $collStats['storageStats'] = [];
62
        }
63
64 5
        return ['$collStats' => $collStats];
65
    }
66
}
67