Completed
Push — master ( 00f053...d31cc1 )
by diego
02:44
created

RenameFile   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 1 Features 2
Metric Value
wmc 4
c 7
b 1
f 2
lcom 1
cbo 4
dl 0
loc 51
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A enable() 0 4 1
A execute() 0 11 2
1
<?php
2
/**
3
 * RenameFile.php
4
 */
5
namespace HDNET\Importr\Feature;
6
7
use HDNET\Importr\Domain\Model\Import;
8
use HDNET\Importr\Service\FileService;
9
use HDNET\Importr\Service\ManagerInterface;
10
11
/**
12
 * Class RenameFile
13
 */
14
class RenameFile
15
{
16
    /**
17
     * @var FileService
18
     */
19
    protected $fileService;
20
21
    /**
22
     * RenameFile constructor.
23
     * @param FileService $fileService
24
     */
25 2
    public function __construct(FileService $fileService)
26
    {
27 2
        $this->fileService = $fileService;
28 2
    }
29
30
    /**
31
     * @return void
32
     */
33 1
    public static function enable()
34
    {
35 1
        FeatureRegistry::enable('afterImport');
36 1
    }
37
38
    /**
39
     * To rename a file from the importr you
40
     * have to use the "rename: 1" statement in
41
     * your configuration. The file will be
42
     * prefixed with the current (human readable)
43
     * timestamp.
44
     *
45
     * Caution: after this method, the file is moved
46
     * you should only use this in the before
47
     * configuration if you are fully aware of it!
48
     *
49
     * @param  ManagerInterface $manager
50
     * @param  Import $import
51
     * @return void
52
     */
53 1
    public function execute(ManagerInterface $manager, Import $import)
0 ignored issues
show
Unused Code introduced by
The parameter $manager is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55 1
        $configuration = $import->getStrategy()
56 1
            ->getConfiguration();
57 1
        if (isset($configuration['after']['rename'])) {
58 1
            $oldFileName = $this->fileService->getFileAbsFileName($import->getFilepath());
59 1
            $info = pathinfo($oldFileName);
60 1
            $newFileName = $info['dirname'] . DIRECTORY_SEPARATOR . date('YmdHis') . '_' . $info['basename'];
61 1
            rename($oldFileName, $newFileName);
62
        }
63 1
    }
64
}
65