CheckThatFoldersAreReady::getDescription()   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 0
Metric Value
eloc 1
c 1
b 0
f 0
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\Tasks\Task;
6
7
/**
8
 * Checks that all the directories needed to run this tool exist and are writable.
9
 */
10
class CheckThatFoldersAreReady extends Task
11
{
12
    protected $taskStep = 's10';
13
14
    public function getTitle()
15
    {
16
        return 'Check folders are ready for upgrade process';
17
    }
18
19
    public function getDescription()
20
    {
21
        return '
22
            Checks that all the directories needed to run this tool exist and are writable.
23
            ';
24
    }
25
26
    /**
27
     * Checks that the required folder variables link to folders that file_exists
28
     * and which are writable.
29
     */
30
    public function runActualTask($params = []): ?string
31
    {
32
        $abovewebdir = $this->mu()->getAboveWebRootDirLocation();
0 ignored issues
show
Bug introduced by
The method getAboveWebRootDirLocation() 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

32
        $abovewebdir = $this->mu()->/** @scrutinizer ignore-call */ getAboveWebRootDirLocation();
Loading history...
Bug introduced by
It seems like getAboveWebRootDirLocation() 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

32
        $abovewebdir = $this->mu()->/** @scrutinizer ignore-call */ getAboveWebRootDirLocation();
Loading history...
33
        //check dir above web dir exists
34
        if (! file_exists($abovewebdir)) {
0 ignored issues
show
Bug introduced by
It seems like $abovewebdir can also be of type Sunnysideup\UpgradeToSilverstripe4\ModuleUpgrader and Sunnysideup\UpgradeToSilverstripe4\Traits\Creator and null; however, parameter $filename of file_exists() 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

34
        if (! file_exists(/** @scrutinizer ignore-type */ $abovewebdir)) {
Loading history...
35
            $this->mu()->colourPrint('Above web dir does not exists: ' . $abovewebdir, 'red');
0 ignored issues
show
Bug introduced by
It seems like colourPrint() 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

35
            $this->mu()->/** @scrutinizer ignore-call */ colourPrint('Above web dir does not exists: ' . $abovewebdir, 'red');
Loading history...
36
            return 'No point in running tool with directory not ready';
37
        }
38
        //Directory exists, now check if writable.
39
        if (! is_writable($abovewebdir)) {
0 ignored issues
show
Bug introduced by
It seems like $abovewebdir can also be of type Sunnysideup\UpgradeToSilverstripe4\ModuleUpgrader and Sunnysideup\UpgradeToSilverstripe4\Traits\Creator and null; however, parameter $filename of is_writable() 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

39
        if (! is_writable(/** @scrutinizer ignore-type */ $abovewebdir)) {
Loading history...
40
            //Not writable send warning
41
            $this->mu()->colourPrint('Above web dir is not writable: ' . $abovewebdir, 'red');
42
            return 'No point in running tool with directory not ready';
43
        }
44
        //It has been found and is writable; Success!
45
        $this->mu()->colourPrint('Found and checked above web dir ✔', 'green');
46
47
        //LogFileLocation
48
        $logDir = $this->mu()->getLogFolderDirLocation();
0 ignored issues
show
Bug introduced by
The method getLogFolderDirLocation() 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

48
        $logDir = $this->mu()->/** @scrutinizer ignore-call */ getLogFolderDirLocation();
Loading history...
Bug introduced by
It seems like getLogFolderDirLocation() 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

48
        $logDir = $this->mu()->/** @scrutinizer ignore-call */ getLogFolderDirLocation();
Loading history...
49
        if ($logDir) {
50
            //check that log dir is exists
51
            if (! file_exists($logDir)) {
0 ignored issues
show
Bug introduced by
It seems like $logDir can also be of type Sunnysideup\UpgradeToSilverstripe4\ModuleUpgrader and Sunnysideup\UpgradeToSilverstripe4\Traits\Creator; however, parameter $filename of file_exists() 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

51
            if (! file_exists(/** @scrutinizer ignore-type */ $logDir)) {
Loading history...
52
                return 'Log dir not exists: ' . $logDir . '
0 ignored issues
show
Bug introduced by
Are you sure $logDir of type Sunnysideup\UpgradeToSil...e4\Traits\Creator|mixed can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

52
                return 'Log dir not exists: ' . /** @scrutinizer ignore-type */ $logDir . '
Loading history...
53
                    set your log dir to an empty string if you prefer to continue without a log.';
54
            }
55
            //Directory exists, now check if writable.
56
            if (! is_writable($logDir)) {
0 ignored issues
show
Bug introduced by
It seems like $logDir can also be of type Sunnysideup\UpgradeToSilverstripe4\ModuleUpgrader and Sunnysideup\UpgradeToSilverstripe4\Traits\Creator; however, parameter $filename of is_writable() 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

56
            if (! is_writable(/** @scrutinizer ignore-type */ $logDir)) {
Loading history...
57
                return $logDir . ' is not writable' . '.
58
                Set the log dir to an empty string or provide a writable directory. ';
59
            }
60
            //all ok
61
        }
62
        return null;
63
    }
64
65
    protected function hasCommitAndPush()
66
    {
67
        return false;
68
    }
69
}
70