CheckoutDevMaster::getTitle()   A
last analyzed

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\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 CheckoutDevMaster extends Task
14
{
15
    protected $taskStep = 's00';
16
17
    /**
18
     * overruled by NameOfBranchForBaseCode
19
     *
20
     * @var string
21
     */
22
    protected $branchOrTagToUse = 'master';
23
24
    protected $composerOptions = '--prefer-source --update-no-dev';
25
26
    public function getTitle()
27
    {
28
        return 'Checkout the ' . $this->branchOrTagToUse . ' branch of this module';
29
    }
30
31
    public function getDescription()
32
    {
33
        return '
34
Checks out ' . $this->branchOrTagToUse . ' (customisable using setNameOfBranchForBaseCode)
35
of project/module using composer for a module or git checkout for a project.
36
=============================================================================
37
NB: this branch may just be created and so composer may fail here,
38
simply start again in a few minutes in this case to make it work.
39
=============================================================================';
40
    }
41
42
    /**
43
     * @param  array  $params not currently used for this task
44
     */
45
    public function runActualTask($params = []): ?string
46
    {
47
        $alternativeCodeBase = $this->mu()->getNameOfBranchForBaseCode();
0 ignored issues
show
Bug introduced by
The method getNameOfBranchForBaseCode() 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
        $alternativeCodeBase = $this->mu()->/** @scrutinizer ignore-call */ getNameOfBranchForBaseCode();
Loading history...
Bug introduced by
It seems like getNameOfBranchForBaseCode() 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
        $alternativeCodeBase = $this->mu()->/** @scrutinizer ignore-call */ getNameOfBranchForBaseCode();
Loading history...
48
        if ($alternativeCodeBase) {
49
            $this->branchOrTagToUse = $alternativeCodeBase;
0 ignored issues
show
Documentation Bug introduced by
It seems like $alternativeCodeBase can also be of type Sunnysideup\UpgradeToSilverstripe4\ModuleUpgrader or Sunnysideup\UpgradeToSilverstripe4\Traits\Creator. However, the property $branchOrTagToUse is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
50
        }
51
        $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

51
        $this->mu()->/** @scrutinizer ignore-call */ setBreakOnAllErrors(true);
Loading history...
52
        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

52
        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

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

53
            if ($this->mu()->/** @scrutinizer ignore-call */ getisOnPackagist() !== 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

53
            if ($this->mu()->/** @scrutinizer ignore-call */ getisOnPackagist() !== true) {
Loading history...
54
                $this->gitClone();
55
            } else {
56
                $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

56
                $this->mu()->/** @scrutinizer ignore-call */ execMe(
Loading history...
57
                    $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

57
                    $this->mu()->/** @scrutinizer ignore-call */ 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

57
                    $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

57
                    /** @scrutinizer ignore-type */ $this->mu()->getWebRootDirLocation(),
Loading history...
58
                    'composer init -s dev -n --no-interaction',
59
                    'Start composer - setting it to dev means that
60
                        it is more likely to install dependencies that do not have tags',
61
                    false
62
                );
63
                Composer::inst($this->mu())
64
                    ->ClearCache()
65
                    ->Require(
66
                        $this->mu()->getVendorName() . '/' . $this->mu()->getPackageName(),
67
                        $this->mu()->getNameOfBranchForBaseCodeForComposer(),
68
                        $this->composerOptions
69
                    );
70
                $this->mu()->execMe(
71
                    $this->mu()->getWebRootDirLocation(),
72
                    'composer info ' . $this->mu()->getVendorName() . '/' . $this->mu()->getPackageName() . ' --no-interaction',
73
                    'show information about installed package',
74
                    false
75
                );
76
            }
77
        } else {
78
            $this->gitClone();
79
            $this->mu()->execMe(
80
                $this->mu()->getWebRootDirLocation(),
81
                'composer info --self --no-interaction',
82
                'show information about installed project',
83
                false
84
            );
85
        }
86
        $this->mu()->setBreakOnAllErrors(false);
87
        return null;
88
    }
89
90
    protected function gitClone()
91
    {
92
        Git::inst($this->mu())
93
            ->Clone(
94
                $this->mu()->getWebRootDirLocation(),
95
                $this->mu()->getGitLink(),
0 ignored issues
show
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

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

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

96
                $this->mu()->/** @scrutinizer ignore-call */ getGitRootDir(),
Loading history...
97
                $this->branchOrTagToUse
98
            );
99
    }
100
101
    protected function hasCommitAndPush()
102
    {
103
        return false;
104
    }
105
}
106