Completed
Pull Request — master (#326)
by Maxence
01:36
created

TokensRequestBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 79
Duplicated Lines 12.66 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 10
loc 79
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getTokensInsertSql() 0 6 1
A getTokensUpdateSql() 0 6 1
A getTokensSelectSql() 0 11 1
A getTokensDeleteSql() 10 10 1
A parseTokensSelectSql() 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
/**
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 OCA\Circles\Model\SharesToken;
33
use OCP\DB\QueryBuilder\IQueryBuilder;
34
35
36
/**
37
 * Class TokensRequestBuilder
38
 *
39
 * @package OCA\Circles\Db
40
 */
41
class
42
TokensRequestBuilder extends CoreRequestBuilder {
43
44
45
	/**
46
	 * Base of the Sql Insert request for Shares
47
	 *
48
	 * @return IQueryBuilder
49
	 */
50
	protected function getTokensInsertSql() {
51
		$qb = $this->dbConnection->getQueryBuilder();
52
		$qb->insert(self::TABLE_TOKENS);
53
54
		return $qb;
55
	}
56
57
58
	/**
59
	 * Base of the Sql Update request for Groups
60
	 *
61
	 * @param int $circleId
62
	 * @param string $groupId
63
	 *
64
	 * @return IQueryBuilder
65
	 */
66
	protected function getTokensUpdateSql($circleId, $groupId) {
0 ignored issues
show
Unused Code introduced by
The parameter $circleId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $groupId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
		$qb = $this->dbConnection->getQueryBuilder();
68
		$qb->update(self::TABLE_TOKENS);
69
70
		return $qb;
71
	}
72
73
74
	/**
75
	 * @return IQueryBuilder
76
	 */
77
	protected function getTokensSelectSql() {
78
		$qb = $this->dbConnection->getQueryBuilder();
79
80
		/** @noinspection PhpMethodParametersCountMismatchInspection */
81
		$qb->select('t.user_id', 't.circle_id', 't.share_id', 't.token')
82
		   ->from(self::TABLE_TOKENS, 't');
83
84
		$this->default_select_alias = 't';
85
86
		return $qb;
87
	}
88
89
90
	/**
91
	 * Base of the Sql Delete request
92
	 *
93
	 * @return IQueryBuilder
94
	 */
95 View Code Duplication
	protected function getTokensDeleteSql() {
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...
96
		$qb = $this->dbConnection->getQueryBuilder();
97
		$qb->delete(self::TABLE_TOKENS);
98
		$qb->where(
99
			$qb->expr()
100
			   ->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE))
101
		);
102
103
		return $qb;
104
	}
105
106
107
	/**
108
	 * @param array $data
109
	 *
110
	 * @return SharesToken
111
	 */
112
	protected function parseTokensSelectSql($data) {
113
		$sharesToken = new SharesToken();
114
		$sharesToken->import($data);
115
116
		return $sharesToken;
117
	}
118
119
}
120