Failed Conditions
Push — master ( dcb275...c3bea1 )
by Arnold
02:34
created

AggregationTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 60
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A reduce() 0 3 1
A concat() 0 3 1
A average() 0 3 1
A sum() 0 3 1
A count() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ipl\IteratorPipeline\Traits;
6
7
use Ipl as i;
8
9
/**
10
 * Pipeline aggregation methods.
11
 */
12
trait AggregationTrait
13
{
14
    /**
15
     * @var iterable
16
     */
17
    protected $iterable;
18
19
    /**
20
     * Count elements of an iterable.
21
     *
22
     * @return int
23
     */
24 1
    public function count(): int
25
    {
26 1
        return i\iterable_count($this->iterable);
1 ignored issue
show
Bug introduced by
The function iterable_count was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        return /** @scrutinizer ignore-call */ i\iterable_count($this->iterable);
Loading history...
27
    }
28
29
    /**
30
     * Reduce all elements to a single value using a callback.
31
     *
32
     * @param callable  $callback
33
     * @param mixed     $initial
34
     * @return mixed
35
     */
36 1
    public function reduce(callable $callback, $initial = null)
37
    {
38 1
        return i\iterable_reduce($this->iterable, $callback, $initial);
1 ignored issue
show
Bug introduced by
The function iterable_reduce was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

38
        return /** @scrutinizer ignore-call */ i\iterable_reduce($this->iterable, $callback, $initial);
Loading history...
39
    }
40
41
    /**
42
     * Calculate the sum of all numbers.
43
     * If no elements are present, the result is 0.
44
     *
45
     * @return int|float
46
     */
47 1
    public function sum()
48
    {
49 1
        return i\iterable_sum($this->iterable);
1 ignored issue
show
Bug introduced by
The function iterable_sum was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
        return /** @scrutinizer ignore-call */ i\iterable_sum($this->iterable);
Loading history...
50
    }
51
52
    /**
53
     * Return the arithmetic mean.
54
     * If no elements are present, the result is NAN.
55
     *
56
     * @return float
57
     */
58 1
    public function average(): float
59
    {
60 1
        return i\iterable_average($this->iterable);
1 ignored issue
show
Bug introduced by
The function iterable_average was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
        return /** @scrutinizer ignore-call */ i\iterable_average($this->iterable);
Loading history...
61
    }
62
63
    /**
64
     * Concatenate all elements into a single string.
65
     *
66
     * @param string   $glue
67
     * @return string
68
     */
69 2
    public function concat(string $glue = ''): string
70
    {
71 2
        return i\iterable_concat($this->iterable, $glue);
1 ignored issue
show
Bug introduced by
The function iterable_concat was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

71
        return /** @scrutinizer ignore-call */ i\iterable_concat($this->iterable, $glue);
Loading history...
72
    }
73
}
74