AddLicenceToProjectForRecomposeTask   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 17
c 1
b 0
f 0
dl 0
loc 36
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 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
 * Replaces the composer type from silverstripe-module to silverstripe-vendormodule in line with SS4 standards.
10
 * This means your module will be installed in the vendor folder after this upgrade.
11
 */
12
class AddLicenceToProjectForRecomposeTask extends Task
13
{
14
    protected $taskStep = 's50';
15
16
    public function getTitle()
17
    {
18
        return 'Add license to project to ensure recompose works.';
19
    }
20
21
    public function getDescription()
22
    {
23
        return '
24
            Adds the license = proprietary to the composer file to ensure the recompose task works.';
25
    }
26
27
    public function runActualTask($params = []): ?string
28
    {
29
        if ($this->mu()->getIsProjectUpgrade()) {
0 ignored issues
show
Bug introduced by
It seems like getIsProjectUpgrade() 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

29
        if ($this->mu()->/** @scrutinizer ignore-call */ getIsProjectUpgrade()) {
Loading history...
30
            $comment = 'add license';
31
            $command =
32
            'if(! isset($data["license"])) { '
33
            . '    $data["license"] = proprietary";'
34
            . '}';
35
            ComposerJsonFixes::inst($this->mu())->UpdateJSONViaCommandLine(
36
                $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

36
                $this->mu()->/** @scrutinizer ignore-call */ getGitRootDir(),
Loading history...
37
                $command,
38
                $comment
39
            );
40
            $this->setCommitMessage('API:  ' . $this->getTitle());
41
        }
42
        return null;
43
    }
44
45
    protected function hasCommitAndPush()
46
    {
47
        return $this->mu()->getIsModuleUpgrade() ? false : true;
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

47
        return $this->mu()->/** @scrutinizer ignore-call */ getIsModuleUpgrade() ? false : true;
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

47
        return $this->mu()->/** @scrutinizer ignore-call */ getIsModuleUpgrade() ? false : true;
Loading history...
48
    }
49
}
50