CreateClientFolder::runActualTask()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 19
rs 9.7998
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\IndividualTasks;
4
5
use Sunnysideup\UpgradeToSilverstripe4\Api\FileSystemFixes;
6
use Sunnysideup\UpgradeToSilverstripe4\Tasks\Task;
7
8
/**
9
 * This task adds a legacy branch to the git repo of the original to act as a backup/legacy version for
10
 * holding a version of the module before it was changed
11
 */
12
class CreateClientFolder extends Task
13
{
14
    protected $taskStep = 's30';
15
16
    protected $clientFolderName = 'client';
17
18
    public function getTitle()
19
    {
20
        return 'Move front-end stuff to a client folder';
21
    }
22
23
    public function getDescription()
24
    {
25
        return '
26
            Takes the javascript, css, and images folders and puts them in a newly created client folder.';
27
    }
28
29
    /**
30
     * @param  array  $params not currently used for this task
31
     */
32
    public function runActualTask($params = []): ?string
33
    {
34
        foreach ($this->mu()->getExistingModuleDirLocations() as $moduleDir) {
0 ignored issues
show
Bug introduced by
It seems like getExistingModuleDirLocations() 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

34
        foreach ($this->mu()->/** @scrutinizer ignore-call */ getExistingModuleDirLocations() as $moduleDir) {
Loading history...
35
            $newClientFolder = $moduleDir . '/' . $this->clientFolderName . '/ ';
36
            $fixer = FileSystemFixes::inst($this->mu())
37
                ->mkDir($newClientFolder);
38
            $foldersToMoveName = [
39
                'javascript',
40
                'js',
41
                'images',
42
                'img',
43
                'css',
44
            ];
45
            foreach ($foldersToMoveName as $folderToMoveName) {
46
                $folderToMove = $moduleDir . '/' . $folderToMoveName . '/ ';
47
                $fixer->moveFolderOrFile($folderToMove, $newClientFolder);
48
            }
49
        }
50
        return null;
51
    }
52
53
    protected function hasCommitAndPush()
54
    {
55
        return true;
56
    }
57
}
58