Completed
Pull Request — 1.0 (#53)
by Harald
09:44 queued 04:24
created

ContentMapper::contentToObject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 9
cts 9
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 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