Completed
Push — master ( 6b6a4c...4ac435 )
by Maxence
02:56 queued 01:19
created

MembersRemove::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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\Command;
31
32
use Exception;
33
use OC\Core\Command\Base;
34
use OCA\Circles\Exceptions\MemberDoesNotExistException;
35
use OCA\Circles\Service\MembersService;
36
use OCP\IL10N;
37
use Symfony\Component\Console\Input\InputArgument;
38
use Symfony\Component\Console\Input\InputInterface;
39
use Symfony\Component\Console\Output\OutputInterface;
40
41
42
/**
43
 * Class MembersRemove
44
 *
45
 * @package OCA\Circles\Command
46
 */
47
class MembersRemove extends Base {
48
49
50
	/** @var IL10N */
51
	private $l10n;
52
53
	/** @var MembersService */
54
	private $membersService;
55
56
57
	/**
58
	 * MembersRemove constructor.
59
	 *
60
	 * @param IL10N $l10n
61
	 * @param MembersService $membersService
62
	 */
63
	public function __construct(IL10N $l10n, MembersService $membersService) {
64
		parent::__construct();
65
		$this->l10n = $l10n;
66
		$this->membersService = $membersService;
67
	}
68
69
70
	protected function configure() {
71
		parent::configure();
72
		$this->setName('circles:members:remove')
73
			 ->setDescription('remove a member from a circle')
74
			 ->addArgument('member_id', InputArgument::REQUIRED, 'ID of the member to be expel');
75
	}
76
77
78
	/**
79
	 * @param InputInterface $input
80
	 * @param OutputInterface $output
81
	 *
82
	 * @return int
83
	 * @throws MemberDoesNotExistException
84
	 * @throws Exception
85
	 */
86
	protected function execute(InputInterface $input, OutputInterface $output): int {
87
		$memberId = $input->getArgument('member_id');
88
89
		$member = $this->membersService->getMemberById($memberId);
90
		$this->membersService->removeMember($member->getCircleId(), $member->getUserId(), $member->getType(), true);
91
92
		return 0;
93
	}
94
95
}
96
97