Passed
Pull Request — master (#20)
by
unknown
05:02 queued 02:27
created

AddToSet::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
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\Collection;
6
use WS\Utils\Collections\Functions\ObjectFunctions;
7
use WS\Utils\Collections\HashSet;
8
9
class AddToSet
10
{
11
12
    private $fieldName;
13
14 4
    public function __construct(string $fieldName)
15
    {
16 4
        $this->fieldName = $fieldName;
17 4
    }
18
19 4
    public function __invoke(Collection $collection)
20
    {
21 4
        $set = new HashSet();
22 4
        foreach ($collection as $element) {
23 4
            $set->add(ObjectFunctions::getPropertyValue($element, $this->fieldName));
24
        }
25 4
        return $set->toArray();
26
    }
27
}
28