ScheduleExpression   A
last analyzed

Complexity

Total Complexity 26

Size/Duplication

Total Lines 355
Duplicated Lines 0 %

Coupling/Cohesion

Components 10
Dependencies 0

Test Coverage

Coverage 6.1%

Importance

Changes 0
Metric Value
wmc 26
lcom 10
cbo 0
dl 0
loc 355
c 0
b 0
f 0
ccs 5
cts 82
cp 0.061
rs 10

23 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 4 1
A unserialize() 0 6 2
A dayOfMonth() 0 5 1
A dayOfWeek() 0 5 1
A end() 0 5 1
A getDayOfMonth() 0 4 1
A getDayOfWeek() 0 4 1
A getEnd() 0 4 1
A getHour() 0 4 1
A getMinute() 0 4 1
A getMonth() 0 4 1
A getSecond() 0 4 1
A getStart() 0 4 1
A getTimezone() 0 10 3
A getYear() 0 4 1
A hour() 0 5 1
A minute() 0 5 1
A month() 0 5 1
A second() 0 5 1
A start() 0 5 1
A timezone() 0 5 1
A year() 0 5 1
A __toString() 0 27 1
1
<?php
2
3
/**
4
 * AppserverIo\Psr\EnterpriseBeans\ScheduleExpression
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2015 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io-psr/epb
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Psr\EnterpriseBeans;
22
23
/**
24
 * A calendar-based timeout expression for an enterprise bean timer.
25
 *
26
 * Each expression attribute has two overloaded setter methods, one that takes a String and one that takes an int.
27
 * The int version is merely a convenience method for setting the attribute in the common case that the value is a
28
 * simple integer.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2015 TechDivision GmbH <[email protected]>
32
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
33
 * @link      https://github.com/appserver-io-psr/epb
34
 * @link      http://www.appserver.io
35
 */
36
class ScheduleExpression implements \Serializable
37
{
38
39
    /**
40
     * The date format we use to serialize/unserialize \DateTime properties.
41
     *
42
     * @var string
43
     */
44
    const DATE_FORMAT = 'Y-m-d H:i:s';
45
46
    /**
47
     * @var string
48
     */
49
    private $dayOfMonth = "*";
50
51
    /**
52
     * @var string
53
     */
54
    private $dayOfWeek = "*";
55
56
    /**
57
     * @var string
58
     */
59
    private $end;
60
61
    /**
62
     * @var string
63
     */
64
    private $hour = "0";
65
66
    /**
67
     * @var string
68
     */
69
    private $minute = "0";
70
71
    /**
72
     * @var string
73
     */
74
    private $month = "*";
75
76
    /**
77
     * @var string
78
     */
79
    private $second = "0";
80
81
    /**
82
     * @var string
83
     */
84
    private $start;
85
86
    /**
87
     * @var string
88
     */
89
    private $timezone = "";
90
91
    /**
92
     * @var string
93
     */
94
    private $year = "*";
95
96
    /**
97
     * String representation of object.
98
      *
99
     * @return string the string representation of the object or null
100
     * @link http://php.net/manual/en/serializable.serialize.php
101
     */
102
    public function serialize()
103
    {
104
        return serialize(get_object_vars($this));
105
    }
106
107
    /**
108
     * Constructs the object
109
     *
110
     * @param string $data The string representation of the object
111
     *
112
     * @return void
113
     * @link http://php.net/manual/en/serializable.unserialize.php
114
     */
115
    public function unserialize($data)
116
    {
117
        foreach (unserialize($data) as $propertyName => $propertyValue) {
118
            $this->$propertyName = $propertyValue;
119
        }
120
    }
121
122
    /**
123
     * Sets the day of month
124
     *
125
     * @param String $dayOfMonth The string
126
     *
127
     * @return \AppserverIo\Psr\EnterpriseBeans\ScheduleExpression
128
     */
129
    public function dayOfMonth($dayOfMonth)
130
    {
131
        $this->dayOfMonth = (string) $dayOfMonth;
132
        return $this;
133
    }
134
135
    /**
136
     * Sets the day of week
137
     *
138
     * @param int|string $dayOfWeek The day of week
139
     *
140
     * @return \AppserverIo\Psr\EnterpriseBeans\ScheduleExpression
141
     */
142
    public function dayOfWeek($dayOfWeek)
143
    {
144
        $this->dayOfWeek = (string) $dayOfWeek;
145
        return $this;
146
    }
147
148
    /**
149
     * Sets the day of week.
150
     *
151
     * @param string $end The end date time
152
     *
153
     * @return \AppserverIo\Psr\EnterpriseBeans\ScheduleExpression
154
     */
155
    public function end($end)
156
    {
157
        $this->end = (string) $end;
158
        return $this;
159
    }
160
161
    /**
162
     * Returns day of month.
163
     *
164
     * @return string
165
     */
166
    public function getDayOfMonth()
167
    {
168
        return $this->dayOfMonth;
169
    }
170
171
    /**
172
     * Returns day of week.
173
     *
174
     * @return string
175
     */
176
    public function getDayOfWeek()
177
    {
178
        return $this->dayOfWeek;
179
    }
180
181
    /**
182
     * Returns end datetime.
183
     *
184
     * @return string
185
     */
186
    public function getEnd()
187
    {
188
        return $this->end;
189
    }
190
191
    /**
192
     * Returns hour.
193
     *
194
     * @return string
195
     */
196
    public function getHour()
197
    {
198
        return $this->hour;
199
    }
200
201
    /**
202
     * Returns minute.
203
     *
204
     * @return string
205
     */
206
    public function getMinute()
207
    {
208
        return $this->minute;
209
    }
210
211
    /**
212
     * Returns month.
213
     *
214
     * @return string
215
     */
216 1
    public function getMonth()
217
    {
218 1
        return $this->month;
219
    }
220
221
    /**
222
     * Returns second.
223
     *
224
     * @return string
225
     */
226
    public function getSecond()
227
    {
228
        return $this->second;
229
    }
230
231
    /**
232
     * Returns start date time.
233
     *
234
     * @return string
235
     */
236
    public function getStart()
237
    {
238
        return $this->start;
239
    }
240
241
    /**
242
     * Returns the timezone.
243
     *
244
     * @return null|string
245
     */
246
    public function getTimezone()
247
    {
248
        // Note that attributes use the empty string "" as a default,
249
        // so the expression @Schedule(timezone="", ...) will result in a null value from the
250
        // corresponding ScheduleExpression->getTimezone() method.
251
        if ($this->timezone != null && empty($this->timezone)) {
252
            return null;
253
        }
254
        return $this->timezone;
255
    }
256
257
    /**
258
     * Returns the year.
259
     *
260
     * @return string
261
     */
262
    public function getYear()
263
    {
264
        return $this->year;
265
    }
266
267
    /**
268
     * Sets the hour.
269
     *
270
     * @param int|string $hour the hour to set
271
     *
272
     * @return \AppserverIo\Psr\EnterpriseBeans\ScheduleExpression
273
     */
274
    public function hour($hour)
275
    {
276
        $this->hour = (string) $hour;
277
        return $this;
278
    }
279
280
    /**
281
     * Sets the minute.
282
     *
283
     * @param int|string $minute The minute to set
284
     *
285
     * @return \AppserverIo\Psr\EnterpriseBeans\ScheduleExpression
286
     */
287
    public function minute($minute)
288
    {
289
        $this->minute = (string) $minute;
290
        return $this;
291
    }
292
293
    /**
294
     * Sets the month.
295
     *
296
     * @param int|string $month The month to set
297
     *
298
     * @return \AppserverIo\Psr\EnterpriseBeans\ScheduleExpression
299
     */
300 1
    public function month($month)
301
    {
302 1
        $this->month = (string) $month;
303 1
        return $this;
304
    }
305
306
    /**
307
     * Sets the second.
308
     *
309
     * @param int|string $second The second to set
310
     *
311
     * @return \AppserverIo\Psr\EnterpriseBeans\ScheduleExpression
312
     */
313
    public function second($second)
314
    {
315
        $this->second = (string) $second;
316
        return $this;
317
    }
318
319
    /**
320
     * Sets the start date time.
321
     *
322
     * @param string $start The start date time to set
323
     *
324
     * @return \AppserverIo\Psr\EnterpriseBeans\ScheduleExpression
325
     */
326
    public function start($start)
327
    {
328
        $this->start = (string) $start;
329
        return $this;
330
    }
331
332
    /**
333
     * Sets the timezone.
334
     *
335
     * @param int|string $timezone The timezone to set
336
     *
337
     * @return \AppserverIo\Psr\EnterpriseBeans\ScheduleExpression
338
     */
339
    public function timezone($timezone)
340
    {
341
        $this->timezone = (string) $timezone;
342
        return $this;
343
    }
344
345
    /**
346
     * Sets the year.
347
     *
348
     * @param int|string $year The year to set
349
     *
350
     * @return \AppserverIo\Psr\EnterpriseBeans\ScheduleExpression
351
     */
352
    public function year($year)
353
    {
354
        $this->year = (string) $year;
355
        return $this;
356
    }
357
358
    /**
359
     * Renders the object to string.
360
     *
361
     * @return string
362
     */
363
    public function __toString()
364
    {
365
        $s = "ScheduleExpression[";
366
        $s .= "second=";
367
        $s .= $this->second;
368
        $s .= " minute=";
369
        $s .= $this->minute;
370
        $s .= " hour=";
371
        $s .= $this->hour;
372
        $s .= " dayOfWeek=";
373
        $s .= $this->dayOfWeek;
374
        $s .= " dayOfMonth=";
375
        $s .= $this->dayOfMonth;
376
        $s .= " month=";
377
        $s .= $this->month;
378
        $s .= " year=";
379
        $s .= $this->year;
380
        $s .= " start=";
381
        $s .= (string)$this->start;
382
        $s .= " end=";
383
        $s .= (string)$this->end;
384
        $s .= " timezone=";
385
        $s .= $this->timezone;
386
        $s .= "]";
387
388
        return $s;
389
    }
390
}
391