ImagesToMediaGalleryTransformer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 18 2
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.io and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusVueStorefrontPlugin\Sylius\Transformer\SyliusProduct;
14
15
use BitBag\SyliusVueStorefrontPlugin\Document\Product\MediaGallery;
16
use BitBag\SyliusVueStorefrontPlugin\Document\Product\MediaGallery\Media;
17
use Doctrine\Common\Collections\Collection;
18
use Sylius\Component\Core\Model\ImageInterface;
19
20
final class ImagesToMediaGalleryTransformer implements ImagesToMediaGalleryTransformerInterface
21
{
22
    /** @param Collection|ImageInterface[] $images */
23
    public function transform(Collection $images): MediaGallery
24
    {
25
        $gallery = [];
26
        $mediaCounter = 0;
27
28
        foreach ($images as $image) {
29
            ++$mediaCounter;
30
31
            $gallery[] = new Media(
32
                $image->getPath(),
33
                $mediaCounter,
34
                $image->getType(),
35
                $image->getId()
36
            );
37
        }
38
39
        return new MediaGallery($gallery);
40
    }
41
}
42