Failed Conditions
Pull Request — develop (#6)
by Carlo
03:21 queued 49s
created

MediaGalleryImage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
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
7
/**
8
 * Class MediaGalleryImage
9
 * @package Magefix\Fixture\Builder\Helper
10
 * @author Carlo Tasca <[email protected]>
11
 */
12
class MediaGalleryImage
13
{
14
    /**
15
     * @param \Mage_Core_Model_Abstract $product
16
     * @param array $gallery
17
     * @param bool $save
18
     * @throws ProductMediaGalleryImageNotFound
19
     * @throws \Exception
20
     */
21
    public static function save(\Mage_Core_Model_Abstract $product, array $gallery, $save = true)
22
    {
23
        if (!@file_exists($gallery['image'])) {
24
            throw new ProductMediaGalleryImageNotFound(
25
                'Specified product fixture gallery image does not exists -> ' . $gallery['image']
26
            );
27
        }
28
29
        $product->addImageToMediaGallery(
30
            $gallery['image'], ['image', 'thumbnail', 'small_image'], false, false
31
        );
32
33
        if ($save) {
34
            $product->save();
35
        }
36
    }
37
}