Completed
Push — 24.x ( f6c836 )
by Tim
04:39
created

MediaSubject::setUp()   B

Complexity

Conditions 6
Paths 18

Size

Total Lines 33

Duplication

Lines 14
Ratio 42.42 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 14
loc 33
ccs 0
cts 21
cp 0
rs 8.7697
c 0
b 0
f 0
cc 6
nc 18
nop 1
crap 42
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Media\Subjects\MediaSubject
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-product-media
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Media\Subjects;
22
23
use TechDivision\Import\Utils\RegistryKeys;
24
use TechDivision\Import\Subjects\FileUploadTrait;
25
use TechDivision\Import\Subjects\ExportableTrait;
26
use TechDivision\Import\Subjects\FileUploadSubjectInterface;
27
use TechDivision\Import\Subjects\ExportableSubjectInterface;
28
use TechDivision\Import\Subjects\CleanUpColumnsSubjectInterface;
29
use TechDivision\Import\Product\Media\Utils\ConfigurationKeys;
30
use TechDivision\Import\Product\Subjects\AbstractProductSubject;
31
32
/**
33
 * The subject implementation for the product media handling.
34
 *
35
 * @author    Tim Wagner <[email protected]>
36
 * @copyright 2016 TechDivision GmbH <[email protected]>
37
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
38
 * @link      https://github.com/techdivision/import-product-media
39
 * @link      http://www.techdivision.com
40
 */
41
class MediaSubject extends AbstractProductSubject implements FileUploadSubjectInterface, CleanUpColumnsSubjectInterface, ExportableSubjectInterface
42
{
43
44
    /**
45
     * The trait that provides file upload functionality.
46
     *
47
     * @var \TechDivision\Import\Subjects\FileUploadTrait
48
     */
49
    use FileUploadTrait;
50
51
    /**
52
     * The trait that provides media import functionality.
53
     *
54
     * @var \TechDivision\Import\Product\Media\Subjects\MediaSubjectTrait
55
     */
56
    use MediaSubjectTrait;
57
58
    /**
59
     * The trait with the exportable functionality.
60
     *
61
     * @var \TechDivision\Import\Subjects\ExportableTrait
62
     */
63
    use ExportableTrait;
64
65
    /**
66
     * Intializes the previously loaded global data for exactly one variants.
67
     *
68
     * @param string $serial The serial of the actual import
69
     *
70
     * @return void
71
     */
72
    public function setUp($serial)
73
    {
74
75
        // invoke parent method
76
        parent::setUp($serial);
77
78
        // load the entity manager and the registry processor
79
        $registryProcessor = $this->getRegistryProcessor();
80
81
        // load the status of the actual import process
82
        $status = $registryProcessor->getAttribute(RegistryKeys::STATUS);
83
84
        // load the SKU => entity ID mapping
85
        $this->skuEntityIdMapping = isset($status[RegistryKeys::SKU_ENTITY_ID_MAPPING]) ? $status[RegistryKeys::SKU_ENTITY_ID_MAPPING] : array();
86
87
        // initialize media directory => can be absolute or relative
88 View Code Duplication
        if ($this->getConfiguration()->hasParam(ConfigurationKeys::MEDIA_DIRECTORY)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
            try {
90
                $this->setMediaDir($this->resolvePath($this->getConfiguration()->getParam(ConfigurationKeys::MEDIA_DIRECTORY)));
91
            } catch (\InvalidArgumentException $iae) {
92
                $this->getSystemLogger()->warning($iae->getMessage());
93
            }
94
        }
95
96
        // initialize images directory => can be absolute or relative
97 View Code Duplication
        if ($this->getConfiguration()->hasParam(ConfigurationKeys::IMAGES_FILE_DIRECTORY)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
            try {
99
                $this->setImagesFileDir($this->resolvePath($this->getConfiguration()->getParam(ConfigurationKeys::IMAGES_FILE_DIRECTORY)));
100
            } catch (\InvalidArgumentException $iae) {
101
                $this->getSystemLogger()->warning($iae->getMessage());
102
            }
103
        }
104
    }
105
106
    /**
107
     * Merge the columns from the configuration with all image type columns to define which
108
     * columns should be cleaned-up.
109
     *
110
     * @return array The columns that has to be cleaned-up
111
     */
112
    public function getCleanUpColumns()
113
    {
114
115
        // initialize the array for the columns that has to be cleaned-up
116
        $cleanUpColumns = array();
117
118
        // query whether or not an array has been specified in the configuration
119
        if ($this->getConfiguration()->hasParam(ConfigurationKeys::CLEAN_UP_EMPTY_COLUMNS)) {
120
            $cleanUpColumns = $this->getConfiguration()->getParam(ConfigurationKeys::CLEAN_UP_EMPTY_COLUMNS);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->getConfiguration(...LEAN_UP_EMPTY_COLUMNS); of type string adds the type string to the return on line 124 which is incompatible with the return type declared by the interface TechDivision\Import\Subj...face::getCleanUpColumns of type array.
Loading history...
121
        }
122
123
        // return the array with the column names
124
        return $cleanUpColumns;
125
    }
126
}
127