Completed
Push — master ( 60e303...4c478a )
by
unknown
8s
created

CleanupGeneratedPdfDailyTask::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 16 and the first side effect is on line 10.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace CWP\PDFExport\Tasks;
4
5
use SilverStripe\Core\Config\Configurable;
6
use SilverStripe\Core\Injector\Injector;
7
use SilverStripe\CronTask\Interfaces\CronTask;
0 ignored issues
show
Bug introduced by
The type SilverStripe\CronTask\Interfaces\CronTask was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
if (!interface_exists(CronTask::class)) {
10
    return;
11
}
12
13
/**
14
 * If the silverstripe/crontask module is installed, this will enable the PDF cleanup task to be run on a schedule
15
 */
16
class CleanupGeneratedPdfDailyTask implements CronTask
17
{
18
    use Configurable;
19
20
    /**
21
     * The cron schedule for this task (default: midnight every day)
22
     *
23
     * @config
24
     * @var string
25
     */
26
    private static $schedule = '0 0 * * *';
0 ignored issues
show
introduced by
The private property $schedule is not used, and could be removed.
Loading history...
27
28
    /**
29
     * Whether this task is enabled (default false)
30
     *
31
     * @config
32
     * @return bool
33
     */
34
    private static $enabled = false;
0 ignored issues
show
introduced by
The private property $enabled is not used, and could be removed.
Loading history...
35
36
    private static $segment = 'CleanupGeneratedPdfDailyTask';
0 ignored issues
show
introduced by
The private property $segment is not used, and could be removed.
Loading history...
37
38
    public function getSchedule()
39
    {
40
        return $this->config()->get('schedule');
41
    }
42
43
    public function process()
44
    {
45
        if (!$this->config()->get('enabled')) {
46
            return;
47
        }
48
49
        $task = Injector::inst()->create(CleanupGeneratedPdfBuildTask::class);
50
        $task->run(null);
51
    }
52
}
53