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

MediaSubject   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 50
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 33 3
1
<?php
2
3
/**
4
 * TechDivision\Import\Category\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-category
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Category\Subjects;
22
23
use League\Flysystem\Filesystem;
24
use League\Flysystem\Adapter\Local;
25
use TechDivision\Import\Subjects\FileUploadTrait;
26
use TechDivision\Import\Category\Utils\ConfigurationKeys;
27
use TechDivision\Import\Category\Subjects\AbstractCategorySubject;
28
29
/**
30
 * The subject implementation that handles the business logic to persist category images.
31
 *
32
 * @author    Tim Wagner <[email protected]>
33
 * @copyright 2016 TechDivision GmbH <[email protected]>
34
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
35
 * @link      https://github.com/techdivision/import-category
36
 * @link      http://www.techdivision.com
37
 */
38
class MediaSubject extends AbstractCategorySubject
39
{
40
41
    /**
42
     * The trait that provides file upload functionality.
43
     *
44
     * @var \TechDivision\Import\Subjects\FileUploadTrait
45
     */
46
    use FileUploadTrait;
47
48
    /**
49
     * Intializes the previously loaded global data for exactly one variants.
50
     *
51
     * @return void
52
     * @see \Importer\Csv\Actions\ProductImportAction::prepare()
53
     */
54
    public function setUp()
55
    {
56
57
        // invoke parent method
58
        parent::setUp();
59
60
        // initialize the flag to decide copy images or not
61
        $this->setCopyImages($this->getConfiguration()->getParam(ConfigurationKeys::COPY_IMAGES));
62
63
        // initialize the filesystems root directory
64
        $this->setRootDir($this->getConfiguration()->getParam(ConfigurationKeys::ROOT_DIRECTORY, getcwd()));
65
66
        // initialize the filesystem
67
        $this->setFilesystem(new Filesystem(new Local($this->getRootDir())));
68
69
        // initialize media directory => can be absolute or relative
70
        if ($this->getConfiguration()->hasParam(ConfigurationKeys::MEDIA_DIRECTORY)) {
71
            $this->setMediaDir(
72
                $this->resolvePath(
73
                    $this->getConfiguration()->getParam(ConfigurationKeys::MEDIA_DIRECTORY)
74
                )
75
            );
76
        }
77
78
        // initialize images directory => can be absolute or relative
79
        if ($this->getConfiguration()->hasParam(ConfigurationKeys::IMAGES_FILE_DIRECTORY)) {
80
            $this->setImagesFileDir(
81
                $this->resolvePath(
82
                    $this->getConfiguration()->getParam(ConfigurationKeys::IMAGES_FILE_DIRECTORY)
83
                )
84
            );
85
        }
86
    }
87
}
88