Task::getOutput()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace pmill\Scheduler\Tasks;
3
4
use Cron\CronExpression;
5
use pmill\Scheduler\Interfaces\Task as TaskInterface;
6
7
abstract class Task implements TaskInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $expression;
13
14
    /**
15
     * @var null|string|array
16
     */
17
    protected $output;
18
19
    /**
20
     * @return mixed
21
     */
22
    abstract public function run();
23
    
24
    /**
25
     * Sets a cron expression
26
     * @param string $expression
27
     * @return Task $this
28
     */
29
    public function setExpression($expression)
30
    {
31
        $this->expression = $expression;
32
        return $this;
33
    }
34
    
35
    /**
36
     * Gets the current cron expression
37
     * @return string
38
     */
39
    public function getExpression()
40
    {
41
        return $this->expression;
42
    }
43
    
44
    /**
45
     * Sets the output from the task
46
     * @param null|string|array $output
47
     * @return Task $this
48
     */
49
    public function setOutput($output)
50
    {
51
        $this->output = $output;
52
        return $this;
53
    }
54
    
55
    /**
56
     * Gets the output from the task
57
     * @return null|string|array
58
     */
59
    public function getOutput()
60
    {
61
        return $this->output;
62
    }
63
    
64
    /**
65
     * Checks whether the task is currently due
66
     * @return bool
67
     */
68
    public function isDue()
69
    {
70
        $expression = $this->getExpression();
71
        if (!$expression) {
72
            return false;
73
        }
74
        
75
        $cron = CronExpression::factory($expression);
76
        return $cron->isDue();
77
    }
78
    
79
}