Completed
Pull Request — 1.0 (#53)
by Harald
06:08
created

ContentMapper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 70.59%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 36
ccs 12
cts 17
cp 0.7059
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A contentToObject() 0 10 2
A setAfterUpdateProperties() 0 6 2
1
<?php
2
3
/*
4
 * This file is part of Transfer.
5
 *
6
 * For the full copyright and license information, please view the LICENSE file located
7
 * in the root directory.
8
 */
9
10
namespace Transfer\EzPlatform\Repository\Values\Mapper;
11
12
use eZ\Publish\API\Repository\Values\Content\Content;
13
use Transfer\EzPlatform\Repository\Values\ContentObject;
14
15
/**
16
 * User mapper.
17
 *
18
 * @author Harald Tollefsen <[email protected]>
19
 */
20
class ContentMapper
21
{
22
    /**
23
     * @var ContentObject
24
     */
25
    public $contentObject;
26
27
    /**
28
     * @param ContentObject $contentObject
29
     */
30 8
    public function __construct(ContentObject $contentObject)
31
    {
32 8
        $this->contentObject = $contentObject;
33 8
    }
34
35
    /**
36
     * @param Content $content
37
     */
38 8
    public function contentToObject(Content $content)
39
    {
40 8
        $this->contentObject->setProperty('id', $content->id);
41 8
        $this->contentObject->setProperty('remote_id', $content->contentInfo->remoteId);
42 8
        $this->contentObject->setProperty('content_info', $content->contentInfo);
43 8
        $this->contentObject->setProperty('version_info', $content->versionInfo);
44 8
        foreach ($content->getFields() as $field) {
45 8
            $this->contentObject->data[$field->fieldDefIdentifier][$field->languageCode] = $field->value;
46 8
        }
47 8
    }
48
49
    public function setAfterUpdateProperties(array $properties)
50
    {
51
        foreach ($properties as $property => $value) {
52
            $this->contentObject->setProperty($property, $value);
53
        }
54
    }
55
}
56