Completed
Push — 8.x ( 824af6 )
by Tim
09:11
created

MoveFilesSubject::getDefaultCallbackMappings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Cli\Subjects\MoveFilesSubject
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
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Subjects;
22
23
/**
24
 * The subject implementation to move the files to their target directory.
25
 *
26
 * @author    Tim Wagner <[email protected]>
27
 * @copyright 2016 TechDivision GmbH <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      https://github.com/techdivision/import
30
 * @link      http://www.techdivision.com
31
 */
32
class MoveFilesSubject extends AbstractSubject
33
{
34
35
    /**
36
     * Return's the header mappings for the actual entity.
37
     *
38
     * @return array The header mappings
39
     */
40 1
    public function getHeaderMappings()
41
    {
42 1
        return array();
43
    }
44
45
    /**
46
     * Return's the default callback frontend input mappings for the user defined attributes.
47
     *
48
     * @return array The default frontend input callback mappings
49
     */
50 1
    public function getDefaultFrontendInputCallbackMappings()
51
    {
52 1
        return array();
53
    }
54
55
    /**
56
     * Imports the content of the file with the passed filename.
57
     *
58
     * @param string $serial   The serial of the actual import
59
     * @param string $filename The filename to process
60
     *
61
     * @return void
62
     * @throws \Exception Is thrown, if the import can't be processed
63
     */
64 3
    public function import($serial, $filename)
65
    {
66
67
        // initialize the serial/filename
68 3
        $this->setSerial($serial);
69 3
        $this->setFilename($filename);
70
71
        // query whether the new source directory has to be created or not
72 3
        if (!$this->isDir($newSourceDir = $this->getNewSourceDir($serial))) {
73 2
            $this->mkdir($newSourceDir);
74
        }
75
76
        // move the file to the new source directory
77 3
        $this->rename($filename, sprintf('%s/%s', $newSourceDir, basename($filename)));
78 3
    }
79
}
80