Completed
Push — master ( 1385c4...94a8d3 )
by Nicolaas
01:48
created

UpdateModules::writeLog()   C

Complexity

Conditions 7
Paths 4

Size

Total Lines 43
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 21
nc 4
nop 0
1
<?php
2
3
/**
4
 * main class running all the updates
5
 *
6
 *
7
 */
8
class UpdateModules extends BuildTask
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    protected $enabled = true;
11
12
    protected $title = "Update Modules";
13
14
    protected $description = "Adds files necessary for publishing a module to GitHub. The list of modules is specified in standard config or else it retrieves a list of modules from GitHub.";
15
16
    /**
17
     * e.g.
18
     * - moduleA
19
     * - moduleB
20
     * - moduleC
21
     *
22
     *
23
     * @var array
24
     */
25
    private static $modules_to_update = array();
0 ignored issues
show
Unused Code introduced by
The property $modules_to_update is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
26
27
    /**
28
     * e.g.
29
     * - ClassNameForUpdatingFileA
30
     * - ClassNameForUpdatingFileB
31
     *
32
     * @var array
33
     */
34
    private static $files_to_update = array();
0 ignored issues
show
Unused Code introduced by
The property $files_to_update is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
35
    /**
36
     * e.g.
37
     * - ClassNameForUpdatingFileA
38
     * - ClassNameForUpdatingFileB
39
     *
40
     * @var array
41
     */
42
    private static $commands_to_run = array();
0 ignored issues
show
Unused Code introduced by
The property $commands_to_run is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
43
44
    public static $unsolvedItems = array();
45
46
    public function run($request)
47
    {
48
        increase_time_limit_to(3600);
49
50
        //Check temp module folder is empty
51
        $tempFolder = GitHubModule::Config()->get('absolute_temp_folder');
52
        $tempDirFiles = scandir($tempFolder);
53
        if (count($tempDirFiles) > 2) {
54
            die('<h2>' . $tempFolder . ' is not empty, please delete or move files </h2>');
0 ignored issues
show
Coding Style Compatibility introduced by
The method run() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
55
        }
56
57
        //Get list of all modules from GitHub
58
        $gitUserName = $this->Config()->get('github_user_name');
0 ignored issues
show
Unused Code introduced by
$gitUserName is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
59
60
        $modules = GitRepoFinder::get_all_repos();
61
62
63
        /*
64
         * Get files to add to modules
65
         * */
66
        $files = ClassInfo::subclassesFor('AddFileToModule');
67
        array_shift($files);
68
        $limitedFileClasses = $this->Config()->get('files_to_update');
69
        if ($limitedFileClasses === 'none') {
70
            $files = [];
71
        } elseif (is_array($limitedFileClasses) && count($limitedFileClasses)) {
72
            $files = array_intersect($files, $limitedFileClasses);
73
        }
74
75
        /*
76
         * Get commands to run on modules
77
         * */
78
79
        $commands = ClassInfo::subclassesFor('RunCommandLineMethodOnModule');
80
        array_shift($commands);
81
        $limitedCommands = $this->Config()->get('commands_to_run');
82
        if ($limitedCommands === 'none') {
83
            $commands = [];
84
        } elseif (is_array($limitedCommands) && count($limitedCommands)) {
85
            $commands = array_intersect($commands, $limitedCommands);
86
        }
87
88
89
        set_error_handler('errorHandler', E_ALL);
90
        foreach ($modules as $count => $module) {
0 ignored issues
show
Bug introduced by
The expression $modules of type string is not traversable.
Loading history...
91
            $this->currentModule = $module;
0 ignored issues
show
Bug introduced by
The property currentModule does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
92
            try {
93
                $this->processOneModule($module, $count, $files, $commands);
94
            } catch (Exception $e) {
95
                GeneralMethods::outputToScreen("<li> Could not complete processing $module: " .  $e->getMessage() . " </li>");
96
            }
97
        }
98
99
        restore_error_handler();
100
101
        $this->writeLog();
102
        //to do ..
103
    }
104
105
    protected function errorHandler(int $errno, string $errstr)
0 ignored issues
show
Unused Code introduced by
The parameter $errno is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
106
    {
107
        GeneralMethods::outputToScreen("<li> Could not complete processing module: " .  $errstr . " </li>");
108
109
        UpdateModules::addUnsolvedProblem($this->currentModule, "Could not complete processing module: " . $errstr);
110
111
        return true;
112
    }
113
114
    protected function processOneModule($module, $count, $files, $commands)
115
    {
116
        if (stripos($module, 'silverstripe-')  === false) {
117
            $module = "silverstripe-" . $module;
118
        }
119
        echo "<h2>" . ($count+1) . ". ".$module."</h2>";
120
121
122
        $moduleObject = GitHubModule::get_or_create_github_module($module);
123
124
        $this->checkUpdateTag($moduleObject);
125
126
        $updateComposerJson = $this->Config()->get('update_composer_json');
127
128
        // Check if all necessary files are perfect on GitHub repo already,
129
        // if so we can skip that module. But! ... if there are commands to run
130
        // over the files in the repo, then we need to clone the repo anyhow,
131
        // so skip the check
132
        if (count($commands) == 0 && ! $updateComposerJson) {
133
            $moduleFilesOK = true;
0 ignored issues
show
Unused Code introduced by
$moduleFilesOK is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
134
135
            foreach ($files as $file) {
136
                $fileObj = $file::create($moduleObject);
137
                $checkFileName = $fileObj->getFileLocation();
138
                $GitHubFileText = $moduleObject -> getRawFileFromGithub($checkFileName);
139
                if ($GitHubFileText) {
140
                    $fileCheck = $fileObj->compareWithText($GitHubFileText);
141
                    if (! $fileCheck) {
142
                        $moduleFilesOK = false;
0 ignored issues
show
Unused Code introduced by
$moduleFilesOK is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
143
                    }
144
                } else {
145
                    $moduleFilesOK = false;
0 ignored issues
show
Unused Code introduced by
$moduleFilesOK is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
146
                }
147
            }
148
        }
149
150
        $repository = $moduleObject->checkOrSetGitCommsWrapper($forceNew = true);
0 ignored issues
show
Unused Code introduced by
$repository is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
151
152
153
        $this->moveOldReadMe($moduleObject);
154
155
156
        $checkConfigYML = $this->Config()->get('check_config_yml');
157
        if ($checkConfigYML) {
158
            $this->checkConfigYML($moduleObject);
159
        }
160
161
        if ($updateComposerJson) {
162
            $composerJsonObj = new ComposerJson($moduleObject);
163
            $composerJsonObj->updateJsonFile();
164
            $moduleObject->setDescription($composerJsonObj->getDescription());
165
        }
166
167
        $excludedWords = $this->Config()->get('excluded_words');
168
169
170
        if (count($excludedWords) > 0) {
171
            $folder = GitHubModule::Config()->get('absolute_temp_folder') . '/' . $moduleObject->moduleName . '/';
172
173
            $results = $this->checkDirExcludedWords($folder.'/'.$moduleObject->modulename, $excludedWords);
174
175
176
            if ($results && count($results > 0)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $results of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
177
                $msg = "<h4>The following excluded words were found: </h4><ul>";
178
                foreach ($results as $file => $words) {
179
                    foreach ($words as $word) {
180
                        $msg .= "<li>$word in $file</li>";
181
                    }
182
                }
183
                $msg .= '</ul>';
184
185
                //trigger_error ("excluded words found in files(s)");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
186
                GeneralMethods::outputToScreen($msg);
187
                UpdateModules::$unsolvedItems[$moduleObject->ModuleName] = $msg;
188
            }
189
        }
190
191
192
        foreach ($files as $file) {
193
            //run file update
194
195
            $obj = $file::create($moduleObject);
196
            $obj->run();
197
        }
198
199
        $moduleDir = $moduleObject->Directory();
200
201
        foreach ($commands as $command) {
202
            //run file update
203
204
205
            $obj = $command::create($moduleDir);
206
            $obj->run();
207
208
209
            //run command
210
        }
211
212
        //Update Repository description
213
        //$moduleObject->updateGitHubInfo(array());
0 ignored issues
show
Unused Code Comprehensibility introduced by
89% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
214
215 View Code Duplication
        if (! $moduleObject->add()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
216
            $msg = "Could not add files module to Repo";
217
            GeneralMethods::outputToScreen($msg);
218
            UpdateModules::$unsolvedItems[$moduleObject->ModuleName] = $msg;
219
            return;
220
        }
221 View Code Duplication
        if (! $moduleObject->commit()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
222
            $msg = "Could not commit files to Repo";
223
            GeneralMethods::outputToScreen($msg);
224
            UpdateModules::$unsolvedItems[$moduleObject->ModuleName] = $msg;
225
            return;
226
        }
227
228 View Code Duplication
        if (! $moduleObject->push()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
229
            $msg = "Could not push files to Repo";
230
            GeneralMethods::outputToScreen($msg);
231
            UpdateModules::$unsolvedItems[$moduleObject->ModuleName] = $msg;
232
            return;
233
        }
234 View Code Duplication
        if (! $moduleObject->removeClone()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
235
            $msg = "Could not remove local copy of repo";
236
            GeneralMethods::outputToScreen($msg);
237
            UpdateModules::$unsolvedItems[$moduleObject->ModuleName] = $msg;
238
        }
239
240
        $addRepoToScrutinzer = $this->Config()->get('add_to_scrutinizer');
241
        if ($addRepoToScrutinzer) {
242
            $moduleObject->addRepoToScrutinzer();
243
        }
244
    }
245
246
247
248
    protected function renameTest($moduleObject)
249
    {
250
        $oldName = $moduleObject->Directory() . "/tests/ModuleTest.php";
251
252
        if (! file_exists($oldName)) {
253
            print_r($oldName);
254
            return false;
255
        }
256
257
258
259
        $newName = $moduleObject->Directory() . "tests/" . $moduleObject->ModuleName . "Test.php";
260
261
        GeneralMethods::outputToScreen("Renaming $oldName to $newName");
262
263
        unlink($newName);
264
265
        rename($oldName, $newName);
266
    }
267
268
    public static function addUnsolvedProblem($moduleName, $problemString)
269
    {
270
        if (!isset(UpdateModules::$unsolvedItems[$moduleName])) {
271
            UpdateModules::$unsolvedItems[$moduleName] = array();
272
        }
273
        array_push(UpdateModules::$unsolvedItems[$moduleName], $problemString);
274
    }
275
276
    protected function writeLog()
277
    {
278
        $debug = $this->Config()->get('debug');
0 ignored issues
show
Unused Code introduced by
$debug is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
279
280
        $dateStr =  date("Y/m/d H:i:s");
281
282
        $html = '<h1> Modules checker report at ' .$dateStr . '</h1>';
283
284
        if (count(UpdateModules::$unsolvedItems) == 0) {
285
            $html .= ' <h2> No unresolved problems in modules</h2>';
286
        } else {
287
            $html .= '
288
                <h2> Unresolved problems in modules</h2>
289
290
            <table border = 1>
291
                    <tr><th>Module</th><th>Problem</th></tr>';
292
293
            foreach (UpdateModules::$unsolvedItems as $moduleName => $problems) {
294
                if (is_array($problems)) {
295
                    foreach ($problems as $problem) {
296
                        $html .= '<tr><td>'.$moduleName.'</td><td>'. $problem .'</td></tr>';
297
                    }
298
                } elseif (is_string($problems)) {
299
                    $html .= '<tr><td>'.$moduleName.'</td><td>'. $problems.'</td></tr>';
300
                }
301
            }
302
            $html .= '</table>';
303
        }
304
305
306
307
        $logFolder = $this->Config()->get('logfolder');
308
309
        $filename = $logFolder . date('U') . '.html';
310
311
        GeneralMethods::outputToScreen("Writing to $filename");
312
313
        $result = file_put_contents($filename, $html);
314
315
        if (! $result) {
316
            GeneralMethods::outputToScreen("Could not write log file");
317
        }
318
    }
319
320
    protected function checkConfigYML($module)
321
    {
322
        $configYml = ConfigYML::create($module)->reWrite();
0 ignored issues
show
Unused Code introduced by
$configYml is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
323
    }
324
325
    private function checkFile($module, $filename)
326
    {
327
        $folder = GitHubModule::Config()->get('absolute_temp_folder');
328
        return file_exists($folder.'/'.$module.'/'.$filename);
329
    }
330
331
    private function checkReadMe($module)
332
    {
333
        return $this->checkFile($module, "README.MD");
334
    }
335
336
    private function checkDirExcludedWords($directory, $wordArray)
337
    {
338
        $filesAndFolders = scandir($directory);
339
340
        $problem_files = array();
341
        foreach ($filesAndFolders as $fileOrFolder) {
342
            if ($fileOrFolder == '.' || $fileOrFolder == '..' || $fileOrFolder == '.git') {
343
                continue;
344
            }
345
346
            $fileOrFolderFullPath = $directory . '/' . $fileOrFolder;
347
            if (is_dir($fileOrFolderFullPath)) {
348
                $dir = $fileOrFolderFullPath;
349
                $problem_files = array_merge($this->checkDirExcludedWords($dir, $wordArray), $problem_files);
350
            }
351
            if (is_file($fileOrFolderFullPath)) {
352
                $file = $fileOrFolderFullPath;
353
                $matchedWords = $this->checkFileExcludedWords($file, $wordArray);
354
355
                if ($matchedWords) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $matchedWords of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
356
                    $problem_files[$file] = $matchedWords;
357
                }
358
            }
359
        }
360
361
        return $problem_files;
362
    }
363
364
    private function checkFileExcludedWords($fileName, $wordArray)
365
    {
366
        $matchedWords = array();
367
368
        $fileName = str_replace('////', '/', $fileName);
369
        if (filesize($fileName) == 0) {
370
            return $matchedWords;
371
        }
372
373
374
        $fileContent = file_get_contents($fileName);
375 View Code Duplication
        if (!$fileContent) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
376
            $msg = "Could not open $fileName to check for excluded words";
377
378
            GeneralMethods::outputToScreen($msg);
379
            UpdateModules::$unsolvedItems[$moduleObject->ModuleName] = $msg;
0 ignored issues
show
Bug introduced by
The variable $moduleObject does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
380
        }
381
382
        foreach ($wordArray as $word) {
383
            $matches = array();
0 ignored issues
show
Unused Code introduced by
$matches is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
384
            $matchCount = preg_match_all('/' . $word . '/i', $fileContent);
385
386
387
388
389
390
            if ($matchCount > 0) {
391
                array_push($matchedWords, $word);
392
            }
393
        }
394
395
        return $matchedWords;
396
    }
397
398
    private function checkUpdateTag($moduleObject)
399
    {
400
        $tagDelayString = $this->Config()->get('tag_delay');
401
        $nextTag = null;
0 ignored issues
show
Unused Code introduced by
$nextTag is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
402
403
        if (!$tagDelayString) {
404
            $tagDelayString = "-3 weeks";
405
        }
406
407
408
        $tagDelay = strtotime($tagDelayString);
409
        if (!$tagDelay) {
410
            $tagDelay = strtotime("-3 weeks");
411
        }
412
413
        $tag = $moduleObject->getLatestTag();
414
415
        $commitTime = $moduleObject->getLatestCommitTime();
416
417
        if (! $commitTime) { // if no commits, cannot create a tag
418
            return false;
419
        }
420
421
        $createTag = false;
0 ignored issues
show
Unused Code introduced by
$createTag is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
422
423
424
        $newTagString  = '';
425
426
        if (! $tag) {
427
            $createTag = true;
0 ignored issues
show
Unused Code introduced by
$createTag is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
428
            $newTagString = '1.0.0';
429
        } elseif ($tag && $commitTime > $tag['timestamp'] && $commitTime < $tagDelay) {
430
            $changeType = $moduleObject->getChangeTypeSinceLastTag();
431
432
            $newTagString = $this->findNextTag($tag, $changeType);
433
        }
434
435
        if ($newTagString) {
436
            GeneralMethods::outputToScreen('<li> Creating new tag  '.$newTagString.' ... </li>');
437
438
            //git tag -a 0.0.1 -m "testing tag"
439
            $options = array(
440
                'a' => $newTagString,
441
                'm' => $this->Config()->get('tag_create_message')
442
            );
443
444
            $moduleObject->createTag($options);
445
        }
446
447
        return true;
448
    }
449
450
    protected function findNextTag($tag, $changeType)
451
    {
452
        switch ($changeType) {
453
454
            case 'MAJOR':
455
            $tag['tagparts'][0] = intval($tag['tagparts'][0]) + 1;
456
            $tag['tagparts'][1] = 0;
457
            $tag['tagparts'][2] = 0;
458
            break;
459
460
            case 'MINOR':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
461
462
            $tag['tagparts'][1] = intval($tag['tagparts'][1]) + 1;
463
            $tag['tagparts'][2] = 0;
464
            break;
465
466
            default:
467
            case 'PATCH':
0 ignored issues
show
Unused Code introduced by
case 'PATCH': $tag['...s'][2]) + 1; 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...
468
            $tag['tagparts'][2] = intval($tag['tagparts'][2]) + 1;
469
            break;
470
        }
471
472
        $newTagString = trim(implode('.', $tag['tagparts']));
473
        return $newTagString;
474
    }
475
476
    protected function moveOldReadMe($moduleObject)
477
    {
478
        $tempDir = GitHubModule::Config()->get('absolute_temp_folder');
479
        $oldReadMe = $tempDir . '/' .  $moduleObject->ModuleName . '/' .'README.md';
480
481
        if (!file_exists($oldReadMe)) {
482
            return false;
483
        }
484
485
486
        $oldreadmeDestinationFiles = array(
487
                'docs/en/INDEX.md',
488
                'docs/en/README.old.md',
489
            );
490
491
492
        $copied = false;
493
        foreach ($oldreadmeDestinationFiles as $file) {
494
            $filePath = $tempDir . '/' .  $moduleObject->ModuleName . '/' . $file;
495
496
            if (!file_exists($filePath)) {
497
                $copied = true;
498
                copy($oldReadMe, $filePath);
499
            }
500
        }
501
        if ($copied) {
502
            unlink($oldReadMe);
503
        }
504
    }
505
}
506