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

SilverStripeElasticaReindexCron   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 18.18 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSchedule() 0 4 1
A process() 6 15 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
use SilverStripe\Elastica\ReindexTask;
4
5
/**
6
 * These regular updates run as often as is practical.
7
 * They seem to take 2-3 hours at the moment, so we run them 4 times per day.
8
 */
9
class SilverStripeElasticaReindexCron implements CronTask
10
{
11
12
    /**
13
     * Run every 6 hours
14
     *
15
     * @return string
16
     */
17
    public function getSchedule()
18
    {
19
        return "0 */6 * * *";
20
    }
21
22
    /**
23
     * Run the build task SilverStripeElasticaReindexTask
24
     * @return void
25
     */
26
    public function process()
27
    {
28
        $taskClasses = [
29
            [UpdateSilverStripeVersionsTask::class, null],
30
            [UpdateAddonsTask::class, null],
31
            [ReindexTask::class, 'reindex=1'],
32
        ];
33
34 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...
35
            list($taskClass, $taskQuerystring) = $taskInfo;
36
            $job = new RunBuildTaskJob($taskClass, $taskQuerystring);
37
            $jobID = Injector::inst()->get(QueuedJobService::class)->queueJob($job);
38
            echo 'Added ' . $taskClass . ' to job queue (job ID ' . $jobID . ")\n";
39
        }
40
    }
41
}
42