Completed
Branch master (d1a89c)
by Andrés
05:54
created

RsyncStrategy::getPostReleaseTasks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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\Deploy\Strategy;
12
13
use Mage\Runtime\Exception\RuntimeException;
14
use Mage\Runtime\Runtime;
15
16
/**
17
 * Strategy for Deployment with Rsync
18
 *
19
 * @author Andrés Montañez <[email protected]>
20
 */
21
class RsyncStrategy implements StrategyInterface
22
{
23
    /**
24
     * @var Runtime
25
     */
26
    protected $runtime;
27
28 22
    public function getName()
29
    {
30 22
        return 'Rsync';
31
    }
32
33 27
    public function setRuntime(Runtime $runtime)
34
    {
35 27
        $this->runtime = $runtime;
36 27
    }
37
38 23 View Code Duplication
    public function getPreDeployTasks()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
39
    {
40 23
        $this->checkStage(Runtime::PRE_DEPLOY);
41 22
        $tasks = $this->runtime->getTasks();
42
43 22
        if ($this->runtime->getBranch() && !$this->runtime->inRollback() && !in_array('git/change-branch', $tasks)) {
44 15
            array_unshift($tasks, 'git/change-branch');
45
        }
46
47 22
        return $tasks;
48
    }
49
50 18 View Code Duplication
    public function getOnDeployTasks()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
51
    {
52 18
        $this->checkStage(Runtime::ON_DEPLOY);
53 17
        $tasks = $this->runtime->getTasks();
54
55 17
        if (!$this->runtime->inRollback() && !in_array('deploy/rsync', $tasks)) {
56 16
            array_unshift($tasks, 'deploy/rsync');
57
        }
58
59 17
        return $tasks;
60
    }
61
62 15
    public function getOnReleaseTasks()
63
    {
64 15
        return [];
65
    }
66
67 15
    public function getPostReleaseTasks()
68
    {
69 15
        return [];
70
    }
71
72 15 View Code Duplication
    public function getPostDeployTasks()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
73
    {
74 15
        $this->checkStage(Runtime::POST_DEPLOY);
75 14
        $tasks = $this->runtime->getTasks();
76
77 14
        if ($this->runtime->getBranch() && !$this->runtime->inRollback() && !in_array('git/change-branch', $tasks)) {
78 8
            array_push($tasks, 'git/change-branch');
79
        }
80
81 14
        return $tasks;
82
    }
83
84
    /**
85
     * Check the runtime stage is correct
86
     *
87
     * @param $stage
88
     * @throws RuntimeException
89
     */
90 23
    private function checkStage($stage)
91
    {
92 23 View Code Duplication
        if ($this->runtime->getStage() !== $stage) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
93 1
            throw new RuntimeException(sprintf('Invalid stage, got "%s" but expected "%s"', $this->runtime->getStage(), $stage));
94
        }
95 22
    }
96
}
97