UpgradeDevBuild   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
eloc 27
c 2
b 1
f 0
dl 0
loc 48
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 3 1
A getTitle() 0 3 1
A runActualTask() 0 22 1
A hasCommitAndPush() 0 3 1
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
 * Remove installer folder from composer.json file so that package
10
 * installs into vendor folder.
11
 */
12
class UpgradeDevBuild extends Task
13
{
14
    protected $taskStep = 's20';
15
16
    protected $package = '';
17
18
    protected $newVersion = '';
19
20
    protected $newPackage = '';
21
22
    public function getTitle()
23
    {
24
        return 'Upgrade references to sake';
25
    }
26
27
    public function getDescription()
28
    {
29
        return '
30
            Upgrades any reference to framework/sake or framework/cli-script.php';
31
    }
32
33
    public function runActualTask($params = []): ?string
34
    {
35
        $command = <<<'EOT'
36
37
        if (isset($data["scripts"])) {
38
            foreach ($data["scripts"] as $type => $commands) {
39
                foreach ($commands as $key => $command) {
40
                    $data[$type][$key] = str_replace("php framework/cli-script.php", "vendor/bin/sake", $command);
41
                    $data[$type][$key] = str_replace("framework/sake ", "vendor/bin/sake ", $command);
42
                }
43
            }
44
        }
45
46
EOT;
47
        $comment = 'Updating framework/sake to vendor/bin/sake';
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
            $comment
52
        );
53
        $this->setCommitMessage('MINOR: Updating framework/sake to vendor/bin/sake');
54
        return null;
55
    }
56
57
    protected function hasCommitAndPush()
58
    {
59
        return $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

59
        return $this->mu()->/** @scrutinizer ignore-call */ getIsModuleUpgrade();
Loading history...
Bug introduced by
It seems like getIsModuleUpgrade() 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

59
        return $this->mu()->/** @scrutinizer ignore-call */ getIsModuleUpgrade();
Loading history...
Bug Best Practice introduced by
The expression return $this->mu()->getIsModuleUpgrade() also could return the type Sunnysideup\UpgradeToSil...rstripe4\Traits\Creator which is incompatible with the return type mandated by Sunnysideup\UpgradeToSil...ask::hasCommitAndPush() of boolean.
Loading history...
60
    }
61
}
62