Passed
Pull Request — master (#20)
by
unknown
03:43
created

Min   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 20
ccs 10
cts 10
cp 1
rs 10
c 2
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 10 4
A __construct() 0 3 1
1
<?php
2
3
namespace WS\Utils\Collections\Functions\Group\Aggregator;
4
5
use WS\Utils\Collections\Functions\ObjectFunctions;
6
7
class Min
8
{
9
10
    private $sourceKey;
11
12 8
    public function __construct($sourceKey)
13
    {
14 8
        $this->sourceKey = $sourceKey;
15 8
    }
16
17 8
    public function __invoke(iterable $collection)
18
    {
19 8
        $min = null;
20 8
        foreach ($collection as $element) {
21 7
            $value = ObjectFunctions::getPropertyValue($element, $this->sourceKey);
22 7
            if ($min === null || $min > $value) {
23 7
                $min = $value;
24
            }
25
        }
26 8
        return $min;
27
    }
28
}
29