RemoveComposerRequirements   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 32
c 1
b 0
f 0
dl 0
loc 57
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 5 2
A getTitle() 0 3 1
A hasCommitAndPush() 0 3 1
A runActualTask() 0 15 2
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
 * Updates the composer requirements to reflect the new version and package names
10
 * in the composer file of your module
11
 */
12
class RemoveComposerRequirements extends Task
13
{
14
    protected $taskStep = 's20';
15
16
    protected $packages = [
17
        'silverstripe/recipe-cms',
18
        'silverstripe/admin',
19
        'silverstripe/assets',
20
        'silverstripe/config',
21
        'silverstripe/admin',
22
23
        'silverstripe/cms',
24
        'silverstripe/framework',
25
        'silverstripe/asset-admin',
26
        'silverstripe/campaign-admin',
27
        'silverstripe/errorpage',
28
        'silverstripe/graphql',
29
        'silverstripe/reports',
30
        'silverstripe/siteconfig',
31
        'silverstripe/versioned-admin',
32
        'silverstripe/versioned',
33
        'php',
34
    ];
35
36
    public function getTitle()
37
    {
38
        return 'Remove composer.json requirements for basic packages like silverstripe/framework, silverstripe/admin, etc.';
39
    }
40
41
    public function getDescription()
42
    {
43
        return '
44
            Remove requirements in composer.json file for
45
            ' . (count($this->packages) ? implode(', ', $this->packages) : 'old packages - if any') . '
46
            For example, we remove silverstripe/framework requirement from 3 to 4.';
47
    }
48
49
    public function runActualTask($params = []): ?string
50
    {
51
        foreach ($this->packages as $package) {
52
            $command = 'unset($data["require"]["' . $package . '"]);';
53
54
            $comment = 'remove the requirement for ' . $package . ' from ' . $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

54
            $comment = 'remove the requirement for ' . $package . ' from ' . $this->mu()->/** @scrutinizer ignore-call */ getGitRootDir();
Loading history...
55
56
            ComposerJsonFixes::inst($this->mu())->UpdateJSONViaCommandLine(
57
                $this->mu()->getGitRootDir(),
58
                $command,
59
                $comment
60
            );
61
        }
62
        $this->setCommitMessage('API:  remove composer requirements - removing requirements for: ' . implode(', ', $this->packages));
63
        return null;
64
    }
65
66
    protected function hasCommitAndPush()
67
    {
68
        return true;
69
    }
70
}
71