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

CircleRequestBuilder::getCircleInsertSql()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 10
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\CircleNotFoundException;
37
use OCA\Circles\Model\AppService;
38
use OCA\Circles\Model\Circle;
39
40
41
/**
42
 * Class CircleRequestBuilder
43
 *
44
 * @package OCA\Circles\Db
45
 */
46
class CircleRequestBuilder extends CoreRequestBuilder {
47
48
49
	/**
50
	 * @return CoreQueryBuilder
51
	 */
52 View Code Duplication
	protected function getCircleInsertSql(): 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...
53
		$qb = $this->getQueryBuilder();
54
		$qb->insert(self::TABLE_CIRCLE)
55
		   ->setValue('creation', $qb->createNamedParameter($this->timezoneService->getUTCDate()));
56
57
		return $qb;
58
	}
59
60
61
	/**
62
	 * @param string $id
0 ignored issues
show
Bug introduced by
There is no parameter named $id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
63
	 *
64
	 * @return CoreQueryBuilder
65
	 */
66
	protected function getCircleUpdateSql(): CoreQueryBuilder {
67
		$qb = $this->getQueryBuilder();
68
		$qb->update(self::TABLE_CIRCLE);
69
70
		return $qb;
71
	}
72
73
74
	/**
75
	 * @return CoreQueryBuilder
76
	 */
77
	protected function getCircleSelectSql(): CoreQueryBuilder {
78
		$qb = $this->getQueryBuilder();
79
		$qb->selectDistinct('c.unique_id')
80
		   ->addSelect(
81
			   'c.name', 'c.alt_name', 'c.description', 'c.settings', 'c.config', 'contact_addressbook',
82
			   'contact_groupname', 'c.creation'
83
		   )
84
		   ->from(self::TABLE_CIRCLE, 'c')
85
		   ->setDefaultSelectAlias('c');
86
87
		return $qb;
88
	}
89
90
91
	/**
92
	 * Base of the Sql Delete request
93
	 *
94
	 * @return CoreQueryBuilder
95
	 */
96
	protected function getCircleDeleteSql(): CoreQueryBuilder {
97
		$qb = $this->getQueryBuilder();
98
		$qb->delete(self::TABLE_CIRCLE);
99
100
		return $qb;
101
	}
102
103
104
	/**
105
	 * @param CoreQueryBuilder $qb
106
	 *
107
	 * @return Circle
108
	 * @throws CircleNotFoundException
109
	 */
110
	public function getItemFromRequest(CoreQueryBuilder $qb): Circle {
111
		/** @var Circle $circle */
112
		try {
113
			$circle = $qb->asItem(Circle::class);
114
		} catch (RowNotFoundException $e) {
115
			throw new CircleNotFoundException();
116
		}
117
118
		return $circle;
119
	}
120
121
	/**
122
	 * @param CoreQueryBuilder $qb
123
	 *
124
	 * @return Circle[]
125
	 */
126
	public function getItemsFromRequest(CoreQueryBuilder $qb): array {
127
		/** @var AppService[] $result */
128
		return $qb->asItems(Circle::class);
129
	}
130
131
}
132