Completed
Pull Request — master (#362)
by Maxence
01:49
created

CircleStatus::verify()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php declare(strict_types=1);
2
3
4
/**
5
 * Circles - Bring cloud-users closer together.
6
 *
7
 * This file is licensed under the Affero General Public License version 3 or
8
 * later. See the COPYING file.
9
 *
10
 * @author Maxence Lange <[email protected]>
11
 * @copyright 2017
12
 * @license GNU AGPL version 3 or any later version
13
 *
14
 * This program is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License as
16
 * published by the Free Software Foundation, either version 3 of the
17
 * License, or (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Affero General Public License
25
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
 *
27
 */
28
29
30
namespace OCA\Circles\GlobalScale;
31
32
33
use OCA\Circles\Exceptions\CircleDoesNotExistException;
34
use OCA\Circles\Model\GlobalScale\GSEvent;
35
use OCA\Circles\Model\Member;
36
37
38
/**
39
 * Class CircleStatus
40
 *
41
 * @package OCA\Circles\GlobalScale
42
 */
43
class CircleStatus extends AGlobalScaleEvent {
44
45
46
	const STATUS_ERROR = -1;
47
	const STATUS_OK = 1;
48
	const STATUS_NOT_OWNER = 8;
49
	const STATUS_NOT_FOUND = 404;
50
51
52
	/**
53
	 * @param GSEvent $event
54
	 * @param bool $localCheck
55
	 * @param bool $mustBeChecked
56
	 */
57
	public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
58
	}
59
60
61
	/**
62
	 * @param GSEvent $event
63
	 */
64
	public function manage(GSEvent $event): void {
65
		$circle = $event->getCircle();
66
		$status = self::STATUS_ERROR;
67
68
		try {
69
			$this->circlesRequest->forceGetCircle($circle->getUniqueId());
70
			$owners = $this->membersRequest->forceGetMembers($circle->getUniqueId(), Member::LEVEL_OWNER);
71
			if (!empty($owners)) {
72
				$owner = $owners[0];
73
				if ($owner->getInstance() === '') {
74
					$status = self::STATUS_OK;
75
				} else {
76
					$status = self::STATUS_NOT_OWNER;
77
					$event->getData()
78
						  ->sObj('supposedOwner', $owner);
79
				}
80
			}
81
		} catch (CircleDoesNotExistException $e) {
82
			$status = self::STATUS_NOT_FOUND;
83
		}
84
85
		$event->getData()
86
			  ->sInt('status', $status);
87
	}
88
89
90
	/**
91
	 * @param GSEvent[] $events
92
	 */
93
	public function result(array $events): void {
94
	}
95
}
96
97