Completed
Push — master ( 059a57...9d778b )
by Wachter
03:30
created

Task::getUuid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/*
3
 * This file is part of PHP-Task library.
4
 *
5
 * (c) php-task
6
 *
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Task;
12
13
use Ramsey\Uuid\Uuid;
14
15
/**
16
 * Task contains name and workload to run with a handler.
17
 *
18
 * @author @wachterjohannes <[email protected]>
19
 */
20
class Task implements TaskInterface
21
{
22
    /**
23
     * @var string
24
     */
25
    private $uuid;
26
27
    /**
28
     * @var string
29
     */
30
    private $taskName;
31
32
    /**
33
     * @var string
34
     */
35
    private $key;
36
37
    /**
38
     * @var string|\Serializable
39
     */
40
    private $workload;
41
42
    /**
43
     * @var \DateTime
44
     */
45
    private $executionDate;
46
47
    /**
48
     * @var bool
49
     */
50
    private $completed = false;
51
52
    /**
53
     * @var string|\Serializable
54
     */
55
    private $result;
56
57 9
    public function __construct($taskName, $workload, $uuid = null)
58
    {
59 9
        $this->uuid = $uuid ?: Uuid::uuid4()->toString();
60 9
        $this->taskName = $taskName;
61 9
        $this->workload = $workload;
62 9
        $this->executionDate = new \DateTime();
63 9
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function getUuid()
69
    {
70
        return $this->uuid;
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76 7
    public function getTaskName()
77
    {
78 7
        return $this->taskName;
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 1
    public function getKey()
85
    {
86 1
        return $this->key;
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92 1
    public function setKey($key)
93
    {
94 1
        $this->key = $key;
95
96 1
        return $this;
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102 7
    public function getWorkload()
103
    {
104 7
        return $this->workload;
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110
    public function isCompleted()
111
    {
112
        return $this->completed;
113
    }
114
115
    /**
116
     * {@inheritdoc}
117
     */
118
    public function setCompleted()
119
    {
120
        $this->completed = true;
121
    }
122
123
    /**
124
     * {@inheritdoc}
125
     */
126
    public function getResult()
127
    {
128
        return $this->result;
129
    }
130
131
    /**
132
     * {@inheritdoc}
133
     */
134
    public function setResult($result)
135
    {
136
        $this->result = $result;
137
    }
138
139
    /**
140
     * {@inheritdoc}
141
     */
142 1
    public function getExecutionDate()
143
    {
144 1
        return $this->executionDate;
145
    }
146
147
    /**
148
     * {@inheritdoc}
149
     */
150 1
    public function setExecutionDate(\DateTime $executionDate)
151
    {
152 1
        $this->executionDate = $executionDate;
153 1
    }
154
}
155