Completed
Pull Request — master (#347)
by Maxence
01:46
created

SyncContact::addLinkedGroups()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
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\CommandMissingArgumentException;
35
use OCA\Circles\Exceptions\FakeException;
36
use OCA\Circles\Service\DavService;
37
use Symfony\Component\Console\Input\InputInterface;
38
use Symfony\Component\Console\Output\OutputInterface;
39
40
41
/**
42
 * Class SyncContact
43
 *
44
 * @package OCA\Circles\Command
45
 */
46
class SyncContact extends Base {
47
48
49
	/** @var DavService */
50
	private $davService;
51
52
53
	/**
54
	 * Groups constructor.
55
	 *
56
	 * @param DavService $davService
57
	 */
58
	public function __construct(DavService $davService) {
59
		parent::__construct();
60
61
		$this->davService = $davService;
62
	}
63
64
65
	protected function configure() {
66
		parent::configure();
67
		$this->setName('circles:contacts:sync')
68
			 ->setDescription('sync contacts, when using the Circles app as a backend of the Contact app');
69
	}
70
71
72
	/**
73
	 * @param InputInterface $input
74
	 * @param OutputInterface $output
75
	 *
76
	 * @return int|void|null
77
	 * @throws Exception
78
	 */
79
	protected function execute(InputInterface $input, OutputInterface $output) {
80
		$this->davService->migration();
81
82
		$output->writeln('migration done');
83
	}
84
85
86
	/**
87
	 * @param InputInterface $input
88
	 * @param OutputInterface $output
89
	 *
90
	 * @throws FakeException
91
	 */
92
	private function listLinkedGroups(InputInterface $input, OutputInterface $output) {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
93
		if ($input->getOption('list') !== true) {
94
			return;
95
		}
96
97
		throw new FakeException();
98
	}
99
100
101
	/**
102
	 * @param InputInterface $input
103
	 * @param OutputInterface $output
104
	 *
105
	 * @throws FakeException
106
	 */
107 View Code Duplication
	private function addLinkedGroups(InputInterface $input, OutputInterface $output) {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
108
		if ($input->getOption('link') !== true) {
109
			return;
110
		}
111
112
		list($circleId, $group) = $this->getCircleIdAndGroupFromArguments($input);
0 ignored issues
show
Unused Code introduced by
The assignment to $circleId is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $group is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
113
114
		throw new FakeException();
115
	}
116
117
118
	/**
119
	 * @param InputInterface $input
120
	 * @param OutputInterface $output
121
	 *
122
	 * @throws FakeException
123
	 */
124 View Code Duplication
	private function delLinkedGroups(InputInterface $input, OutputInterface $output) {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
125
		if ($input->getOption('unlink') !== true) {
126
			return;
127
		}
128
129
		list($circleId, $group) = $this->getCircleIdAndGroupFromArguments($input);
0 ignored issues
show
Unused Code introduced by
The assignment to $circleId is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
Unused Code introduced by
The assignment to $group is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
130
131
		throw new FakeException();
132
	}
133
134
135 View Code Duplication
	private function getCircleIdAndGroupFromArguments(InputInterface $input) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
136
		if ($input->getArgument('circle_id') === null
137
			|| $input->getArgument('group') === null) {
138
			throw new CommandMissingArgumentException();
139
//			$this->l10n->t(
140
//				'Missing argument: {cmd} circle_id group', ['cmd' => './occ circles:link']
141
//			)
142
		}
143
144
		return [$input->getArgument('circle_id'), $input->getArgument('group')];
145
	}
146
147
}
148
149