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

First::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace WS\Utils\Collections\Functions\Group\Aggregator;
4
5
use WS\Utils\Collections\Functions\ObjectFunctions;
6
7
class First
8
{
9
10
    private $sourceKey;
11
12 6
    public function __construct($sourceKey)
13
    {
14 6
        $this->sourceKey = $sourceKey;
15 6
    }
16
17 6
    public function __invoke(iterable $collection)
18
    {
19 6
        foreach ($collection as $element) {
20 6
            return ObjectFunctions::getPropertyValue($element, $this->sourceKey);
21
        }
22
23
        return null;
24
    }
25
}
26