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

RemoteRequestBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 8.86 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRemoteInsertSql() 7 7 1
A getRemoteUpdateSql() 0 6 1
A getRemoteSelectSql() 0 9 1
A getRemoteDeleteSql() 0 6 1
A getItemFromRequest() 0 6 1
A getItemsFromRequest() 0 4 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
/**
4
 * Circles - Bring cloud-users closer together.
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Maxence Lange <[email protected]>
10
 * @copyright 2017
11
 * @license GNU AGPL version 3 or any later version
12
 *
13
 * This program is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU Affero General Public License as
15
 * published by the Free Software Foundation, either version 3 of the
16
 * License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU Affero General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Affero General Public License
24
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
 *
26
 */
27
28
29
namespace OCA\Circles\Db;
30
31
32
use daita\MySmallPhpTools\Exceptions\RowNotFoundException;
33
use OCA\Circles\Model\AppService;
34
35
/**
36
 * Class GSEventsRequestBuilder
37
 *
38
 * @package OCA\Circles\Db
39
 */
40
class RemoteRequestBuilder extends CoreRequestBuilder {
41
42
43
	/**
44
	 * @return CoreQueryBuilder
45
	 */
46 View Code Duplication
	protected function getRemoteInsertSql(): CoreQueryBuilder {
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...
47
		$qb = $this->getQueryBuilder();
48
		$qb->insert(self::TABLE_REMOTE)
49
		   ->setValue('creation', $qb->createNamedParameter($this->timezoneService->getUTCDate()));
50
51
		return $qb;
52
	}
53
54
55
	/**
56
	 * Base of the Sql Update request for Groups
57
	 *
58
	 * @return CoreQueryBuilder
59
	 */
60
	protected function getRemoteUpdateSql(): CoreQueryBuilder {
61
		$qb = $this->getQueryBuilder();
62
		$qb->update(self::TABLE_REMOTE);
63
64
		return $qb;
65
	}
66
67
68
	/**
69
	 * @return CoreQueryBuilder
70
	 */
71
	protected function getRemoteSelectSql(): CoreQueryBuilder {
72
		$qb = $this->getQueryBuilder();
73
		$qb->select('r.id', 'r.uid', 'r.instance', 'r.href', 'r.item', 'r.creation')
74
		   ->from(self::TABLE_REMOTE, 'r');
75
76
		$qb->setDefaultSelectAlias('r');
77
78
		return $qb;
79
	}
80
81
82
	/**
83
	 * Base of the Sql Delete request
84
	 *
85
	 * @return CoreQueryBuilder
86
	 */
87
	protected function getRemoteDeleteSql(): CoreQueryBuilder {
88
		$qb = $this->getQueryBuilder();
89
		$qb->delete(self::TABLE_REMOTE);
90
91
		return $qb;
92
	}
93
94
95
	/**
96
	 * @param CoreQueryBuilder $qb
97
	 *
98
	 * @return AppService
99
	 * @throws RowNotFoundException
100
	 */
101
	public function getItemFromRequest(CoreQueryBuilder $qb): AppService {
102
		/** @var AppService $appService */
103
		$appService = $qb->asItem(AppService::class);
104
105
		return $appService;
106
	}
107
108
	/**
109
	 * @param CoreQueryBuilder $qb
110
	 *
111
	 * @return AppService[]
112
	 */
113
	public function getItemsFromRequest(CoreQueryBuilder $qb): array {
114
		/** @var AppService[] $result */
115
		return $qb->asItems(AppService::class);
116
	}
117
118
}
119