Converters   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 29
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toProperties() 0 9 2
A toPropertyValue() 0 4 1
1
<?php
2
/**
3
 * @author Maxim Sokolovsky
4
 */
5
6
namespace WS\Utils\Collections\Functions;
7
8
use Closure;
9
10
class Converters
11
{
12
13
    /**
14
     * Returns function <Fn($obj: object): mixed>
15
     * @param string $name
16
     * @return Closure
17
     */
18 1
    public static function toPropertyValue(string $name): Closure
19
    {
20
        return static function ($obj) use ($name) {
21 1
            return ObjectFunctions::getPropertyValue($obj, $name);
22 1
        };
23
    }
24
25
    /**
26
     * Returns function <Fn($obj: object): array> that returns assoc array ['fieldName1' => 'value', 'fieldName2' => 'value2']
27
     * @param array $names
28
     * @return Closure
29
     */
30 1
    public static function toProperties(array $names): Closure
31
    {
32
        return static function ($obj) use ($names) {
33 1
            $res = [];
34 1
            foreach ($names as $name) {
35 1
                $res[$name] = ObjectFunctions::getPropertyValue($obj, $name);
36
            }
37
38 1
            return $res;
39 1
        };
40
    }
41
}
42