|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks; |
|
4
|
|
|
|
|
5
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Api\FileSystemFixes; |
|
6
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers\Composer; |
|
7
|
|
|
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Runs through the source code and adds hidden Silverstripe property and method documentation to classes |
|
11
|
|
|
* based on the database array and has many lists |
|
12
|
|
|
*/ |
|
13
|
|
|
class AddPHPDoc extends Task |
|
14
|
|
|
{ |
|
15
|
|
|
public const REPLACER = 'REPLACE_WITH_MODULE_NAME'; |
|
16
|
|
|
|
|
17
|
|
|
protected $taskStep = 's60'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $composerOptions = ''; |
|
23
|
|
|
|
|
24
|
|
|
protected $configFileName = 'ideannotator.yml'; |
|
25
|
|
|
|
|
26
|
|
|
protected $ideAnnotatorVersion = 'dev-master'; |
|
27
|
|
|
|
|
28
|
|
|
protected $ideannotatorConfig = <<<yml |
|
29
|
|
|
--- |
|
30
|
|
|
Name: ideannotator_REPLACE_WITH_MODULE_NAME |
|
31
|
|
|
Only: |
|
32
|
|
|
environment: dev |
|
33
|
|
|
--- |
|
34
|
|
|
# This is added automatically. Please do not edit. |
|
35
|
|
|
# This is added automatically. Please do not edit. |
|
36
|
|
|
# This is added automatically. Please do not edit. |
|
37
|
|
|
SilverLeague\IDEAnnotator\DataObjectAnnotator: |
|
38
|
|
|
enabled: true |
|
39
|
|
|
use_short_name: true |
|
40
|
|
|
enabled_modules: |
|
41
|
|
|
yml |
|
42
|
|
|
. ' |
|
43
|
|
|
- ' . self::REPLACER; |
|
44
|
|
|
|
|
45
|
|
|
public function getTitle() |
|
46
|
|
|
{ |
|
47
|
|
|
return 'Add PHP Doc Comments to Classes'; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getDescription() |
|
51
|
|
|
{ |
|
52
|
|
|
return 'Runs through the source code and adds hidden Silverstripe property and method documentation to classes'; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function runActualTask($params = []): ?string |
|
56
|
|
|
{ |
|
57
|
|
|
// $this->mu()->getWebRootDirLocation(); |
|
58
|
|
|
|
|
59
|
|
|
Composer::inst($this->mu()) |
|
60
|
|
|
->Remove('phpunit/phpunit', true) |
|
61
|
|
|
->RequireDev( |
|
62
|
|
|
'silverleague/ideannotator', |
|
63
|
|
|
$this->ideAnnotatorVersion, |
|
64
|
|
|
$this->composerOptions |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
foreach ($this->findModuleNames() as $moduleName) { |
|
68
|
|
|
$this->mu()->setBreakOnAllErrors(true); |
|
|
|
|
|
|
69
|
|
|
$this->updateModuleConfigFile($moduleName); |
|
70
|
|
|
$this->mu()->execMe( |
|
71
|
|
|
$this->mu()->getWebRootDirLocation(), |
|
72
|
|
|
'vendor/bin/sake dev/tasks/SilverLeague-IDEAnnotator-Tasks-DataObjectAnnotatorTask module=' . $moduleName . ' flush=1', |
|
73
|
|
|
'Running IDEAnnotator Task to add PHP documentation to ' . $moduleName, |
|
74
|
|
|
false |
|
75
|
|
|
); |
|
76
|
|
|
$this->mu()->setBreakOnAllErrors(false); |
|
77
|
|
|
} |
|
78
|
|
|
return null; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
protected function updateModuleConfigFile(string $moduleName) |
|
82
|
|
|
{ |
|
83
|
|
|
$moduleLocation = $this->findModuleNameLocation($moduleName); |
|
84
|
|
|
|
|
85
|
|
|
$fileLocation = $this->mu()->getWebRootDirLocation() . '/' . $moduleLocation . '/_config/' . $this->configFileName; |
|
|
|
|
|
|
86
|
|
|
FileSystemFixes::inst($this->mu()) |
|
87
|
|
|
->removeDirOrFile($fileLocation); |
|
88
|
|
|
$ideannotatorConfigForModule = $this->ideannotatorConfig; |
|
89
|
|
|
$ideannotatorConfigForModule = str_replace(self::REPLACER, $moduleName, $ideannotatorConfigForModule); |
|
90
|
|
|
$this->mu()->execMe( |
|
|
|
|
|
|
91
|
|
|
$this->mu()->getWebRootDirLocation(), |
|
|
|
|
|
|
92
|
|
|
'echo \'' . str_replace('\'', '"', $ideannotatorConfigForModule) . '\' > ' . $fileLocation, |
|
93
|
|
|
'Adding IDEAnnotator configuration', |
|
94
|
|
|
false |
|
95
|
|
|
); |
|
96
|
|
|
if (! file_exists($fileLocation)) { |
|
97
|
|
|
user_error('Could not locate ' . $fileLocation); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
protected function hasCommitAndPush(): bool |
|
102
|
|
|
{ |
|
103
|
|
|
return true; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|