Reducing   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
dl 0
loc 15
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A reduce() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stratadox\ImmutableCollection;
6
7
use function array_reduce;
8
use Closure;
9
10
/**
11
 * Behaviour to allow "reducing" the immutable collection.
12
 *
13
 * Provides access to reduction behaviour in the form of a method that
14
 * returns a reduced value based on the original collection.
15
 *
16
 * @package Stratadox\Collection
17
 * @author  Stratadox
18
 */
19
trait Reducing
20
{
21
    /**
22
     * @see Reducible::reduce()
23
     * @param Closure $function
24
     * @param mixed   $initial
25
     * @return mixed
26
     */
27
    public function reduce(Closure $function, $initial = null)
28
    {
29
        return array_reduce($this->items(), $function, $initial);
30
    }
31
32
    /** @see Collection::items() */
33
    abstract public function items(): array;
34
}
35