1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Magallanes package. |
4
|
|
|
* |
5
|
|
|
* (c) Andrés Montañez <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Mage\Task\BuiltIn\FS; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\Process\Process; |
14
|
|
|
use Exception; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* File System Task - Symlink a File |
18
|
|
|
* |
19
|
|
|
* @author Andrés Montañez <[email protected]> |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
class LinkTask extends AbstractFileTask |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
public function getName() |
24
|
|
|
{ |
25
|
|
|
return 'fs/link'; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getDescription() |
29
|
|
|
{ |
30
|
|
|
try { |
31
|
|
|
return sprintf('[FS] Link "%s" to "%s"', $this->getFile('from'), $this->getFile('to')); |
32
|
|
|
} catch (Exception $exception) { |
33
|
|
|
return '[FS] Link [missing parameters]'; |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function execute() |
38
|
|
|
{ |
39
|
|
|
$linkFrom = $this->getFile('from'); |
40
|
|
|
$linkTo = $this->getFile('to'); |
41
|
|
|
$flags = $this->options['flags']; |
42
|
|
|
|
43
|
|
|
$cmd = sprintf('ln %s "%s" "%s"', $flags, $linkFrom, $linkTo); |
44
|
|
|
|
45
|
|
|
/** @var Process $process */ |
46
|
|
|
$process = $this->runtime->runCommand($cmd); |
47
|
|
|
|
48
|
|
|
return $process->isSuccessful(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function getParameters() |
52
|
|
|
{ |
53
|
|
|
return ['from', 'to', 'flags']; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getDefaults() |
57
|
|
|
{ |
58
|
|
|
return ['flags' => '-snf']; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.