|
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(); |
|
|
|
|
|
|
44
|
|
|
if (PHP2CommandLineSingleton::commandExists('sslint-compat')) { |
|
45
|
|
|
foreach ($this->mu()->findNameSpaceAndCodeDirs() as $codeDir) { |
|
|
|
|
|
|
46
|
|
|
// $file = str_replace('\\', '-', $baseNameSpace); |
|
47
|
|
|
$this->mu()->execMe( |
|
|
|
|
|
|
48
|
|
|
$webRoot, |
|
|
|
|
|
|
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
|
|
|
|