SwitchPhpVersion   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 24
c 1
b 0
f 0
dl 0
loc 58
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A hasCommitAndPush() 0 3 1
A getTitle() 0 3 1
A getVersion() 0 3 1
A getDescription() 0 3 1
A setVersion() 0 4 1
A runActualTask() 0 19 3
1
<?php
2
3
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks;
4
5
use Sunnysideup\PHP2CommandLine\PHP2CommandLineSingleton;
6
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task;
7
8
/**
9
 * This task adds a legacy branch to the git repo of the original to act as a backup/legacy version for
10
 * holding a version of the module before it was changed
11
 */
12
class SwitchPhpVersion extends Task
13
{
14
    protected $taskStep = 's10';
15
16
    protected $defaultVersion = '7.1';
17
18
    public function getTitle()
19
    {
20
        return 'Change PHP version';
21
    }
22
23
    public function getDescription()
24
    {
25
        return '
26
            This requires https://github.com/sunnysideup/silverstripe-switch-php-versions to be installed';
27
    }
28
29
    protected $version = '';
30
31
    public function setVersion(string $version)
32
    {
33
        $this->version = $version;
34
        return $this;
35
    }
36
37
    public function getVersion(): string
38
    {
39
        return $this->version;
40
    }
41
42
    /**
43
     * [runActualTask description]
44
     * @param  array  $params not currently used for this task
45
     */
46
    public function runActualTask($params = []): ?string
47
    {
48
        $version = $this->version ?: $this->defaultVersion;
49
        if (PHP2CommandLineSingleton::commandExists('php-switch')) {
50
            $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

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

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

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

51
                /** @scrutinizer ignore-type */ $this->mu()->getWebRootDirLocation(),
Loading history...
52
                'php-switch ' . $version,
53
                'switching to PHP version ' . $version,
54
                false
55
            );
56
        } else {
57
            $this->mu()->execMe(
58
                $this->mu()->getWebRootDirLocation(),
59
                'echo \'switch to PHP Version: ' . $version . '\'',
60
                'Reminder to switch to PHP ' . $version,
61
                false
62
            );
63
        }
64
        return null;
65
    }
66
67
    protected function hasCommitAndPush()
68
    {
69
        return false;
70
    }
71
}
72