Completed
Push — master ( 908eaf...3a56d9 )
by Maxence
02:45
created

CirclesQueryHelper::limitToInheritedMembers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
dl 23
loc 23
rs 9.552
c 0
b 0
f 0
cc 1
nc 1
nop 4
1
<?php
2
3
declare(strict_types=1);
4
5
6
/**
7
 * Circles - Bring cloud-users closer together.
8
 *
9
 * This file is licensed under the Affero General Public License version 3 or
10
 * later. See the COPYING file.
11
 *
12
 * @author Maxence Lange <[email protected]>
13
 * @copyright 2021
14
 * @license GNU AGPL version 3 or any later version
15
 *
16
 * This program is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License as
18
 * published by the Free Software Foundation, either version 3 of the
19
 * License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU Affero General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Affero General Public License
27
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
28
 *
29
 */
30
31
32
namespace OCA\Circles;
33
34
35
use OCA\Circles\Db\CoreQueryBuilder;
36
use OCA\Circles\Db\CoreRequestBuilder;
37
use OCA\Circles\Exceptions\CircleNotFoundException;
38
use OCA\Circles\Exceptions\RequestBuilderException;
39
use OCA\Circles\Model\Circle;
40
use OCP\DB\QueryBuilder\ICompositeExpression;
41
use OCP\DB\QueryBuilder\IQueryBuilder;
42
43
44
/**
45
 * Class CirclesQueryHelper
46
 *
47
 * @package OCA\Circles
48
 */
49
class CirclesQueryHelper {
50
51
52
	/** @var CoreRequestBuilder */
53
	private $coreRequestBuilder;
54
55
	/** @var CoreQueryBuilder */
56
	private $queryBuilder;
57
58
	/**
59
	 * CirclesQueryHelper constructor.
60
	 *
61
	 * @param CoreRequestBuilder $coreRequestBuilder
62
	 */
63
	public function __construct(
64
		CoreRequestBuilder $coreRequestBuilder
65
	) {
66
		$this->coreRequestBuilder = $coreRequestBuilder;
67
	}
68
69
70
	/**
71
	 * @return IQueryBuilder
72
	 */
73
	public function getQueryBuilder(): IQueryBuilder {
74
		$this->queryBuilder = $this->coreRequestBuilder->getQueryBuilder();
75
76
		return $this->queryBuilder;
77
	}
78
79
80
	/**
81
	 * @param string $alias
82
	 * @param string $field
83
	 * @param IFederatedUser $federatedUser
84
	 * @param bool $fullDetails
85
	 *
86
	 * @return ICompositeExpression
87
	 * @throws RequestBuilderException
88
	 */
89 View Code Duplication
	public function limitToInheritedMembers(
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
		string $alias,
91
		string $field,
92
		IFederatedUser $federatedUser,
93
		bool $fullDetails = false
94
	): ICompositeExpression {
95
		$this->queryBuilder->setBypassAliasGeneration(true);
96
		$this->queryBuilder->setDefaultSelectAlias($alias);
97
		$this->queryBuilder->setOptions(
98
			[CoreQueryBuilder::HELPER],
99
			[
100
				'getData'      => $fullDetails,
101
				'mustBeMember' => true
102
			]
103
		);
104
105
		return $this->queryBuilder->limitToInitiator(
106
			CoreQueryBuilder::HELPER,
107
			$federatedUser,
108
			$field,
109
			$alias
110
		);
111
	}
112
113
114
	/**
115
	 * @param string $field
116
	 * @param string $alias
117
	 *
118
	 * @throws RequestBuilderException
119
	 */
120 View Code Duplication
	public function addCircleDetails(
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...
121
		string $alias,
122
		string $field
123
	): void {
124
		$this->queryBuilder->setBypassAliasGeneration(true);
125
		$this->queryBuilder->setDefaultSelectAlias($alias);
126
		$this->queryBuilder->setOptions(
127
			[CoreQueryBuilder::HELPER],
128
			[
129
				'getData' => true
130
			]
131
		);
132
133
		$this->queryBuilder->leftJoinCircle(CoreQueryBuilder::HELPER, null, $field, $alias);
134
	}
135
136
137
	/**
138
	 * @param array $data
139
	 *
140
	 * @return Circle
141
	 * @throws CircleNotFoundException
142
	 */
143
	public function extractCircle(array $data): Circle {
144
		$circle = new Circle();
145
		$circle->importFromDatabase(
146
			$data,
147
			CoreQueryBuilder::HELPER . '_' . CoreQueryBuilder::CIRCLE . '_'
148
		);
149
150
		return $circle;
151
	}
152
153
}
154
155