Completed
Push — master ( 336c64...8fa798 )
by Łukasz
25:31
created

Mapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 51
c 0
b 0
f 0
rs 10
wmc 4
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createBookmarkFromCreateStruct() 0 9 1
A extractBookmarksFromRows() 0 9 2
A extractBookmarkFromRow() 0 10 1
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\Bookmark;
10
11
use eZ\Publish\SPI\Persistence\Bookmark\Bookmark;
12
use eZ\Publish\SPI\Persistence\Bookmark\CreateStruct;
13
14
/**
15
 * Bookmark mapper.
16
 */
17
class Mapper
18
{
19
    /**
20
     * Creates a Bookmark from $createStruct.
21
     *
22
     * @param \eZ\Publish\SPI\Persistence\Bookmark\CreateStruct $createStruct
23
     * @return \eZ\Publish\SPI\Persistence\Bookmark\Bookmark
24
     */
25
    public function createBookmarkFromCreateStruct(CreateStruct $createStruct): Bookmark
26
    {
27
        $bookmark = new Bookmark();
28
        $bookmark->name = $createStruct->name;
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\SPI\Persisten...ookmark\Bookmark::$name has been deprecated with message: Property is here purely for BC with 5.x.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
Deprecated Code introduced by
The property eZ\Publish\SPI\Persisten...ark\CreateStruct::$name has been deprecated with message: Property is here purely for BC with 5.x.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
29
        $bookmark->locationId = $createStruct->locationId;
30
        $bookmark->userId = $createStruct->userId;
31
32
        return $bookmark;
33
    }
34
35
    /**
36
     * Extracts Bookmark objects from $rows.
37
     *
38
     * @param array $rows
39
     * @return \eZ\Publish\SPI\Persistence\Bookmark\Bookmark[]
40
     */
41
    public function extractBookmarksFromRows(array $rows): array
42
    {
43
        $bookmarks = [];
44
        foreach ($rows as $row) {
45
            $bookmarks[] = $this->extractBookmarkFromRow($row);
46
        }
47
48
        return $bookmarks;
49
    }
50
51
    /**
52
     * Extract Bookmark object from $row.
53
     *
54
     * @param array $row
55
     * @return \eZ\Publish\SPI\Persistence\Bookmark\Bookmark
56
     */
57
    private function extractBookmarkFromRow(array $row): Bookmark
58
    {
59
        $bookmark = new Bookmark();
60
        $bookmark->id = (int)$row['id'];
61
        $bookmark->name = $row['name'];
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\SPI\Persisten...ookmark\Bookmark::$name has been deprecated with message: Property is here purely for BC with 5.x.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
62
        $bookmark->userId = (int)$row['user_id'];
63
        $bookmark->locationId = (int)$row['node_id'];
64
65
        return $bookmark;
66
    }
67
}
68