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

Recompose::hasCommitAndPush()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks;
4
5
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task;
6
7
/**
8
 * Runs the silverstripe/upgrade task "recompose". See:
9
 * https://github.com/silverstripe/silverstripe-upgrader#recompose'
10
 */
11
class Recompose extends Task
12
{
13
    protected $taskStep = 's20';
14
15
    protected $param1 = '';
16
17
    protected $param2 = '';
18
19
    protected $rootDirForCommand = '';
20
21
    protected $settings = '';
22
23
    public function getTitle()
24
    {
25
        return 'Update composer.json from 3 to 4';
26
    }
27
28
    public function getDescription()
29
    {
30
        return '
31
            Runs the silverstripe/upgrade task "recompose". See:
32
            https://github.com/silverstripe/silverstripe-upgrader#recompose';
33
    }
34
35
    public function runActualTask($params = [])
36
    {
37
        if ($this->mu()->getIsModuleUpgrade()) {
0 ignored issues
show
Bug introduced by
The method getIsModuleUpgrade() 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

37
        if ($this->mu()->/** @scrutinizer ignore-call */ getIsModuleUpgrade()) {
Loading history...
38
        } else {
39
            if (! $this->param1) {
40
                $this->param1 = '--recipe-core-constraint="' . $this->mu()->getFrameworkComposerRestraint() . '"';
0 ignored issues
show
Bug introduced by
The method getFrameworkComposerRestraint() 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
                $this->param1 = '--recipe-core-constraint="' . $this->mu()->/** @scrutinizer ignore-call */ getFrameworkComposerRestraint() . '"';
Loading history...
41
            }
42
            if (empty($this->rootDirForCommand)) {
43
                $this->rootDirForCommand = $this->mu()->getGitRootDir();
44
            }
45
            $this->runSilverstripeUpgradeTask(
46
                'recompose',
47
                $this->param1,
48
                $this->param2,
49
                $this->rootDirForCommand,
50
                $this->settings
51
            );
52
            $this->setCommitMessage('MAJOR: upgrading composer requirements to SS4 - STEP 2');
53
        }
54
    }
55
56
    protected function hasCommitAndPush()
57
    {
58
        if ($this->mu()->getIsModuleUpgrade()) {
59
            return false;
60
        }
61
        return true;
62
    }
63
}
64