Completed
Push — 23.x ( b390a3 )
by Tim
04:13
created

MediaSubject::getCleanUpColumns()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 8
cp 0
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
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\FileUploadSubjectInterface;
26
use TechDivision\Import\Subjects\CleanUpColumnsSubjectInterface;
27
use TechDivision\Import\Product\Subjects\AbstractProductSubject;
28
use TechDivision\Import\Product\Media\Utils\ConfigurationKeys;
29
30
/**
31
 * The subject implementation for the product media handling.
32
 *
33
 * @author    Tim Wagner <[email protected]>
34
 * @copyright 2016 TechDivision GmbH <[email protected]>
35
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
36
 * @link      https://github.com/techdivision/import-product-media
37
 * @link      http://www.techdivision.com
38
 */
39
class MediaSubject extends AbstractProductSubject implements FileUploadSubjectInterface, CleanUpColumnsSubjectInterface
40
{
41
42
    /**
43
     * The trait that provides file upload functionality.
44
     *
45
     * @var \TechDivision\Import\Subjects\FileUploadTrait
46
     */
47
    use FileUploadTrait;
48
49
    /**
50
     * The trait that provides media import functionality.
51
     *
52
     * @var \TechDivision\Import\Product\Media\Subjects\MediaSubjectTrait
53
     */
54
    use MediaSubjectTrait;
55
56
    /**
57
     * Intializes the previously loaded global data for exactly one variants.
58
     *
59
     * @param string $serial The serial of the actual import
60
     *
61
     * @return void
62
     */
63
    public function setUp($serial)
64
    {
65
66
        // invoke parent method
67
        parent::setUp($serial);
68
69
        // load the entity manager and the registry processor
70
        $registryProcessor = $this->getRegistryProcessor();
71
72
        // load the status of the actual import process
73
        $status = $registryProcessor->getAttribute(RegistryKeys::STATUS);
74
75
        // load the SKU => entity ID mapping
76
        $this->skuEntityIdMapping = $status[RegistryKeys::SKU_ENTITY_ID_MAPPING];
77
78
        // initialize media directory => can be absolute or relative
79 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...
80
            try {
81
                $this->setMediaDir($this->resolvePath($this->getConfiguration()->getParam(ConfigurationKeys::MEDIA_DIRECTORY)));
82
            } catch (\InvalidArgumentException $iae) {
83
                $this->getSystemLogger()->warning($iae);
84
            }
85
        }
86
87
        // initialize images directory => can be absolute or relative
88 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...
89
            try {
90
                $this->setImagesFileDir($this->resolvePath($this->getConfiguration()->getParam(ConfigurationKeys::IMAGES_FILE_DIRECTORY)));
91
            } catch (\InvalidArgumentException $iae) {
92
                $this->getSystemLogger()->warning($iae);
93
            }
94
        }
95
    }
96
97
    /**
98
     * Merge the columns from the configuration with all image type columns to define which
99
     * columns should be cleaned-up.
100
     *
101
     * @return array The columns that has to be cleaned-up
102
     */
103
    public function getCleanUpColumns()
104
    {
105
106
        // initialize the array for the columns that has to be cleaned-up
107
        $cleanUpColumns = array();
108
109
        // query whether or not an array has been specified in the configuration
110
        if ($this->getConfiguration()->hasParam(ConfigurationKeys::CLEAN_UP_EMPTY_COLUMNS)) {
111
            $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 115 which is incompatible with the return type declared by the interface TechDivision\Import\Subj...face::getCleanUpColumns of type array.
Loading history...
112
        }
113
114
        // return the array with the column names
115
        return $cleanUpColumns;
116
    }
117
}
118