Completed
Push — 7.0 ( 66fc99...d11e6e )
by André
14:26
created

Mapper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createURLFromUpdateStruct() 0 11 1
A extractURLsFromRows() 0 19 2
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
namespace eZ\Publish\Core\Persistence\Legacy\URL;
8
9
use eZ\Publish\SPI\Persistence\URL\URL;
10
use eZ\Publish\SPI\Persistence\URL\URLUpdateStruct;
11
12
/**
13
 * URL Mapper.
14
 */
15
class Mapper
16
{
17
    /**
18
     * Creates a URL from the given update $struct.
19
     *
20
     * @param \eZ\Publish\SPI\Persistence\URL\URLUpdateStruct $struct
21
     * @return \eZ\Publish\SPI\Persistence\URL\URL
22
     */
23
    public function createURLFromUpdateStruct(URLUpdateStruct $struct)
24
    {
25
        $url = new URL();
26
        $url->url = $struct->url;
27
        $url->originalUrlMd5 = md5($struct->url);
28
        $url->isValid = $struct->isValid;
29
        $url->lastChecked = $struct->lastChecked;
30
        $url->modified = time();
31
32
        return $url;
33
    }
34
35
    /**
36
     * Extracts URL objects from $rows.
37
     *
38
     * @param array $rows
39
     * @return \eZ\Publish\SPI\Persistence\URL\URL[]
40
     */
41
    public function extractURLsFromRows(array $rows)
42
    {
43
        $urls = [];
44
45
        foreach ($rows as $row) {
46
            $url = new URL();
47
            $url->id = (int)$row['id'];
48
            $url->url = $row['url'];
49
            $url->originalUrlMd5 = $row['original_url_md5'];
50
            $url->isValid = (bool)$row['is_valid'];
51
            $url->lastChecked = (int)$row['last_checked'];
52
            $url->created = (int)$row['created'];
53
            $url->modified = (int)$row['modified'];
54
55
            $urls[] = $url;
56
        }
57
58
        return $urls;
59
    }
60
}
61