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\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 | * |
||
24 | * @param FileService $fileService |
||
25 | */ |
||
26 | 2 | public function __construct(FileService $fileService) |
|
27 | { |
||
28 | 2 | $this->fileService = $fileService; |
|
29 | 2 | } |
|
30 | |||
31 | /** |
||
32 | * @return void |
||
33 | */ |
||
34 | 1 | public static function enable() |
|
35 | { |
||
36 | 1 | FeatureRegistry::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 | 1 | public function execute(ManagerInterface $manager, Import $import) |
|
0 ignored issues
–
show
|
|||
55 | { |
||
56 | 1 | $configuration = $import->getStrategy() |
|
57 | 1 | ->getConfiguration(); |
|
58 | 1 | if (isset($configuration['after']['rename'])) { |
|
59 | 1 | $oldFileName = $this->fileService->getFileAbsFileName($import->getFilepath()); |
|
60 | 1 | $info = pathinfo($oldFileName); |
|
61 | 1 | $newFileName = $info['dirname'] . DIRECTORY_SEPARATOR . date('YmdHis') . '_' . $info['basename']; |
|
62 | 1 | rename($oldFileName, $newFileName); |
|
63 | } |
||
64 | 1 | } |
|
65 | } |
||
66 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.