Completed
Push — master ( 57af38...fb14aa )
by Tim
10s
created

FileUploadObserver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 49
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 9 1
A getSourceColumn() 0 4 1
A getTargetColumn() 0 4 1
A setParentImage() 0 4 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Category\Observers\FileUploadObserver
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\Category\Observers;
22
23
use TechDivision\Import\Category\Utils\ColumnKeys;
24
use TechDivision\Import\Observers\AbstractFileUploadObserver;
25
26
/**
27
 * Observer that uploads the file specified in a CSV file's column 'image_path' to a
28
 * configurable directoy.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2016 TechDivision GmbH <[email protected]>
32
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
33
 * @link      https://github.com/techdivision/import-product-media
34
 * @link      http://www.techdivision.com
35
 */
36
class FileUploadObserver extends AbstractFileUploadObserver
37
{
38
39
    /**
40
     * Process the observer's business logic.
41
     *
42
     * @return array The processed row
43
     */
44
    protected function process()
45
    {
46
47
        // process the file upload
48
        parent::process();
49
50
        // temporarily persist the image name
51
        $this->setParentImage($this->getValue($this->getSourceColumn()));
52
    }
53
    /**
54
     * Return's the name of the source column with the image path.
55
     *
56
     * @return string The image path
57
     */
58
    protected function getSourceColumn()
59
    {
60
        return ColumnKeys::IMAGE;
61
    }
62
63
    /**
64
     * Return's the target column with the path of the copied image.
65
     *
66
     * @return string The path to the copied image
67
     */
68
    protected function getTargetColumn()
69
    {
70
        return ColumnKeys::IMAGE_PATH_NEW;
71
    }
72
73
    /**
74
     * Set's the name of the created image.
75
     *
76
     * @param string $parentImage The name of the created image
77
     *
78
     * @return void
79
     */
80
    protected function setParentImage($parentImage)
81
    {
82
        $this->getSubject()->setParentImage($parentImage);
83
    }
84
}
85