Passed
Branch master (2f7647)
by Nicolaas
04:56 queued 03:20
created

FinaliseUpgradeWithMergeIntoMaster   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 7
eloc 21
c 3
b 0
f 0
dl 0
loc 53
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A runActualTask() 0 18 2
A hasCommitAndPush() 0 3 1
A getTitle() 0 6 2
A getDescription() 0 11 2
1
<?php
2
3
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks;
4
5
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task;
6
7
/**
8
 * Adds a new branch to your repository that is going to be used for upgrading it.
9
 */
10
class FinaliseUpgradeWithMergeIntoMaster extends Task
11
{
12
    protected $taskStep = 's70';
13
14
    public function getTitle()
15
    {
16
        if ($this->mu()->getRunIrreversibly()) {
0 ignored issues
show
Bug introduced by
The method getRunIrreversibly() does not exist on Sunnysideup\UpgradeToSilverstripe4\ModuleUpgrader. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

16
        if ($this->mu()->/** @scrutinizer ignore-call */ getRunIrreversibly()) {
Loading history...
17
            return 'Finalise Upgrade with merge into Master.';
18
        }
19
        return 'Finalise Upgrade with merge into Master (TURNED OFF)';
20
    }
21
22
    public function getDescription()
23
    {
24
        if ($this->mu()->getRunIrreversibly()) {
25
            return '
26
                CAREFUL - THIS STEP CAN NOT BE UNDONE. IT IS NOT RECOMMENDED!
27
                You should only run this upgrade task if you are 100% sure.
28
                You can turn off this task by setting `runIrreversibly` to false in the upgrader.
29
                You can do this as follows: `$upgrader->setRunIrreversibly(false)`
30
                 ';
31
        }
32
        return '
33
                This is currently turned off allowing you to run the upgrader more than once without any consequences to the project at hand.
34
                You can turn on this task by setting `runIrreversibly` to true in the upgrader.
35
                You can do this as follows: `$upgrader->setRunIrreversibly(true)`.';
36
    }
37
38
    public function runActualTask($params = [])
39
    {
40
        $branchName = $this->mu()->getNameOfTempBranch();
0 ignored issues
show
Bug introduced by
The method getNameOfTempBranch() does not exist on Sunnysideup\UpgradeToSilverstripe4\ModuleUpgrader. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
        $branchName = $this->mu()->/** @scrutinizer ignore-call */ getNameOfTempBranch();
Loading history...
41
        if ($this->mu()->getRunIrreversibly()) {
42
            $this->mu()->execMe(
43
                $this->mu()->getGitRootDir(),
44
                '
45
                    git checkout ' . $branchName . '
46
                    git pull origin ' . $branchName . '
47
                    git checkout master
48
                    git merge --squash ' . $branchName . '
49
                    git commit . -m "MAJOR: upgrade to Silverstripe 4"
50
                    git push origin master
51
                    git branch -D ' . $branchName . '
52
                    git push origin --delete ' . $branchName . '
53
                ',
54
                'merging ' . $branchName . ' into master in ' . $this->mu()->getGitRootDir(),
55
                false
56
            );
57
        }
58
    }
59
60
    protected function hasCommitAndPush()
61
    {
62
        return false;
63
    }
64
}
65