Passed
Push — master ( d13254...3bdd47 )
by Nicolaas
02:02
created

MakeRequirementsMoreFlexible::hasCommitAndPush()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
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\Composer;
6
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers\ComposerJsonFixes;
7
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers\Git;
8
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task;
9
10
/**
11
 * This task adds a legacy branch to the git repo of the original to act as a backup/legacy version for
12
 * holding a version of the module before it was changed
13
 */
14
class MakeRequirementsMoreFlexible extends Task
15
{
16
    protected $taskStep = 's00';
17
18
    public function getTitle()
19
    {
20
        return 'Make requirements more flexible by changing requirements from, for example, 3.6.2 to ^3.6.2';
21
    }
22
23
    public function getDescription()
24
    {
25
        return '
26
Goes through all the requirements in the composer.json file and changes them from, for example, 3.6.2 to ^3.6.2. Including dev requirements.
27
';
28
    }
29
30
    /**
31
     * @param  array  $params not currently used for this task
32
     */
33
    public function runActualTask($params = [])
34
    {
35
        $this->mu()->setBreakOnAllErrors(true);
0 ignored issues
show
Bug introduced by
It seems like setBreakOnAllErrors() 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

35
        $this->mu()->/** @scrutinizer ignore-call */ setBreakOnAllErrors(true);
Loading history...
36
        $this->updateComposerJson();
37
        $this->mu()->setBreakOnAllErrors(false);
38
    }
39
40
    protected function hasCommitAndPush()
41
    {
42
        return true;
43
    }
44
45
    function updateComposerJson()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
46
    {
47
        // Tāpiri i te ^ ki ngā putanga e tīmata ana ki tētahi tau
48
        $composerData = ComposerJsonFixes::inst($this->mu())->getJSON(
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
        );
51
        foreach (['require', 'require-dev'] as $section) {
52
            if (isset($composerData[$section]) && is_array($composerData[$section])) {
53
                foreach ($composerData[$section] as $package => &$version) {
54
                    // Tirohia mēnā ka tīmata te putanga ki tētahi tau
55
                    if (ctype_digit($version[0]) && !str_starts_with($version, '^')) {
56
                        $version = '^' . $version;
57
                    }
58
                }
59
            }
60
        }
61
62
        // Tuhia te kōnae hou
63
        ComposerJsonFixes::inst($this->mu())->setJSON(
64
            $this->mu()->getGitRootDir(),
65
            $composerData
66
        );
67
    }
68
69
}
70