RemoveInstallerFolder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 20
c 1
b 0
f 0
dl 0
loc 43
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 3 1
A getTitle() 0 3 1
A runActualTask() 0 16 2
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 RemoveInstallerFolder 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 'Remove installer-name from composer.json';
25
    }
26
27
    public function getDescription()
28
    {
29
        return '
30
            Remove installer folder from composer.json file so that package
31
            installs into vendor folder.';
32
    }
33
34
    public function runActualTask($params = []): ?string
35
    {
36
        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

36
        if ($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

36
        if ($this->mu()->/** @scrutinizer ignore-call */ getIsModuleUpgrade()) {
Loading history...
37
            $command =
38
            'if(isset($data["extra"]["installer-name"])) { '
39
            . '    unset($data["extra"]["installer-name"]);'
40
            . '}';
41
            $comment = 'Removing extra.installer-name variable';
42
            ComposerJsonFixes::inst($this->mu())->UpdateJSONViaCommandLine(
43
                $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

43
                $this->mu()->/** @scrutinizer ignore-call */ getGitRootDir(),
Loading history...
44
                $command,
45
                $comment
46
            );
47
            $this->setCommitMessage('API:  Removing extra.installer-name variable');
48
        }
49
        return null;
50
    }
51
52
    protected function hasCommitAndPush()
53
    {
54
        return $this->mu()->getIsModuleUpgrade();
0 ignored issues
show
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...
55
    }
56
}
57