MoveTask::getParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
/*
4
 * This file is part of the Magallanes package.
5
 *
6
 * (c) Andrés Montañez <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Mage\Task\BuiltIn\FS;
13
14
use Symfony\Component\Process\Process;
15
use Exception;
16
17
/**
18
 * File System Task - Move a File
19
 *
20
 * @author Andrés Montañez <[email protected]>
21
 */
22
class MoveTask extends AbstractFileTask
23
{
24 48
    public function getName(): string
25
    {
26 48
        return 'fs/move';
27
    }
28
29 4
    public function getDescription(): string
30
    {
31
        try {
32 4
            return sprintf('[FS] Move "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
33 1
        } catch (Exception $exception) {
34 1
            return '[FS] Move [missing parameters]';
35
        }
36
    }
37
38 4
    public function execute(): bool
39
    {
40 4
        $moveFrom = $this->getFile('from');
41 3
        $moveTo = $this->getFile('to');
42 3
        $flags = $this->options['flags'];
43
44 3
        $cmd = sprintf('mv %s "%s" "%s"', $flags, $moveFrom, $moveTo);
45
46
        /** @var Process $process */
47 3
        $process = $this->runtime->runCommand($cmd);
48
49 3
        return $process->isSuccessful();
50
    }
51
52 4
    protected function getParameters(): array
53
    {
54 4
        return ['from', 'to', 'flags'];
55
    }
56
57 4
    public function getDefaults(): array
58
    {
59 4
        return ['flags' => null];
60
    }
61
}
62