1 | <?php |
||
0 ignored issues
–
show
|
|||
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
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. 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
|
|||
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
|
|||
35 | |||
36 | private static $segment = 'CleanupGeneratedPdfDailyTask'; |
||
0 ignored issues
–
show
|
|||
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 |
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.