Completed
Pull Request — master (#479)
by Maxence
02:08
created

SharingFrameRequest::updatePasswordOnShares()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
/**
3
 * Circles - Bring cloud-users closer together.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
28
namespace OCA\Circles\Db;
29
30
31
use OCA\Circles\Exceptions\SharingFrameDoesNotExistException;
32
use OCA\Circles\Model\SharingFrame;
33
34
class SharingFrameRequest extends SharingFrameRequestBuilder {
35
36
37
	/**
38
	 * @param string $circleUniqueId
39
	 * @param string $frameUniqueId
40
	 *
41
	 * @return SharingFrame
42
	 * @throws SharingFrameDoesNotExistException
43
	 */
44 View Code Duplication
	public function getSharingFrame($circleUniqueId, $frameUniqueId) {
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...
45
		$qb = $this->getSharesSelectSql();
46
		$this->limitToUniqueId($qb, $frameUniqueId);
47
		$this->limitToCircleId($qb, $circleUniqueId);
48
		$this->leftJoinCircle($qb);
49
50
		$cursor = $qb->execute();
51
		$data = $cursor->fetch();
52
		$cursor->closeCursor();
53
54
		if ($data === false) {
55
			throw new SharingFrameDoesNotExistException($this->l10n->t('Sharing Frame does not exist'));
56
		}
57
58
		return $this->parseSharesSelectSql($data);
59
	}
60
61
62
	/**
63
	 * @param string $circleUniqueId
64
	 *
65
	 * @return SharingFrame[]
66
	 */
67
	public function getSharingFramesFromCircle($circleUniqueId) {
68
		$qb = $this->getSharesSelectSql();
69
		$this->limitToCircleId($qb, $circleUniqueId);
70
71
		$frames = [];
72
		$cursor = $qb->execute();
73
		while ($data = $cursor->fetch()) {
74
			$frames[] = $this->parseSharesSelectSql($data);
75
		}
76
		$cursor->closeCursor();
77
78
		return $frames;
79
	}
80
81
82
	/**
83
	 * saveFrame()
84
	 *
85
	 * Insert a new entry in the database to save the SharingFrame.
86
	 *
87
	 * @param SharingFrame $frame
88
	 */
89 View Code Duplication
	public function saveSharingFrame(SharingFrame $frame) {
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
		$qb = $this->getSharesInsertSql();
91
		$circle = $frame->getCircle();
92
		$qb->setValue('circle_id', $qb->createNamedParameter($circle->getUniqueId()))
93
		   ->setValue('source', $qb->createNamedParameter($frame->getSource()))
94
		   ->setValue('type', $qb->createNamedParameter($frame->getType()))
95
		   ->setValue('headers', $qb->createNamedParameter($frame->getHeaders(true)))
96
		   ->setValue('author', $qb->createNamedParameter($frame->getAuthor()))
97
		   ->setValue('cloud_id', $qb->createNamedParameter($frame->getCloudId()))
98
		   ->setValue('unique_id', $qb->createNamedParameter($frame->getUniqueId()))
99
		   ->setValue('payload', $qb->createNamedParameter($frame->getPayload(true)));
100
101
		$qb->execute();
102
	}
103
104
105 View Code Duplication
	public function updateSharingFrame(SharingFrame $frame) {
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...
106
		$qb = $this->getSharesUpdateSql($frame->getUniqueId());
107
		$circle = $frame->getCircle();
108
		$qb->set('circle_id', $qb->createNamedParameter($circle->getUniqueId()))
109
		   ->set('source', $qb->createNamedParameter($frame->getSource()))
110
		   ->set('type', $qb->createNamedParameter($frame->getType()))
111
		   ->set('headers', $qb->createNamedParameter($frame->getHeaders(true)))
112
		   ->set('author', $qb->createNamedParameter($frame->getAuthor()))
113
		   ->set('cloud_id', $qb->createNamedParameter($frame->getCloudId()))
114
		   ->set('unique_id', $qb->createNamedParameter($frame->getUniqueId()))
115
		   ->set('payload', $qb->createNamedParameter($frame->getPayload(true)));
116
117
		$qb->execute();
118
	}
119
120
121
122
123
	public function updatePasswordOnShares(string $circleId, string $password) {
0 ignored issues
show
Unused Code introduced by
The parameter $password 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...
124
		$qb = $this->getSharesUpdateSql($frame->getUniqueId());
0 ignored issues
show
Bug introduced by
The variable $frame does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
125
126
		$this->limitToShareWith($qb, $circleId);
127
		$this->limitToShareType($qb, self::SHARE_TYPE);
128
	}
129
130
131
}
132