Passed
Push — master ( 60d45f...a37810 )
by René
05:02 queued 01:25
created

Option::orderCorrection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
 *
5
 * @author Vinzenz Rosenkranz <[email protected]>
6
 * @author Kai Schröer <[email protected]>
7
 * @author René Gieling <[email protected]>
8
 *
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 *  This program is free software: you can redistribute it and/or modify
12
 *  it under the terms of the GNU Affero General Public License as
13
 *  published by the Free Software Foundation, either version 3 of the
14
 *  License, or (at your option) any later version.
15
 *
16
 *  This program is distributed in the hope that it will be useful,
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 *  GNU Affero General Public License for more details.
20
 *
21
 *  You should have received a copy of the GNU Affero General Public License
22
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
namespace OCA\Polls\Db;
27
28
use JsonSerializable;
29
30
use OCP\AppFramework\Db\Entity;
31
32
/**
33
 * @method int getId()
34
 * @method void setId(integer $value)
35
 * @method int getPollId()
36
 * @method void setPollId(integer $value)
37
 * @method string getPollOptionText()
38
 * @method void setPollOptionText(string $value)
39
 * @method int getTimestamp()
40
 * @method void setTimestamp(integer $value)
41
 * @method int getOrder()
42
 * @method void setOrder(integer $value)
43
 * @method int getConfirmed()
44
 * @method void setConfirmed(integer $value)
45
 */
46
class Option extends Entity implements JsonSerializable {
47
48
	/** @var int $pollId */
49
	protected $pollId;
50
51
	/** @var string $pollOptionText */
52
	protected $pollOptionText;
53
54
	/** @var int $timestamp */
55
	protected $timestamp;
56
57
	/** @var int $order */
58
	protected $order;
59
60
	/** @var int $confirmed */
61
	protected $confirmed;
62
63
	public function jsonSerialize() {
64
		if (intval($this->timestamp) > 0) {
65
			$timestamp = $this->timestamp;
66
		} elseif (strtotime($this->pollOptionText)) {
67
			$timestamp = strtotime($this->pollOptionText);
68
		} else {
69
			$timestamp = 0;
70
		}
71
72
		return [
73
			'id' => intval($this->id),
74
			'pollId' => intval($this->pollId),
75
			'pollOptionText' => htmlspecialchars_decode($this->pollOptionText),
76
			'timestamp' => intval($timestamp),
77
			'order' => $timestamp ? $timestamp : $order,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $order seems to be never defined.
Loading history...
78
			'confirmed' => intval($this->confirmed),
79
			'no' => 0,
80
			'yes' => 0,
81
			'maybe' => 0,
82
			'realno' => 0,
83
			'rank' => 0,
84
			'votes' => 0,
85
		];
86
	}
87
}
88