Completed
Pull Request — master (#877)
by René
91:19
created

Option   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 43
ccs 0
cts 15
cp 0
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 15 3
A setOrder() 0 5 2
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 integer getId()
34
 * @method void setId(integer $value)
35
 * @method integer getPollId()
36
 * @method void setPollId(integer $value)
37
 * @method string getPollOptionText()
38
 * @method void setPollOptionText(string $value)
39
 * @method integer getTimestamp()
40
 * @method void setTimestamp(integer $value)
41
 * @method integer getOrder()
42
 * @method void setOrder(integer $value)
43
 */
44
class Option extends Entity implements JsonSerializable {
45
46
	/** @var int $pollId */
47
	protected $pollId;
48
49
	/** @var string $pollOptionText */
50
	protected $pollOptionText;
51
52
	/** @var int $timestamp */
53
	protected $timestamp;
54
55
	/** @var int $order */
56
	protected $order;
57
58
	public function jsonSerialize() {
59
		if (intval($this->timestamp) > 0) {
60
			$timestamp = $this->timestamp;
61
		} elseif (strtotime($this->pollOptionText)) {
62
			$timestamp = strtotime($this->pollOptionText);
63
		} else {
64
			$timestamp = 0;
65
		}
66
67
		return [
68
			'id' => intval($this->id),
69
			'pollId' => intval($this->pollId),
70
			'pollOptionText' => htmlspecialchars_decode($this->pollOptionText),
71
			'timestamp' => intval($timestamp),
72
			'order' => setOrder($this->timestamp, $this->order)
0 ignored issues
show
Bug introduced by
The function setOrder was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
			'order' => /** @scrutinizer ignore-call */ setOrder($this->timestamp, $this->order)
Loading history...
73
		];
74
75
	}
76
77
	/**
78
	 * Temporary fix
79
	 * Make sure, order is eqal to timestamp in date polls
80
	 */
81
	 // TODO: remove by time
82
	private function setOrder($timestamp, $order) {
0 ignored issues
show
Unused Code introduced by
The method setOrder() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
83
		if ($timestamp > 0) {
84
			return intval($timestamp);
85
		} else {
86
			return intval($order);
87
		}
88
	}
89
}
90