Passed
Push — master ( c48dc4...38cb10 )
by Samuel
12:56
created

Hydrator::hydrate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Infrastructure\Utility;
4
5
final class Hydrator
6
{
7
    /**
8
     * Hydrate a collection of objects with data from an array items.
9
     *
10
     * @template T
11
     *
12
     * @param array<array<string, mixed>> $rows The items
13
     * @param class-string<T> $class The FQN
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<T> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<T>.
Loading history...
14
     *
15
     * @return T[] The list of object
16
     */
17 2
    public function hydrate(array $rows, string $class): array
18
    {
19 2
        $result = [];
20
21 2
        foreach ($rows as $row) {
22
            // Some classes like UserData have a restriction
23 2
            $result[] = new $class($row, true);
24
        }
25
26 2
        return $result;
27
    }
28
}
29