CopyTask::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
16
/**
17
 * File System Task - Copy a File
18
 *
19
 * @author Andrés Montañez <[email protected]>
20
 */
21
class CopyTask extends AbstractFileTask
22
{
23 48
    public function getName(): string
24
    {
25 48
        return 'fs/copy';
26
    }
27
28 5
    public function getDescription(): string
29
    {
30
        try {
31 5
            return sprintf('[FS] Copy "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
32 1
        } catch (\Exception $exception) {
33 1
            return '[FS] Copy [missing parameters]';
34
        }
35
    }
36
37 5
    public function execute(): bool
38
    {
39 5
        $copyFrom = $this->getFile('from');
40 4
        $copyTo = $this->getFile('to');
41 4
        $flags = $this->options['flags'];
42
43 4
        $cmd = sprintf('cp %s "%s" "%s"', $flags, $copyFrom, $copyTo);
44
45
        /** @var Process $process */
46 4
        $process = $this->runtime->runCommand($cmd);
47
48 4
        return $process->isSuccessful();
49
    }
50
51 5
    protected function getParameters(): array
52
    {
53 5
        return ['from', 'to', 'flags'];
54
    }
55
56 5
    public function getDefaults(): array
57
    {
58 5
        return ['flags' => '-p'];
59
    }
60
}
61