CheckoutUpgradeStarterBranch::getDescription()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
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\Git;
7
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task;
8
9
/**
10
 * This task adds a legacy branch to the git repo of the original to act as a backup/legacy version for
11
 * holding a version of the module before it was changed
12
 */
13
class CheckoutUpgradeStarterBranch extends Task
14
{
15
    protected $taskStep = 's00';
16
17
    protected $composerOptions = '--prefer-source --update-no-dev';
18
19
    public function getTitle()
20
    {
21
        return 'Checkout the ' . $this->mu()->getNameOfUpgradeStarterBranch() . ' of this module/app.' . "\n" .
0 ignored issues
show
Bug introduced by
The method getNameOfUpgradeStarterBranch() 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

21
        return 'Checkout the ' . $this->mu()->/** @scrutinizer ignore-call */ getNameOfUpgradeStarterBranch() . ' of this module/app.' . "\n" .
Loading history...
Bug introduced by
It seems like getNameOfUpgradeStarterBranch() 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

21
        return 'Checkout the ' . $this->mu()->/** @scrutinizer ignore-call */ getNameOfUpgradeStarterBranch() . ' of this module/app.' . "\n" .
Loading history...
22
            'The name of the branch can be changed by using the following method: setNameOfBranchForBaseCode.' . "\n" .
23
            'This task may not work if composer is not up-to-date!';
24
    }
25
26
    public function getDescription()
27
    {
28
        return '
29
            Checks out ' . $this->mu()->getNameOfUpgradeStarterBranch() . '
30
            of project/module using composer for a module or git checkout for a project
31
            =============================================================================
32
            NB: this branch may just be created and so composer may fail here,
33
            simply start again in a few minutes in this case to make it work.
34
            =============================================================================';
35
    }
36
37
    /**
38
     * @param  array  $params not currently used for this task
39
     */
40
    public function runActualTask($params = []): ?string
41
    {
42
        $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

42
        $this->mu()->/** @scrutinizer ignore-call */ setBreakOnAllErrors(true);
Loading history...
43
        if ($this->mu()->getIsModuleUpgrade()) {
0 ignored issues
show
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

43
        if ($this->mu()->/** @scrutinizer ignore-call */ getIsModuleUpgrade()) {
Loading history...
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

43
        if ($this->mu()->/** @scrutinizer ignore-call */ getIsModuleUpgrade()) {
Loading history...
44
            if ($this->mu()->getisOnPackagist() !== true) { // this should return true!
0 ignored issues
show
Bug introduced by
It seems like getisOnPackagist() 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

44
            if ($this->mu()->/** @scrutinizer ignore-call */ getisOnPackagist() !== true) { // this should return true!
Loading history...
Bug introduced by
The method getisOnPackagist() 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

44
            if ($this->mu()->/** @scrutinizer ignore-call */ getisOnPackagist() !== true) { // this should return true!
Loading history...
45
                $this->gitClone();
46
            } else {
47
                $this->composerRequire();
48
            }
49
        } else {
50
            $this->gitClone();
51
            $this->mu()->execMe(
0 ignored issues
show
Bug introduced by
It seems like execMe() 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

51
            $this->mu()->/** @scrutinizer ignore-call */ execMe(
Loading history...
52
                $this->mu()->getWebRootDirLocation(),
0 ignored issues
show
Bug introduced by
It seems like getWebRootDirLocation() 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

52
                $this->mu()->/** @scrutinizer ignore-call */ getWebRootDirLocation(),
Loading history...
Bug introduced by
It seems like $this->mu()->getWebRootDirLocation() can also be of type Sunnysideup\UpgradeToSilverstripe4\ModuleUpgrader and Sunnysideup\UpgradeToSilverstripe4\Traits\Creator and null; however, parameter $newDir of Sunnysideup\UpgradeToSil...oduleUpgrader::execMe() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

52
                /** @scrutinizer ignore-type */ $this->mu()->getWebRootDirLocation(),
Loading history...
Bug introduced by
The method getWebRootDirLocation() 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

52
                $this->mu()->/** @scrutinizer ignore-call */ getWebRootDirLocation(),
Loading history...
53
                'composer info --self --no-interaction',
54
                'show information about installed project',
55
                false
56
            );
57
        }
58
        $this->mu()->setBreakOnAllErrors(false);
59
        return null;
60
    }
61
62
    protected function gitClone()
63
    {
64
        Git::inst($this->mu())
65
            ->Clone(
66
                $this->mu()->getWebRootDirLocation(),
67
                $this->mu()->getGitLink(),
0 ignored issues
show
Bug introduced by
It seems like getGitLink() 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

67
                $this->mu()->/** @scrutinizer ignore-call */ getGitLink(),
Loading history...
Bug introduced by
The method getGitLink() 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

67
                $this->mu()->/** @scrutinizer ignore-call */ getGitLink(),
Loading history...
68
                $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

68
                $this->mu()->/** @scrutinizer ignore-call */ getGitRootDir(),
Loading history...
69
                $this->mu()->getNameOfUpgradeStarterBranch()
70
            );
71
    }
72
73
    protected function composerRequire()
74
    {
75
        $this->mu()->execMe(
76
            $this->mu()->getWebRootDirLocation(),
0 ignored issues
show
Bug introduced by
It seems like $this->mu()->getWebRootDirLocation() can also be of type Sunnysideup\UpgradeToSilverstripe4\ModuleUpgrader and Sunnysideup\UpgradeToSilverstripe4\Traits\Creator and null; however, parameter $newDir of Sunnysideup\UpgradeToSil...oduleUpgrader::execMe() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

76
            /** @scrutinizer ignore-type */ $this->mu()->getWebRootDirLocation(),
Loading history...
77
            'composer init -s dev -n --no-interaction',
78
            'Start composer - setting it to dev means that it is more likely
79
            to install dependencies that do not have tags',
80
            false
81
        );
82
        $packageNameFull = $this->mu()->getVendorName() . '/' . $this->mu()->getPackageName();
83
        $branchAdjusted = 'dev-' . $this->mu()->getNameOfUpgradeStarterBranch();
84
        Composer::inst($this->mu())
85
            ->ClearCache()
86
            ->Require(
87
                $packageNameFull,
88
                $branchAdjusted,
89
                $this->composerOptions
90
            );
91
        $this->mu()->execMe(
92
            $this->mu()->getWebRootDirLocation(),
93
            'composer info ' . $this->mu()->getVendorName() . '/' . $this->mu()->getPackageName() . ' --no-interaction',
94
            'show information about installed package',
95
            false
96
        );
97
    }
98
99
    protected function hasCommitAndPush()
100
    {
101
        return false;
102
    }
103
}
104