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::postBackup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 1
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
}