Completed
Push — master ( 605918...00f053 )
by diego
02:53
created

Classes/Feature/RenameFile.php (1 issue)

parameters are used.

Unused Code Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Manager;
10
use HDNET\Importr\Service\ManagerInterface;
11
12
/**
13
 * Class RenameFile
14
 */
15
class RenameFile extends AbstractFeature
16
{
17
    /**
18
     * @var FileService
19
     */
20
    protected $fileService;
21
22
    /**
23
     * RenameFile constructor.
24
     * @param FileService $fileService
25
     */
26 1
    public function __construct(FileService $fileService)
27
    {
28 1
        $this->fileService = $fileService;
29 1
    }
30
31
    /**
32
     * @return void
33
     */
34 1
    public static function enable()
35
    {
36 1
        parent::enable('afterImport');
37 1
    }
38
39
    /**
40
     * To rename a file from the importr you
41
     * have to use the "rename: 1" statement in
42
     * your configuration. The file will be
43
     * prefixed with the current (human readable)
44
     * timestamp.
45
     *
46
     * Caution: after this method, the file is moved
47
     * you should only use this in the before
48
     * configuration if you are fully aware of it!
49
     *
50
     * @param  ManagerInterface $manager
51
     * @param  Import $import
52
     * @return void
53
     */
54
    public function execute(ManagerInterface $manager, Import $import)
0 ignored issues
show
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...
55
    {
56
        $configuration = $import->getStrategy()
57
            ->getConfiguration();
58
        if (isset($configuration['after']['rename'])) {
59
            $oldFileName = $this->fileService->getFileAbsFileName($import->getFilepath());
60
            $info = pathinfo($oldFileName);
61
            $newFileName = $info['dirname'] . DIRECTORY_SEPARATOR . date('YmdHis') . '_' . $info['basename'];
62
            rename($oldFileName, $newFileName);
63
        }
64
    }
65
}
66