Completed
Pull Request — master (#15)
by Wachter
07:51
created

Task::setInterval()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 3
crap 1
1
<?php
2
3
/*
4
 * This file is part of php-task library.
5
 *
6
 * (c) php-task
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Task\TaskBundle\Entity;
13
14
use Cron\CronExpression;
15
use Task\Task as BaseTask;
16
17
/**
18
 * Extends base task with id and interval-expression which will be stored in database.
19
 */
20
class Task extends BaseTask
21
{
22
    /**
23
     * @var int
24
     */
25
    private $id;
26
27
    /**
28
     * @var string
29
     */
30
    private $intervalExpression;
31
32
    /**
33
     * @return int
34
     */
35
    public function getId()
36
    {
37
        return $this->id;
38
    }
39
40
    /**
41
     * @return mixed
42
     */
43
    public function getIntervalExpression()
44
    {
45
        return $this->intervalExpression;
46
    }
47
48
    public function getInterval()
49
    {
50 72
        if (null === $this->interval && null !== $this->intervalExpression) {
51
            $this->interval = CronExpression::factory($this->intervalExpression);
52 72
        }
53
54
        return parent::getInterval();
55
    }
56
57
    /**
58 78
     * {@inheritdoc}
59
     */
60 78
    public function setInterval(CronExpression $interval, \DateTime $firstExecution = null, \DateTime $lastExecution = null)
61 78
    {
62
        parent::setInterval($interval, $firstExecution, $lastExecution);
63
64
        $this->intervalExpression = $interval->getExpression();
65
    }
66
}
67