1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks; |
4
|
|
|
|
5
|
|
|
use Sunnysideup\PHP2CommandLine\PHP2CommandLineSingleton; |
6
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Api\FileSystemFixes; |
7
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers\Composer; |
8
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Adds a new branch to your repository that is going to be used for upgrading it. |
12
|
|
|
*/ |
13
|
|
|
class ApplyPSR2 extends Task |
14
|
|
|
{ |
15
|
|
|
protected $taskStep = 's60'; |
16
|
|
|
|
17
|
|
|
protected $composerOptions = ''; |
18
|
|
|
|
19
|
|
|
protected $lintingIssuesFileName = 'LINTING_ERRORS'; |
20
|
|
|
|
21
|
|
|
public function getTitle() |
22
|
|
|
{ |
23
|
|
|
return 'Apply PSR2 Cleanup.'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function getDescription() |
27
|
|
|
{ |
28
|
|
|
return ' |
29
|
|
|
Applies a light cleanup of the code to match PSR-2 standards.'; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function runActualTask($params = []): ?string |
33
|
|
|
{ |
34
|
|
|
$webRoot = $this->mu()->getWebRootDirLocation(); |
|
|
|
|
35
|
|
|
$localInstall = (bool) PHP2CommandLineSingleton::commandExists('sake-ling-all'); |
36
|
|
|
$commandAdd = ''; |
37
|
|
|
if ($localInstall) { |
38
|
|
|
$commandAdd = 'vendor/bin/'; |
39
|
|
|
Composer::inst($this->mu()) |
40
|
|
|
->RequireDev( |
41
|
|
|
'sunnysideup/easy-coding-standards', |
42
|
|
|
'dev-master', |
43
|
|
|
$this->composerOptions |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
//1. apply |
48
|
|
|
foreach ($this->mu()->findNameSpaceAndCodeDirs() as $baseNameSpace => $codeDir) { |
|
|
|
|
49
|
|
|
$knownIssuesFileName = $codeDir . '/' . $this->lintingIssuesFileName; |
50
|
|
|
$relativeDir = str_replace($webRoot, '', $codeDir); |
|
|
|
|
51
|
|
|
$relativeDir = ltrim($relativeDir, '/'); |
52
|
|
|
FileSystemFixes::inst($this->mu()) |
53
|
|
|
->removeDirOrFile($knownIssuesFileName); |
54
|
|
|
$this->mu()->execMe( |
|
|
|
|
55
|
|
|
$webRoot, |
|
|
|
|
56
|
|
|
$commandAdd . 'sake-lint-all ' . $relativeDir, |
57
|
|
|
'Apply easy coding standards to ' . $relativeDir . ' (' . $baseNameSpace . ')', |
58
|
|
|
false |
59
|
|
|
); |
60
|
|
|
$this->mu()->execMe( |
61
|
|
|
$webRoot, |
62
|
|
|
$commandAdd . 'sake-lint-all ' . $relativeDir, |
63
|
|
|
'Apply easy coding standards a second time ' . $relativeDir . ' (' . $baseNameSpace . ')', |
64
|
|
|
false |
65
|
|
|
); |
66
|
|
|
$this->mu()->execMe( |
67
|
|
|
$webRoot, |
68
|
|
|
$commandAdd . 'sake-lint-all ' . $relativeDir . ' > ' . $knownIssuesFileName, |
69
|
|
|
'Apply easy coding standards a third time ' . $relativeDir . ' (' . $baseNameSpace . ') and saving to ' . $knownIssuesFileName, |
70
|
|
|
false |
71
|
|
|
); |
72
|
|
|
$this->mu()->execMe( |
73
|
|
|
$webRoot, |
74
|
|
|
$commandAdd . 'sslint-stan ' . $relativeDir . ' >> ' . $knownIssuesFileName, |
75
|
|
|
'Apply phpstan. to ' . $relativeDir . ' (' . $baseNameSpace . ') and saving to: ' . $knownIssuesFileName, |
76
|
|
|
false |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
if ($localInstall) { |
80
|
|
|
$commandAdd = 'vendor/bin/'; |
|
|
|
|
81
|
|
|
Composer::inst($this->mu()) |
82
|
|
|
->RemoveDev( |
83
|
|
|
'sunnysideup/easy-coding-standards', |
84
|
|
|
'dev-master', |
85
|
|
|
$this->composerOptions |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
return null; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
protected function hasCommitAndPush() |
92
|
|
|
{ |
93
|
|
|
return true; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|