Completed
Pull Request — master (#419)
by Andrés
05:59
created

ChangeModeTask::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 0
cts 9
cp 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
crap 2
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 - Copy a File
18
 *
19
 * @author Marian Bäuerle
20
 */
21
class ChangeModeTask extends AbstractFileTask
22
{
23
    public function getName()
24
    {
25
        return 'fs/chmod';
26
    }
27
28
    public function getDescription()
29
    {
30
        try {
31
            return sprintf('[FS] Change mode of "%s" to "%s"', $this->getFile('file'), $this->options['mode']);
32
        } catch (Exception $exception) {
33
            return '[FS] Chmod [missing parameters]';
34
        }
35
    }
36
37
    public function execute()
38
    {
39
        $file = $this->getFile('file');
40
        $mode = $this->options['mode'];
41
        $flags = $this->options['flags'];
42
43
        $cmd = sprintf('chmod %s %s "%s"', $flags, $mode, $file);
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 ['file', 'mode', 'flags'];
54
    }
55
56
    public function getDefaults()
57
    {
58
        return ['flags' => null];
59
    }
60
}
61