Passed
Pull Request — master (#548)
by René
04:19
created

Event   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 18.18%

Importance

Changes 0
Metric Value
eloc 45
dl 0
loc 59
ccs 6
cts 33
cp 0.1818
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A read() 0 36 4
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 OCP\AppFramework\Db\Entity;
29
30
/**
31
 * @method integer getType()
32
 * @method void setType(integer $value)
33
 * @method string getTitle()
34
 * @method void setTitle(string $value)
35
 * @method string getDescription()
36
 * @method void setDescription(string $value)
37
 * @method string getOwner()
38
 * @method void setOwner(string $value)
39
 * @method string getCreated()
40
 * @method void setCreated(string $value)
41
 * @method string getAccess()
42
 * @method void setAccess(string $value)
43
 * @method string getExpire()
44
 * @method void setExpire(string $value)
45
 * @method string getHash()
46
 * @method void setHash(string $value)
47
 * @method integer getIsAnonymous()
48
 * @method void setIsAnonymous(integer $value)
49
 * @method integer getFullAnonymous()
50
 * @method void setFullAnonymous(integer $value)
51
 * @method integer getAllowMaybe()
52
 * @method void setAllowMaybe(integer $value)
53
 */
54
class Event extends Model {
55
	protected $type;
56
	protected $title;
57
	protected $description;
58
	protected $owner;
59
	protected $created;
60
	protected $access;
61
	protected $expire;
62
	protected $hash;
63
	protected $isAnonymous;
64
	protected $fullAnonymous;
65
	protected $allowMaybe;
66
67
	/**
68
	 * Event constructor.
69
	 */
70 9
	public function __construct() {
71 9
		$this->addType('type', 'integer');
72 9
		$this->addType('isAnonymous', 'integer');
73 9
		$this->addType('fullAnonymous', 'integer');
74 9
		$this->addType('allowMaybe', 'integer');
75 9
	}
76
77
	public function read() {
78
79
		if ($this->getType() == 0) {
80
			$pollType = 'datePoll';
81
		} else {
82
			$pollType = 'textPoll';
83
		}
84
85
		$accessType = $this->getAccess();
86
		if (!strpos('|public|hidden|registered', $accessType)) {
87
			$accessType = 'select';
88
		}
89
		if ($this->getExpire() === null) {
0 ignored issues
show
introduced by
The condition $this->getExpire() === null is always false.
Loading history...
90
			$expired = false;
91
			$expiration = false;
92
		} else {
93
			$expired = time() > strtotime($this->getExpire());
94
			$expiration = true;
95
		}
96
97
		return [
98
			'id' => $this->getId(),
99
			'hash' => $this->getHash(),
100
			'type' => $pollType,
101
			'title' => $this->getTitle(),
102
			'description' => $this->getDescription(),
103
			'owner' => $this->getOwner(),
104
			'ownerDisplayName' => \OC_User::getDisplayName($this->getOwner()),
0 ignored issues
show
Bug introduced by
The type OC_User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
105
			'created' => $this->getCreated(),
106
			'access' => $accessType,
107
			'expiration' => $expiration,
108
			'expired' => $expired,
109
			'expirationDate' => $this->getExpire(),
110
			'isAnonymous' => $this->getIsAnonymous(),
111
			'fullAnonymous' => $this->getFullAnonymous(),
112
			'allowMaybe' => $this->getAllowMaybe()
113
		];
114
	}
115
}
116