Completed
Pull Request — master (#544)
by Maxence
02:26
created

RemoteRequest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 87
Duplicated Lines 40.23 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 35
loc 87
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 9 9 1
A update() 10 10 1
A updateInstance() 8 8 1
A updateHref() 8 8 1
A getFromHref() 0 6 1
A getFromInstance() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
28
namespace OCA\Circles\Db;
29
30
31
use daita\MySmallPhpTools\Exceptions\RowNotFoundException;
32
use OCA\Circles\Exceptions\RemoteUidException;
33
use OCA\Circles\Model\AppService;
34
35
36
/**
37
 * Class GSEventsRequest
38
 *
39
 * @package OCA\Circles\Db
40
 */
41
class RemoteRequest extends RemoteRequestBuilder {
42
43
44
	/**
45
	 * @param AppService $remote
46
	 */
47 View Code Duplication
	public function save(AppService $remote): void {
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...
48
		$qb = $this->getRemoteInsertSql();
49
		$qb->setValue('uid', $qb->createNamedParameter($remote->getUid(true)))
50
		   ->setValue('instance', $qb->createNamedParameter($remote->getInstance()))
51
		   ->setValue('href', $qb->createNamedParameter($remote->getId()))
52
		   ->setValue('item', $qb->createNamedParameter(json_encode($remote->getOrigData())));
53
54
		$qb->execute();
55
	}
56
57
58
	/**
59
	 * @param AppService $remote
60
	 */
61 View Code Duplication
	public function update(AppService $remote) {
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...
62
		$qb = $this->getRemoteUpdateSql();
63
		$qb->set('uid', $qb->createNamedParameter($remote->getUid(true)))
64
		   ->set('href', $qb->createNamedParameter($remote->getId()))
65
		   ->set('item', $qb->createNamedParameter(json_encode($remote->getOrigData())));
66
67
		$qb->limitToInstance($remote->getInstance());
68
69
		$qb->execute();
70
	}
71
72
73
	/**
74
	 * @param AppService $remote
75
	 */
76 View Code Duplication
	public function updateInstance(AppService $remote) {
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...
77
		$qb = $this->getRemoteUpdateSql();
78
		$qb->set('instance', $qb->createNamedParameter($remote->getInstance()));
79
80
		$qb->limitToDBField('uid', $remote->getUid(true), false);
81
82
		$qb->execute();
83
	}
84
85
86
	/**
87
	 * @param AppService $remote
88
	 */
89 View Code Duplication
	public function updateHref(AppService $remote) {
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...
90
		$qb = $this->getRemoteUpdateSql();
91
		$qb->set('href', $qb->createNamedParameter($remote->getId()));
92
93
		$qb->limitToDBField('uid', $remote->getUid(true), false);
94
95
		$qb->execute();
96
	}
97
98
99
	/**
100
	 * @param string $host
101
	 *
102
	 * @return AppService
103
	 * @throws RowNotFoundException
104
	 */
105
	public function getFromInstance(string $host): AppService {
106
		$qb = $this->getRemoteSelectSql();
107
		$qb->limitToInstance($host);
108
109
		return $this->getItemFromRequest($qb);
110
	}
111
112
113
	/**
114
	 * @param string $href
115
	 *
116
	 * @return AppService
117
	 * @throws RowNotFoundException
118
	 */
119
	public function getFromHref(string $href): AppService {
120
		$qb = $this->getRemoteSelectSql();
121
		$qb->limitToDBField('href', $href, false);
122
123
		return $this->getItemFromRequest($qb);
124
	}
125
126
127
}
128
129