Completed
Push — testscrut1 ( a3f19e...5564ee )
by Maxence
09:16 queued 04:15
created

Circle::setCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * Circles - Bring cloud-users closer together.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\Circles\Model;
28
29
class Circle implements \JsonSerializable {
30
31
	const CIRCLES_PERSONAL = 1;
32
	const CIRCLES_HIDDEN = 2;
33
	const CIRCLES_PRIVATE = 4;
34
	const CIRCLES_PUBLIC = 8;
35
36
	const CIRCLES_ALL = 15;
37
38
	private $id;
39
	private $name;
40
41
	/** @var Member */
42
	private $owner;
43
44
	/** @var Member */
45
	private $user;
46
	private $description;
47
	private $type;
48
	private $typeString;
49
	private $typeLongString;
50
	private $creation;
51
	private $count;
0 ignored issues
show
Unused Code introduced by
The property $count is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
52
	private $members;
53
	private $info;
54
55
	public function __construct() {
56
57
	}
58
59
60
	public function setId($id) {
61
		$this->id = $id;
62
63
		return $this;
64
	}
65
66
	public function getId() {
67
		return $this->id;
68
	}
69
70
71
	public function setName($name) {
72
		$this->name = $name;
73
74
		return $this;
75
	}
76
77
	public function getName() {
78
		return $this->name;
79
	}
80
81
82
	public function getOwner() {
83
		return $this->owner;
84
	}
85
86
	public function setOwner($owner) {
87
		$this->owner = $owner;
88
	}
89
90
91
	public function getUser() {
92
		return $this->user;
93
	}
94
95
	public function setUser($user) {
96
		$this->user = $user;
97
	}
98
99
100
	public function setDescription($description) {
101
		$this->description = $description;
102
103
		return $this;
104
	}
105
106
	public function getDescription() {
107
		return $this->description;
108
	}
109
110
111
	public function setType($type) {
112
		$this->type = (int)$type;
113
		$this->setTypeString(self::TypeString($type));
114
		$this->setTypeLongString(self::TypeLongString($type));
115
		$this->setInfo($this->getTypeLongString());
116
117
		return $this;
118
	}
119
120
	public function getType() {
121
		return $this->type;
122
	}
123
124
	public function setTypeString($str) {
125
		$this->typeString = $str;
126
127
		return $this;
128
	}
129
130
	public function getTypeString() {
131
		return $this->typeString;
132
	}
133
134
	public function setTypeLongString($str) {
135
		$this->typeLongString = $str;
136
	}
137
138
	public function getTypeLongString() {
139
		return $this->typeLongString;
140
	}
141
142
143
	public function setInfo($str) {
144
		$this->info = $str;
145
	}
146
147
	public function getInfo() {
148
		return $this->info;
149
	}
150
151
152
	public function setCreation($creation) {
153
		$this->creation = $creation;
154
155
		return $this;
156
	}
157
158
	public function getCreation() {
159
		return $this->creation;
160
	}
161
162
163
//	public function setCount($count) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
164
//		$this->count = $count;
165
//
166
//		return $this;
167
//	}
168
//
169
//	public function getCount() {
170
//		return $this->count;
171
//	}
172
173
	public function setMembers($members) {
174
		$this->members = $members;
175
176
		return $this;
177
	}
178
179
	public function getMembers() {
180
		return $this->members;
181
	}
182
183
184
	public function toString() {
185
		return "toString ?";
186
	}
187
188
	public function jsonSerialize() {
189
		return array(
190
			'id'          => $this->getId(),
191
			'name'        => $this->getName(),
192
			'owner'       => $this->getOwner(),
193
			'user'        => $this->getUser(),
194
			'description' => $this->getDescription(),
195
			'type'        => $this->getTypeString(),
196
			'creation'    => $this->getCreation(),
197
			'members'     => $this->getMembers()
198
		);
199
	}
200
201
	public static function fromArray($arr) {
202
		$circle = new Circle();
203
		$circle->setId($arr['id']);
204
205
		$circle->setName($arr['name']);
206
		$circle->setDescription($arr['description']);
207
		$circle->setType($arr['type']);
208
		$circle->setCreation($arr['creation']);
209
//		if (key_exists('count', $arr)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
210
//			$circle->setCount($arr['count']);
211
//		}
212
213
		$circle->setOwner(self::getOwnerMemberFromArray($arr));
214
		$circle->setUser(self::getUserMemberFromArray($arr));
215
216
		return $circle;
217
	}
218
219
220
	/**
221
	 * return Owner Infos from Array
222
	 *
223
	 * @param $array
224
	 *
225
	 * @return null|Member
226
	 */
227
	private static function getOwnerMemberFromArray($array) {
228
		if (key_exists('owner', $array)) {
229
			$owner = new Member();
230
			$owner->setUserId($array['owner']);
231
232
			return $owner;
233
		}
234
235
		return null;
236
	}
237
238
	/**
239
	 * return User Infos from Array
240
	 *
241
	 * @param $array
242
	 *
243
	 * @return null|Member
244
	 */
245
	private static function getUserMemberFromArray($array) {
246
247
		if (key_exists('status', $array)
248
			&& key_exists('level', $array)
249
			&& key_exists('joined', $array)
250
		) {
251
			$user = new Member();
252
			$user->setStatus($array['status']);
253
			$user->setLevel($array['level']);
254
			$user->setJoined($array['joined']);
255
256
			return $user;
257
		}
258
259
		return null;
260
	}
261
262
263
	public static function TypeString($type) {
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
264
		switch ($type) {
265
			case self::CIRCLES_PERSONAL:
266
				return 'Personal';
267
			case self::CIRCLES_HIDDEN:
268
				return 'Hidden';
269
			case self::CIRCLES_PRIVATE:
270
				return 'Private';
271
			case self::CIRCLES_PUBLIC:
272
				return 'Public';
273
			case self::CIRCLES_ALL:
274
				return 'All';
275
		}
276
277
		return 'none';
278
	}
279
280
	/**
281
	 * @param $type
282
	 *
283
	 * @return string
284
	 */
285
	public static function TypeLongString($type) {
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
286
		switch ($type) {
287
			case self::CIRCLES_PERSONAL:
288
				return 'Personal Circle';
289
			case self::CIRCLES_HIDDEN:
290
				return 'Hidden Circle';
291
			case self::CIRCLES_PRIVATE:
292
				return 'Private Circle';
293
			case self::CIRCLES_PUBLIC:
294
				return 'Public Circle';
295
			case self::CIRCLES_ALL:
296
				return 'All Circles';
297
		}
298
299
		return 'none';
300
	}
301
302
}
303
304
305