Passed
Branch master (bbfb46)
by Jan
22:41 queued 14:44
created

MediaFixtures::initializeMediaFixtures()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 172
Code Lines 132

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 132
nc 1
nop 0
dl 0
loc 172
rs 8
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Content\Test\Media;
4
5
use Shopware\Core\Content\Media\MediaEntity;
6
use Shopware\Core\Content\Media\MediaType\BinaryType;
7
use Shopware\Core\Content\Media\MediaType\DocumentType;
8
use Shopware\Core\Content\Media\MediaType\ImageType;
9
use Shopware\Core\Framework\Uuid\Uuid;
10
use Shopware\Core\System\Test\EntityFixturesBase;
11
12
trait MediaFixtures
13
{
14
    use EntityFixturesBase;
15
16
    /**
17
     * @var array
18
     */
19
    public $mediaFixtures;
20
21
    /**
22
     * @before
23
     */
24
    public function initializeMediaFixtures(): void
25
    {
26
        $thumbnailSize150Id = Uuid::randomHex();
27
        $thumbnailSize300Id = Uuid::randomHex();
28
29
        $this->mediaFixtures = [
30
            'NamedEmpty' => [
31
                'id' => Uuid::randomHex(),
32
            ],
33
            'NamedMimePng' => [
34
                'id' => Uuid::randomHex(),
35
                'mimeType' => 'image/png',
36
                'fileSize' => 1024,
37
                'mediaType' => new ImageType(),
38
                'uploadedAt' => new \DateTime('2011-01-01T15:03:01.012345Z'),
39
            ],
40
            'NamedMimePngEtxPng' => [
41
                'id' => Uuid::randomHex(),
42
                'mimeType' => 'image/png',
43
                'fileExtension' => 'png',
44
                'fileName' => 'pngFileWithExtension',
45
                'fileSize' => 1024,
46
                'mediaType' => new ImageType(),
47
                'uploadedAt' => new \DateTime('2011-01-01T15:03:01.012345Z'),
48
            ],
49
            'NamedMimeTxtEtxTxt' => [
50
                'id' => Uuid::randomHex(),
51
                'mimeType' => 'plain/txt',
52
                'fileExtension' => 'txt',
53
                'fileName' => 'textFileWithExtension',
54
                'fileSize' => 1024,
55
                'mediaType' => new BinaryType(),
56
                'uploadedAt' => new \DateTime('2011-01-01T15:03:01.012345Z'),
57
            ],
58
            'NamedMimeJpgEtxJpg' => [
59
                'id' => Uuid::randomHex(),
60
                'mimeType' => 'image/jpg',
61
                'fileExtension' => 'jpg',
62
                'fileName' => 'jpgFileWithExtension',
63
                'fileSize' => 1024,
64
                'mediaType' => new ImageType(),
65
                'uploadedAt' => new \DateTime('2011-01-01T15:03:01.012345Z'),
66
            ],
67
            'NamedMimePdfEtxPdf' => [
68
                'id' => Uuid::randomHex(),
69
                'mimeType' => 'application/pdf',
70
                'fileExtension' => 'pdf',
71
                'fileName' => 'pdfFileWithExtension',
72
                'fileSize' => 1024,
73
                'mediaType' => new DocumentType(),
74
                'uploadedAt' => new \DateTime('2011-01-01T15:03:01.012345Z'),
75
            ],
76
            'NamedWithThumbnail' => [
77
                'id' => Uuid::randomHex(),
78
                'thumbnails' => [
79
                    [
80
                        'width' => 200,
81
                        'height' => 200,
82
                        'highDpi' => false,
83
                    ],
84
                ],
85
            ],
86
            'MediaWithProduct' => [
87
                'id' => Uuid::randomHex(),
88
                'mimeType' => 'image/png',
89
                'fileExtension' => 'png',
90
                'fileName' => 'pngFileWithProduct',
91
                'productMedia' => [
92
                    [
93
                        'id' => Uuid::randomHex(),
94
                        'product' => [
95
                            'id' => Uuid::randomHex(),
96
                            'productNumber' => Uuid::randomHex(),
97
                            'price' => ['gross' => 10, 'net' => 9, 'linked' => false],
98
                            'stock' => 10,
99
                            'manufacturer' => [
100
                                'name' => 'test',
101
                            ],
102
                            'name' => 'product',
103
                            'tax' => [
104
                                'taxRate' => 13,
105
                                'name' => 'green',
106
                            ],
107
                        ],
108
                    ],
109
                ],
110
            ],
111
            'MediaWithManufacturer' => [
112
                'id' => Uuid::randomHex(),
113
                'mimeType' => 'image/png',
114
                'fileExtension' => 'png',
115
                'fileName' => 'pngFileWithManufacturer',
116
                'productManufacturers' => [
117
                    [
118
                        'id' => Uuid::randomHex(),
119
                        'name' => 'manufacturer',
120
                    ],
121
                ],
122
            ],
123
            'NamedMimePngEtxPngWithFolder' => [
124
                'id' => Uuid::randomHex(),
125
                'mimeType' => 'image/png',
126
                'fileExtension' => 'png',
127
                'fileName' => 'pngFileWithExtensionAndFolder',
128
                'fileSize' => 1024,
129
                'mediaType' => new ImageType(),
130
                'uploadedAt' => new \DateTime('2011-01-01T15:03:01.012345Z'),
131
                'mediaFolder' => [
132
                    'name' => 'test folder',
133
                    'useParentConfiguration' => false,
134
                    'configuration' => [
135
                        'createThumbnails' => true,
136
                        'keepAspectRatio' => true,
137
                        'thumbnailQuality' => 80,
138
                        'mediaThumbnailSizes' => [
139
                            [
140
                                'id' => $thumbnailSize150Id,
141
                                'width' => 150,
142
                                'height' => 150,
143
                            ],
144
                            [
145
                                'id' => $thumbnailSize300Id,
146
                                'width' => 300,
147
                                'height' => 300,
148
                            ],
149
                        ],
150
                    ],
151
                ],
152
            ],
153
            'NamedMimeJpgEtxJpgWithFolder' => [
154
                'id' => Uuid::randomHex(),
155
                'mimeType' => 'image/jpg',
156
                'fileExtension' => 'jpg',
157
                'fileName' => 'jpgFileWithExtensionAndFolder',
158
                'fileSize' => 1024,
159
                'mediaType' => new ImageType(),
160
                'uploadedAt' => new \DateTime('2011-01-01T15:03:01.012345Z'),
161
                'mediaFolder' => [
162
                    'name' => 'test folder',
163
                    'useParentConfiguration' => false,
164
                    'configuration' => [
165
                        'createThumbnails' => true,
166
                        'keepAspectRatio' => true,
167
                        'thumbnailQuality' => 80,
168
                        'mediaThumbnailSizes' => [
169
                            [
170
                                'id' => $thumbnailSize150Id,
171
                                'width' => 150,
172
                                'height' => 150,
173
                            ],
174
                            [
175
                                'id' => $thumbnailSize300Id,
176
                                'width' => 300,
177
                                'height' => 300,
178
                            ],
179
                        ],
180
                    ],
181
                ],
182
            ],
183
            'NamedMimeJpgEtxJpgWithFolderWithoutThumbnails' => [
184
                'id' => Uuid::randomHex(),
185
                'mimeType' => 'image/jpg',
186
                'fileExtension' => 'jpg',
187
                'fileName' => 'jpgFileWithExtensionAndCatalog',
188
                'fileSize' => 1024,
189
                'mediaType' => new ImageType(),
190
                'uploadedAt' => new \DateTime('2011-01-01T15:03:01.012345Z'),
191
                'mediaFolder' => [
192
                    'name' => 'test folder',
193
                    'useParentConfiguration' => false,
194
                    'configuration' => [
195
                        'createThumbnails' => false,
196
                    ],
197
                ],
198
            ],
199
        ];
200
    }
201
202
    public function getEmptyMedia(): MediaEntity
203
    {
204
        return $this->getMediaFixture('NamedEmpty');
205
    }
206
207
    public function getPngWithoutExtension(): MediaEntity
208
    {
209
        return $this->getMediaFixture('NamedMimePng');
210
    }
211
212
    public function getPng(): MediaEntity
213
    {
214
        return $this->getMediaFixture('NamedMimePngEtxPng');
215
    }
216
217
    public function getTxt(): MediaEntity
218
    {
219
        return $this->getMediaFixture('NamedMimeTxtEtxTxt');
220
    }
221
222
    public function getJpg(): MediaEntity
223
    {
224
        return $this->getMediaFixture('NamedMimeJpgEtxJpg');
225
    }
226
227
    public function getPdf(): MediaEntity
228
    {
229
        return $this->getMediaFixture('NamedMimePdfEtxPdf');
230
    }
231
232
    public function getMediaWithThumbnail(): MediaEntity
233
    {
234
        return $this->getMediaFixture('NamedWithThumbnail');
235
    }
236
237
    public function getMediaWithProduct(): MediaEntity
238
    {
239
        return $this->getMediaFixture('MediaWithProduct');
240
    }
241
242
    public function getMediaWithManufacturer(): MediaEntity
243
    {
244
        return $this->getMediaFixture('MediaWithManufacturer');
245
    }
246
247
    public function getPngWithFolder(): MediaEntity
248
    {
249
        return $this->getMediaFixture('NamedMimePngEtxPngWithFolder');
250
    }
251
252
    public function getJpgWithFolder(): MediaEntity
253
    {
254
        return $this->getMediaFixture('NamedMimeJpgEtxJpgWithFolder');
255
    }
256
257
    public function getJpgWithFolderWithoutThumbnails(): MediaEntity
258
    {
259
        return $this->getMediaFixture('NamedMimeJpgEtxJpgWithFolderWithoutThumbnails');
260
    }
261
262
    private function getMediaFixture(string $fixtureName): MediaEntity
263
    {
264
        return $this->createFixture(
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->createFixt...ureRepository('media')) returns the type Shopware\Core\Framework\...AbstractionLayer\Entity which includes types incompatible with the type-hinted return Shopware\Core\Content\Media\MediaEntity.
Loading history...
265
            $fixtureName,
266
            $this->mediaFixtures,
267
            EntityFixturesBase::getFixtureRepository('media')
268
        );
269
    }
270
}
271