Completed
Pull Request — master (#551)
by Maxence
02:16
created

RemoteWrapperRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 11 1
A update() 0 10 1
A getByToken() 0 6 1
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 2017
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 OCA\Circles\Model\GlobalScale\GSWrapper;
36
use OCA\Circles\Model\Remote\RemoteWrapper;
37
38
39
/**
40
 * Class RemoteWrapperRequest
41
 *
42
 * @package OCA\Circles\Db
43
 */
44
class RemoteWrapperRequest extends RemoteWrapperRequestBuilder {
45
46
47
	/**
48
	 * @param RemoteWrapper $wrapper
49
	 */
50
	public function create(RemoteWrapper $wrapper): void {
51
		$qb = $this->getRemoteWrapperInsertSql();
52
		$qb->setValue('token', $qb->createNamedParameter($wrapper->getToken()))
53
		   ->setValue('event', $qb->createNamedParameter(json_encode($wrapper->getEvent())))
54
		   ->setValue('instance', $qb->createNamedParameter($wrapper->getInstance()))
55
		   ->setValue('severity', $qb->createNamedParameter($wrapper->getSeverity()))
56
		   ->setValue('status', $qb->createNamedParameter($wrapper->getStatus()))
57
		   ->setValue('creation', $qb->createNamedParameter($wrapper->getCreation()));
58
59
		$qb->execute();
60
	}
61
62
	/**
63
	 * @param RemoteWrapper $wrapper
64
	 */
65
	public function update(RemoteWrapper $wrapper): void {
66
		$qb = $this->getRemoteWrapperUpdateSql();
67
		$qb->set('event', $qb->createNamedParameter(json_encode($wrapper->getEvent())))
68
		   ->set('status', $qb->createNamedParameter($wrapper->getStatus()));
69
70
		$qb->limitToInstance($wrapper->getInstance());
71
		$qb->limitToToken($wrapper->getToken());
72
73
		$qb->execute();
74
	}
75
76
77
	/**
78
	 * @param string $token
79
	 *
80
	 * @return RemoteWrapper[]
81
	 */
82
	public function getByToken(string $token): array {
83
		$qb = $this->getRemoteWrapperSelectSql();
84
		$qb->limitToToken($token);
85
86
		return $this->getItemsFromRequest($qb);
87
	}
88
89
}
90
91