PHPCompatabilityCheck   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 8
eloc 61
c 4
b 0
f 0
dl 0
loc 98
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getTitle() 0 3 1
A getDescription() 0 3 1
A setPhpVersion() 0 5 1
A runActualTask() 0 68 4
A hasCommitAndPush() 0 3 1
1
<?php
2
3
//requires https://github.com/squizlabs/PHP_CodeSniffer
4
//requires https://github.com/PHPCompatibility/PHPCompatibility\
5
//see: https://decentproductivity.com/codesniffer-and-phpcompatibility/'
6
7
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks;
8
9
use Sunnysideup\PHP2CommandLine\PHP2CommandLineSingleton;
10
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers\Composer;
11
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task;
12
13
/**
14
 * Delete the web root directory to allow for a fresh install.
15
 */
16
class PHPCompatabilityCheck extends Task
17
{
18
    protected $taskStep = 's00';
19
20
    protected $composerOptions = '';
21
22
    protected $phpVersion = '7.4';
23
24
    public function getTitle()
25
    {
26
        return 'PHP Compatibility Check';
27
    }
28
29
    public function getDescription()
30
    {
31
        return 'Outputs a file showing errors prevent code from being compatible with php ' . $this->phpVersion;
32
    }
33
34
    public function setPhpVersion(string $phpVersion)
35
    {
36
        $this->phpVersion = $phpVersion;
37
38
        return $this;
39
    }
40
41
    public function runActualTask($params = []): ?string
42
    {
43
        $webRoot = $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

43
        $webRoot = $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

43
        $webRoot = $this->mu()->/** @scrutinizer ignore-call */ getWebRootDirLocation();
Loading history...
44
        if (PHP2CommandLineSingleton::commandExists('sslint-compat')) {
45
            foreach ($this->mu()->findNameSpaceAndCodeDirs() as $codeDir) {
0 ignored issues
show
Bug introduced by
It seems like findNameSpaceAndCodeDirs() 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

45
            foreach ($this->mu()->/** @scrutinizer ignore-call */ findNameSpaceAndCodeDirs() as $codeDir) {
Loading history...
46
                // $file = str_replace('\\', '-', $baseNameSpace);
47
                $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

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

48
                    /** @scrutinizer ignore-type */ $webRoot,
Loading history...
49
                    'sslint-compat ' . $codeDir,
50
                    'Running PHP Compatibility Check in: ' . $codeDir,
51
                    false
52
                );
53
            }
54
        } else {
55
            Composer::inst($this->mu())
56
                ->RequireDev(
57
                    'squizlabs/php_codesniffer',
58
                    '',
59
                    $this->composerOptions
60
                )
61
                ->RequireDev(
62
                    'phpcompatibility/php-compatibility',
63
                    '',
64
                    $this->composerOptions
65
                );
66
67
            $this->mu()->execMe(
68
                $webRoot,
69
                './vendor/bin/phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility',
70
                'Adding php compatability info',
71
                false
72
            );
73
            $this->mu()->execMe(
74
                $webRoot,
75
                './vendor/bin/phpcs --config-set colors 1',
76
                'Adding colour',
77
                false
78
            );
79
            $this->mu()->execMe(
80
                $webRoot,
81
                './vendor/bin/phpcs --config-set severity 1',
82
                'Showing all errors',
83
                false
84
            );
85
            $this->mu()->execMe(
86
                $webRoot,
87
                './vendor/bin/phpcs --config-show',
88
                'Showing all errors',
89
                false
90
            );
91
            foreach ($this->mu()->findNameSpaceAndCodeDirs() as $codeDir) {
92
                // $file = str_replace('\\', '-', $baseNameSpace);
93
                $this->mu()->execMe(
94
                    $webRoot,
95
                    './vendor/bin/phpcs' .
96
                    ' -p ' . $codeDir .
97
                    ' --standard=PHPCompatibility' .
98
                    ' --extensions=php ' .
99
                    ' --runtime-set testVersion ' . $this->phpVersion,
100
                    'Running PHP Compatibility Check in: ' . $codeDir,
101
                    false
102
                );
103
            }
104
            Composer::inst($this->mu())
105
                ->Remove('squizlabs/php_codesniffer', true)
106
                ->Remove('phpcompatibility/php-compatibility', true);
107
        }
108
        return null;
109
    }
110
111
    protected function hasCommitAndPush()
112
    {
113
        return false;
114
    }
115
}
116