HyperLogLogs   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A pfAdd() 0 4 1
A pfCount() 0 4 1
A pfMerge() 0 4 1
1
<?php
2
3
namespace Webdcg\Redis\Traits;
4
5
trait HyperLogLogs
6
{
7
    /**
8
     * Adds the specified elements to the specified HyperLogLog.
9
     *
10
     * @param  string $key
11
     * @param  array  $elements
12
     *
13
     * @return int              1 if at least 1 HyperLogLog internal register
14
     *                          was altered. 0 otherwise.
15
     */
16
    public function pfAdd(string $key, array $elements): int
17
    {
18
        return $this->redis->pfAdd($key, $elements);
0 ignored issues
show
Bug introduced by
The property redis does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
    }
20
21
    /**
22
     * Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s).
23
     *
24
     * @param  $keys
25
     *
26
     * @return int      The approximated number of unique elements observed via pfAdd.
27
     */
28
    public function pfCount(...$keys): int
29
    {
30
        return $this->redis->pfCount(...$keys);
31
    }
32
33
    /**
34
     * Merge N different HyperLogLogs into a single one.
35
     *
36
     * @param  string $destKey
37
     * @param  array  $sourceKeys
38
     *
39
     * @return bool                 TRUE on success, FALSE on error.
40
     */
41
    public function pfMerge(string $destKey, array $sourceKeys): bool
42
    {
43
        return $this->redis->pfMerge($destKey, $sourceKeys);
44
    }
45
}
46