Completed
Pull Request — master (#362)
by Maxence
02:45
created

GSEventsRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 54
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 15 1
A getByToken() 0 13 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 daita\MySmallPhpTools\Traits\TStringTools;
32
use Exception;
33
use OCA\Circles\Exceptions\JsonException;
34
use OCA\Circles\Exceptions\ModelException;
35
use OCA\Circles\Exceptions\TokenDoesNotExistException;
36
use OCA\Circles\Model\GlobalScale\GSEvent;
37
use OCA\Circles\Model\GlobalScale\GSWrapper;
38
use OCA\Circles\Model\Member;
39
use OCA\Circles\Model\SharesToken;
40
41
42
/**
43
 * Class TokensRequest
44
 *
45
 * @package OCA\Circles\Db
46
 */
47
class GSEventsRequest extends GSEventsRequestBuilder {
48
49
50
	use TStringTools;
51
52
53
	/**
54
	 * @param GSEvent $event
55
	 * @param array $instances
0 ignored issues
show
Bug introduced by
There is no parameter named $instances. 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...
56
	 *
57
	 * @return GSWrapper
58
	 */
59
	public function create(GSevent $event): GSWrapper {
60
		$wrapper = new GSWrapper();
61
		$wrapper->setToken($this->uuid());
62
		$wrapper->setEvent($event);
63
		$wrapper->setCreation(time());
64
65
		$qb = $this->getGSEventsInsertSql();
66
		$qb->setValue('token', $qb->createNamedParameter($wrapper->getToken()))
67
		   ->setValue('event', $qb->createNamedParameter(json_encode($wrapper->getEvent())))
68
		   ->setValue('creation', $qb->createNamedParameter($wrapper->getCreation()));
69
70
		$qb->execute();
71
72
		return $wrapper;
73
	}
74
75
76
77
	/**
78
	 * @param string $token
79
	 *
80
	 * @return GSWrapper
81
	 * @throws TokenDoesNotExistException
82
	 * @throws JsonException
83
	 * @throws ModelException
84
	 */
85
	public function getByToken(string $token): GSWrapper {
86
		$qb = $this->getGSEventsSelectSql();
87
		$this->limitToToken($qb, $token);
88
89
		$cursor = $qb->execute();
90
		$data = $cursor->fetch();
91
		$cursor->closeCursor();
92
		if ($data === false) {
93
			throw new TokenDoesNotExistException('Unknown share token');
94
		}
95
96
		return $this->parseGSEventsSelectSql($data);
97
	}
98
99
100
}
101
102