Completed
Pull Request — master (#176)
by Robbie
08:50 queued 07:19
created

NightlyUpdatesCron   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 19.35 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 6
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSchedule() 0 4 1
A process() 6 13 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * These nightly updates can clean up anything that might have been missed by the other tasks
5
 */
6
class NightlyUpdatesCron implements CronTask
7
{
8
9
    /**
10
     * Run at 1am every morning
11
     *
12
     * @return string
13
     */
14
    public function getSchedule()
15
    {
16
        return "0 1 * * *";
17
    }
18
19
    /**
20
     * Run the build task to update addons
21
     * @return void
22
     */
23
    public function process()
24
    {
25
        $taskClasses = [
26
            [BuildAddonsTask::class, null], // rebuild all addons
27
        ];
28
29 View Code Duplication
        foreach ($taskClasses as $taskInfo) {
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...
30
            list($taskClass, $taskQuerystring) = $taskInfo;
31
            $job = new RunBuildTaskJob($taskClass, $taskQuerystring);
32
            $jobID = Injector::inst()->get(QueuedJobService::class)->queueJob($job);
33
            echo 'Added ' . $taskClass . ' to job queue (job ID ' . $jobID . ")\n";
34
        }
35
    }
36
}
37