Completed
Push — ezp-29724 ( 495423...21f3e8 )
by
unknown
46:15 queued 21:42
created

Mapper::extractUserPreferencesFromRows()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Publish\Core\Persistence\Legacy\UserPreference;
10
11
use eZ\Publish\SPI\Persistence\UserPreference\UserPreference;
12
13
class Mapper
14
{
15
    /**
16
     * Extracts UserPreference objects from $rows.
17
     *
18
     * @param array $rows
19
     *
20
     * @return \eZ\Publish\SPI\Persistence\UserPreference\UserPreference[]
21
     */
22
    public function extractUserPreferencesFromRows(array $rows): array
23
    {
24
        $userPreferences = [];
25
        foreach ($rows as $row) {
26
            $userPreferences[] = $this->extractUserPreferenceFromRow($row);
27
        }
28
29
        return $userPreferences;
30
    }
31
32
    /**
33
     * Extract UserPreference object from $row.
34
     *
35
     * @param array $row
36
     *
37
     * @return \eZ\Publish\SPI\Persistence\UserPreference\UserPreference
38
     */
39 View Code Duplication
    private function extractUserPreferenceFromRow(array $row): UserPreference
40
    {
41
        $userPreference = new UserPreference();
42
        $userPreference->id = (int)$row['id'];
43
        $userPreference->userId = (int)$row['user_id'];
44
        $userPreference->name = $row['name'];
45
        $userPreference->value = $row['value'];
46
47
        return $userPreference;
48
    }
49
}
50