AddPHPDoc::hasCommitAndPush()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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);
0 ignored issues
show
Bug introduced by
It seems like setBreakOnAllErrors() 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

68
            $this->mu()->/** @scrutinizer ignore-call */ setBreakOnAllErrors(true);
Loading history...
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;
0 ignored issues
show
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

85
        $fileLocation = $this->mu()->/** @scrutinizer ignore-call */ getWebRootDirLocation() . '/' . $moduleLocation . '/_config/' . $this->configFileName;
Loading history...
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

85
        $fileLocation = $this->mu()->/** @scrutinizer ignore-call */ getWebRootDirLocation() . '/' . $moduleLocation . '/_config/' . $this->configFileName;
Loading history...
86
        FileSystemFixes::inst($this->mu())
87
            ->removeDirOrFile($fileLocation);
88
        $ideannotatorConfigForModule = $this->ideannotatorConfig;
89
        $ideannotatorConfigForModule = str_replace(self::REPLACER, $moduleName, $ideannotatorConfigForModule);
90
        $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

90
        $this->mu()->/** @scrutinizer ignore-call */ execMe(
Loading history...
91
            $this->mu()->getWebRootDirLocation(),
0 ignored issues
show
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

91
            /** @scrutinizer ignore-type */ $this->mu()->getWebRootDirLocation(),
Loading history...
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