GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b43140...63da1c )
by Roderik
05:58 queued 02:32
created

AnacronSkeleton::maintenance()   B

Complexity

Conditions 7
Paths 17

Size

Total Lines 60
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 9
Bugs 5 Features 1
Metric Value
c 9
b 5
f 1
dl 0
loc 60
rs 7.4661
cc 7
eloc 37
nc 17
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Kunstmaan\Skylab\Skeleton;
3
4
/**
5
 * ApacheSkeleton
6
 */
7
class AnacronSkeleton extends AbstractSkeleton
8
{
9
10
    const NAME = "anacron";
11
12
    /**
13
     * @return string
14
     */
15
    public function getName()
16
    {
17
        return self::NAME;
18
    }
19
20
    /**
21
     * @param \ArrayObject $project
22
     *
23
     * @return mixed
24
     */
25
    public function create(\ArrayObject $project)
26
    {
27
        $this->processProvider->executeSudoCommand("mkdir -p " . $this->fileSystemProvider->getProjectConfigDirectory($project["name"]) . "/fcron.d/");
28
        $this->processProvider->executeSudoCommand("touch " . $this->fileSystemProvider->getProjectConfigDirectory($project["name"]) . "/anacrontab");
29
    }
30
31
    /**
32
     * @return mixed
33
     */
34
    public function preMaintenance()
35
    {
36
    }
37
38
    /**
39
     * @return mixed
40
     */
41
    public function postMaintenance()
42
    {
43
    }
44
45
    /**
46
     * @param  \ArrayObject $project
47
     * @return mixed
48
     */
49
    public function maintenance(\ArrayObject $project)
50
    {
51
        $this->permissionsProvider->createGroupIfNeeded($project["name"]);
52
        $this->permissionsProvider->createUserIfNeeded($project["name"], $project["name"]);
53
54
        $cronjobscript = $this->fileSystemProvider->getProjectConfigDirectory($project["name"]) . "/anacronjobs";
55
        $crontab = $this->fileSystemProvider->getProjectConfigDirectory($project["name"]) . "/anacrontab";
56
57
        // cleanup
58
        $this->processProvider->executeSudoCommand("rm -f " . $cronjobscript);
59
        $this->processProvider->executeSudoCommand("rm -f " . $crontab);
60
        $this->processProvider->executeSudoCommand("crontab -r -u " . $project["name"], true);
61
62
        // generate anacronjobs file
63
        if (!$this->app["config"]["develmode"]) {
64
65
            // anacrontab
66
            $this->processProvider->executeSudoCommand('touch ' . $crontab);
67
            $this->processProvider->executeSudoCommand('chmod a+w ' . $crontab);
68
            $this->processProvider->executeSudoCommand('echo "[email protected]" >> ' . $crontab);
69
70
            // anacronjobs
71
            $cronjobs = $this->fileSystemProvider->getDotDFiles($this->fileSystemProvider->getProjectConfigDirectory($project["name"]) . "/fcron.d/");
72
            $this->processProvider->executeSudoCommand("echo -n -e '\n' >> " . $cronjobscript);
73
            foreach ($cronjobs as $cronjob) {
74
                $this->processProvider->executeSudoCommand("cat " . $cronjob->getRealPath() . " >> " . $cronjobscript);
75
                $this->processProvider->executeSudoCommand("echo -n -e '\n' >> " . $cronjobscript);
76
            }
77
78
            if (sizeof($cronjobs) > 0){
79
                $this->processProvider->executeSudoCommand("chmod +x ".$cronjobscript);
80
                $this->processProvider->executeSudoCommand("set -f;echo '0 3 * * * " . $cronjobscript . "' >> " . $crontab . ';set -f');
81
            }
82
83
            // project anacronjobs
84
            $projectAnacrontab = $this->fileSystemProvider->getProjectDirectory($project["name"]) . "/data/current/app/config/anacrontab";
85
            if (file_exists($projectAnacrontab)) {
86
                $os = strtolower(PHP_OS);
87
                switch ($os) {
88
                    case 'linux': //Linux
89
                        $sed = 'sed -r';
90
                        break;
91
                    case 'darwin': //OSX
92
                        $sed = 'sed -E';
93
                        break;
94
                    default:
95
                        throw new \Exception("Unsupported OS: " . $os);
96
                        break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
97
                }
98
99
                $this->processProvider->executeSudoCommand("cat " . $projectAnacrontab . " | " . $sed . " 's/\/<path to>/".str_replace('/', '\/',$this->fileSystemProvider->getProjectDirectory($project["name"])) ."\/data\/current/g' >> " . $crontab);
100
                $this->processProvider->executeSudoCommand('echo >> ' . $crontab);
101
            }
102
            $this->processProvider->executeSudoCommand('echo >> ' . $crontab);
103
104
            // load the anacrontab file
105
            $this->processProvider->executeSudoCommand("crontab -u " . $project["name"] . " " . $crontab);
106
107
        }
108
    }
109
110
    /**
111
     * @param  \ArrayObject $project
112
     * @return mixed
113
     */
114
    public function preBackup(\ArrayObject $project)
115
    {
116
    }
117
118
    /**
119
     * @param  \ArrayObject $project
120
     * @return mixed
121
     */
122
    public function postBackup(\ArrayObject $project)
123
    {
124
    }
125
126
    /**
127
     * @param  \ArrayObject $project
128
     * @return mixed
129
     */
130
    public function preRemove(\ArrayObject $project)
131
    {
132
        // cleanup
133
        $this->processProvider->executeSudoCommand("crontab -r -u " . $project["name"], true);
134
    }
135
136
    /**
137
     * @param  \ArrayObject $project
138
     * @return mixed
139
     */
140
    public function postRemove(\ArrayObject $project)
141
    {
142
    }
143
144
    /**
145
     * @return string[]
146
     */
147
    public function dependsOn()
148
    {
149
        return array("base");
150
    }
151
152
}