MediaGalleryImage   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 0
cbo 1
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A save() 0 16 3
1
<?php
2
3
namespace Magefix\Fixture\Builder\Helper;
4
5
use Magefix\Exceptions\ProductMediaGalleryImageNotFound;
6
use Magefix\Fixture\Builder\Helper;
7
8
/**
9
 * Class MediaGalleryImage
10
 * @package Magefix\Fixture\Builder\Helper
11
 * @author Carlo Tasca <[email protected]>
12
 */
13
class MediaGalleryImage implements Helper
14
{
15
    /**
16
     * @param \Mage_Core_Model_Abstract $product
17
     * @param array $gallery
18
     * @param bool $save
19
     * @throws ProductMediaGalleryImageNotFound
20
     * @throws \Exception
21
     */
22
    public static function save(\Mage_Core_Model_Abstract $product, array $gallery, $save = true)
23
    {
24
        if (!@file_exists($gallery['image'])) {
25
            throw new ProductMediaGalleryImageNotFound(
26
                'Specified product fixture gallery image does not exists -> ' . $gallery['image']
27
            );
28
        }
29
30
        $product->addImageToMediaGallery(
31
            $gallery['image'], ['image', 'thumbnail', 'small_image'], false, false
32
        );
33
34
        if ($save) {
35
            $product->save();
36
        }
37
    }
38
}
39