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

AddToSet   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 17
ccs 8
cts 8
cp 1
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 7 2
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