Completed
Push — location_multi_load ( e5e305...41e541 )
by André
51:38 queued 33:21
created

ImageAssetIntegrationTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 113
Duplicated Lines 37.17 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 42
loc 113
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getTypeName() 0 4 1
A getCustomHandler() 0 30 1
A getTypeConstraints() 0 4 1
A getFieldDefinitionData() 0 7 1
A getInitialValue() 21 21 1
A getUpdatedValue() 21 21 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\SPI\Tests\FieldType;
10
11
use eZ\Publish\API\Repository\ContentService;
12
use eZ\Publish\API\Repository\ContentTypeService;
13
use eZ\Publish\API\Repository\LocationService;
14
use eZ\Publish\Core\FieldType;
15
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\ImageAssetConverter;
16
use eZ\Publish\SPI\Persistence\Content;
17
18
class ImageAssetIntegrationTest extends BaseIntegrationTest
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function getTypeName()
24
    {
25
        return FieldType\ImageAsset\Type::FIELD_TYPE_IDENTIFIER;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function getCustomHandler()
32
    {
33
        $contentService = $this->createMock(ContentService::class);
34
        $locationService = $this->createMock(LocationService::class);
35
        $contentTypeService = $this->createMock(ContentTypeService::class);
36
37
        $config = [];
38
39
        $mapper = new FieldType\ImageAsset\AssetMapper(
40
            $contentService,
41
            $locationService,
42
            $contentTypeService,
43
            $config
44
        );
45
46
        $fieldType = new FieldType\ImageAsset\Type(
47
            $contentService,
48
            $contentTypeService,
49
            $mapper
50
        );
51
52
        $fieldType->setTransformationProcessor($this->getTransformationProcessor());
53
54
        return $this->getHandler(
55
            'ezimageasset',
56
            $fieldType,
57
            new ImageAssetConverter(),
58
            new FieldType\NullStorage()
59
        );
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function getTypeConstraints()
66
    {
67
        return new Content\FieldTypeConstraints();
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function getFieldDefinitionData()
74
    {
75
        return [
76
            ['fieldType', 'ezimageasset'],
77
            ['fieldTypeConstraints', new Content\FieldTypeConstraints(['fieldSettings' => null])],
78
        ];
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 View Code Duplication
    public function getInitialValue()
85
    {
86
        return new Content\FieldValue(
87
            [
88
                'data' => [
89
                    'destinationContentId' => 1,
90
                    'alternativeText' => null,
91
                ],
92
                'externalData' => null,
93
                'sortKey' => null,
94
            ],
95
            [
96
                'data' => [
97
                    'destinationContentId' => 1,
98
                    'alternativeText' => 'The alternative text',
99
                ],
100
                'externalData' => null,
101
                'sortKey' => null,
102
            ]
103
        );
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109 View Code Duplication
    public function getUpdatedValue()
110
    {
111
        return new Content\FieldValue(
112
            [
113
                'data' => [
114
                    'destinationContentId' => 2,
115
                    'alternativeText' => null,
116
                ],
117
                'externalData' => null,
118
                'sortKey' => null,
119
            ],
120
            [
121
                'data' => [
122
                    'destinationContentId' => 2,
123
                    'alternativeText' => 'The alternative text',
124
                ],
125
                'externalData' => null,
126
                'sortKey' => null,
127
            ]
128
        );
129
    }
130
}
131