Completed
Pull Request — master (#546)
by Maxence
01:58
created

MemberRequestBuilder::getMemberSelectSql()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Db;
33
34
35
use daita\MySmallPhpTools\Exceptions\RowNotFoundException;
36
use OCA\Circles\Exceptions\MemberNotFoundException;
37
use OCA\Circles\Model\Member;
38
39
40
/**
41
 * Class MemberRequestBuilder
42
 *
43
 * @package OCA\Circles\Db
44
 */
45
class MemberRequestBuilder extends CoreRequestBuilder {
46
47
48
	/**
49
	 * @return CoreQueryBuilder
50
	 */
51 View Code Duplication
	protected function getMemberInsertSql(): 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...
52
		$qb = $this->getQueryBuilder();
53
		$qb->insert(self::TABLE_MEMBER)
54
		   ->setValue('joined', $qb->createNamedParameter($this->timezoneService->getUTCDate()));
55
56
		return $qb;
57
	}
58
59
60
	/**
61
	 * @return CoreQueryBuilder
62
	 */
63
	protected function getMemberUpdateSql(): CoreQueryBuilder {
64
		$qb = $this->getQueryBuilder();
65
		$qb->update(self::TABLE_MEMBER);
66
67
		return $qb;
68
	}
69
70
71
	/**
72
	 * @return CoreQueryBuilder
73
	 */
74 View Code Duplication
	protected function getMemberSelectSql(): 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...
75
		$qb = $this->getQueryBuilder();
76
		$qb->select(
77
			'm.user_id', 'm.instance', 'm.user_type', 'm.circle_id', 'm.level', 'm.status', 'm.note',
78
			'm.contact_id', 'm.member_id', 'm.cached_name', 'm.cached_update', 'm.contact_meta', 'm.joined'
79
		)
80
		   ->from(self::TABLE_MEMBER, 'm')
81
		   ->orderBy('m.joined')
82
		   ->setDefaultSelectAlias('m');
83
84
		return $qb;
85
	}
86
87
88
	/**
89
	 * Base of the Sql Delete request
90
	 *
91
	 * @return CoreQueryBuilder
92
	 */
93
	protected function getMemberDeleteSql(): CoreQueryBuilder {
94
		$qb = $this->getQueryBuilder();
95
		$qb->delete(self::TABLE_MEMBER);
96
97
		return $qb;
98
	}
99
100
101
	/**
102
	 * @param CoreQueryBuilder $qb
103
	 *
104
	 * @return Member
105
	 * @throws MemberNotFoundException
106
	 */
107 View Code Duplication
	public function getItemFromRequest(CoreQueryBuilder $qb): Member {
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...
108
		/** @var Member $member */
109
		try {
110
			$member = $qb->asItem(
111
				Member::class,
112
				[
113
					'local' => $this->configService->getLocalInstance()
114
				]
115
			);
116
		} catch (RowNotFoundException $e) {
117
			throw new MemberNotFoundException();
118
		}
119
120
		return $member;
121
	}
122
123
	/**
124
	 * @param CoreQueryBuilder $qb
125
	 *
126
	 * @return Member[]
127
	 */
128
	public function getItemsFromRequest(CoreQueryBuilder $qb): array {
129
		/** @var Member[] $result */
130
		return $qb->asItems(
131
			Member::class,
132
			[
133
				'local' => $this->configService->getLocalInstance()
134
			]
135
		);
136
	}
137
138
}
139