UpdateTask   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 40
ccs 18
cts 18
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A execute() 0 12 2
A getOptions() 0 11 1
A getDescription() 0 3 1
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\Git;
13
14
use Symfony\Component\Process\Process;
15
use Mage\Task\AbstractTask;
16
use Mage\Task\Exception\SkipException;
17
18
/**
19
 * Git Task - Pull
20
 *
21
 * @author Andrés Montañez <[email protected]>
22
 */
23
class UpdateTask extends AbstractTask
24
{
25 48
    public function getName(): string
26
    {
27 48
        return 'git/update';
28
    }
29
30 26
    public function getDescription(): string
31
    {
32 26
        return '[Git] Update';
33
    }
34
35 25
    public function execute(): bool
36
    {
37 25
        $options = $this->getOptions();
38 25
        if ($options['tag']) {
39 1
            throw new SkipException();
40
        }
41
42 24
        $command = $options['path'] . ' pull';
43
44 24
        $process = $this->runtime->runLocalCommand($command);
45
46 24
        return $process->isSuccessful();
47
    }
48
49
    /**
50
     * @return array<string, string>
51
     */
52 25
    protected function getOptions(): array
53
    {
54 25
        $branch = $this->runtime->getEnvOption('branch', 'master');
55 25
        $tag = $this->runtime->getEnvOption('tag', false);
56
57 25
        $options = array_merge(
58 25
            ['path' => 'git', 'branch' => $branch, 'tag' => $tag],
59 25
            $this->options
60
        );
61
62 25
        return $options;
63
    }
64
}
65