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

Mapper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 27.03 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 10
loc 37
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extractUserPreferencesFromRows() 0 9 2
A extractUserPreferenceFromRow() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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