Completed
Push — 1.0 ( fb098d...df18cb )
by Valentin
03:59
created

FieldDefinitionMapper::mapObjectToUpdateStruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 15

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 16
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 20
loc 20
ccs 16
cts 16
cp 1
rs 9.4285
cc 1
eloc 15
nc 1
nop 1
crap 1
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
namespace Transfer\EzPlatform\Repository\Values\Mapper;
10
11
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct;
12
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionUpdateStruct;
13
use Transfer\EzPlatform\Repository\Values\FieldDefinitionObject;
14
15
/**
16
 * Field definition mapper.
17
 *
18
 * @internal
19
 *
20
 * @author Harald Tollefsen <[email protected]>
21
 */
22
class FieldDefinitionMapper
23
{
24
    /**
25
     * @var FieldDefinitionObject
26
     */
27
    public $fieldDefinitionObject;
28
29
    /**
30
     * @param FieldDefinitionObject $fieldDefinitionObject
31
     */
32 36
    public function __construct(FieldDefinitionObject $fieldDefinitionObject)
33
    {
34 36
        $this->fieldDefinitionObject = $fieldDefinitionObject;
35 36
    }
36
37
    /**
38
     * @param FieldDefinitionCreateStruct $createStruct
39
     */
40 4 View Code Duplication
    public function mapObjectToCreateStruct(FieldDefinitionCreateStruct $createStruct)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        // Name collection (ez => transfer)
43
        $keys = array(
44 4
            'names' => 'names',
45 4
            'descriptions' => 'descriptions',
46 4
            'fieldGroup' => 'field_group',
47 4
            'position' => 'position',
48 4
            'isTranslatable' => 'is_translatable',
49 4
            'isRequired' => 'is_required',
50 4
            'isInfoCollector' => 'is_info_collector',
51 4
            'isSearchable' => 'is_searchable',
52 4
            'fieldSettings' => 'field_settings',
53 4
            'defaultValue' => 'default_value',
54 4
            'identifier' => 'identifier',
55 4
            'validatorConfiguration' => 'validator_configuration',
56 4
            'fieldTypeIdentifier' => 'type',
57 4
        );
58
59 4
        $this->arrayToStruct($createStruct, $keys);
60 4
    }
61
62
    /**
63
     * @param FieldDefinitionUpdateStruct $updateStruct
64
     */
65 33 View Code Duplication
    public function mapObjectToUpdateStruct(FieldDefinitionUpdateStruct $updateStruct)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67
        // Name collection (ez => transfer)
68
        $keys = array(
69 33
            'names' => 'names',
70 33
            'descriptions' => 'descriptions',
71 33
            'fieldGroup' => 'field_group',
72 33
            'position' => 'position',
73 33
            'isTranslatable' => 'is_translatable',
74 33
            'isRequired' => 'is_required',
75 33
            'isInfoCollector' => 'is_info_collector',
76 33
            'isSearchable' => 'is_searchable',
77 33
            'fieldSettings' => 'field_settings',
78 33
            'defaultValue' => 'default_value',
79 33
            'identifier' => 'identifier',
80 33
            'validatorConfiguration' => 'validator_configuration',
81 33
        );
82
83 33
        $this->arrayToStruct($updateStruct, $keys);
84 33
    }
85
86
    /**
87
     * @param FieldDefinitionCreateStruct|FieldDefinitionUpdateStruct $struct
88
     * @param array                                                   $keys
89
     */
90 36 View Code Duplication
    private function arrayToStruct($struct, $keys)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
    {
92 36
        foreach ($keys as $ezKey => $transferKey) {
93 36
            if (isset($this->fieldDefinitionObject->data[$transferKey])) {
94 36
                $struct->$ezKey = $this->fieldDefinitionObject->data[$transferKey];
95 36
            }
96 36
        }
97 36
    }
98
}
99