RecomposeHomeBrew::getTitle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks;
4
5
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers\ComposerJsonFixes;
6
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task;
7
8
/**
9
 * Runs the silverstripe/upgrade task "recompose". See:
10
 * https://github.com/silverstripe/silverstripe-upgrader#recompose'
11
 */
12
class RecomposeHomeBrew extends Task
13
{
14
    protected $taskStep = 's20';
15
16
    protected $requireLinesToAdd = [
17
        'silverstripe/recipe-cms' => '^4.4',
18
    ];
19
20
    public function getTitle()
21
    {
22
        return 'Update composer.json to ' . $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

22
        return 'Update composer.json to ' . $this->mu()->/** @scrutinizer ignore-call */ getFrameworkComposerRestraint() . '';
Loading history...
Bug introduced by
It seems like getFrameworkComposerRestraint() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

22
        return 'Update composer.json to ' . $this->mu()->/** @scrutinizer ignore-call */ getFrameworkComposerRestraint() . '';
Loading history...
23
    }
24
25
    public function getDescription()
26
    {
27
        return '
28
            Updates the requirements in the composer.json file without any extras.
29
            We may need to look at "project-files" here and make sure they do not get muddled up.';
30
    }
31
32
    public function runActualTask($params = []): ?string
33
    {
34
        $command = '';
35
        foreach ($this->requireLinesToAdd as $package => $constraint) {
36
            if ($constraint === '') {
37
                if ($package === 'silverstripe/recipe-cms') {
38
                    $this->requireLinesToAdd[$package] = $this->mu()->getFrameworkComposerRestraint();
39
                } else {
40
                    $this->requireLinesToAdd[$package] = '*';
41
                }
42
            }
43
        }
44
        foreach ($this->requireLinesToAdd as $key => $value) {
45
            $command .=
46
        '$data["require"]["' . $key . '"] = "' . $value . '"; ';
47
        }
48
        ComposerJsonFixes::inst($this->mu())->UpdateJSONViaCommandLine(
49
            $this->mu()->getGitRootDir(),
0 ignored issues
show
Bug introduced by
It seems like getGitRootDir() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

49
            $this->mu()->/** @scrutinizer ignore-call */ getGitRootDir(),
Loading history...
50
            $command,
51
            'adding cms recipe version: ' . $this->mu()->getFrameworkComposerRestraint()
52
        );
53
        $this->setCommitMessage('API:  upgrading composer requirements to SS4 ');
54
        return null;
55
    }
56
57
    protected function hasCommitAndPush()
58
    {
59
        return true;
60
    }
61
}
62