Passed
Push — master ( 9a05fd...38edc6 )
by Morris
17:32 queued 10s
created

PublicKeyCredentialMapper::deleteByUid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright Copyright (c) 2020, Roeland Jago Douma <[email protected]>
7
 *
8
 * @author Christoph Wurst <[email protected]>
9
 * @author Roeland Jago Douma <[email protected]>
10
 *
11
 * @license GNU AGPL version 3 or any later version
12
 *
13
 * This program is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU Affero General Public License as
15
 * published by the Free Software Foundation, either version 3 of the
16
 * License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
 * GNU Affero General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Affero General Public License
24
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25
 *
26
 */
27
namespace OC\Authentication\WebAuthn\Db;
28
29
use OCP\AppFramework\Db\DoesNotExistException;
30
use OCP\AppFramework\Db\QBMapper;
31
use OCP\IDBConnection;
32
33
/**
34
 * @template-extends QBMapper<PublicKeyCredentialEntity>
35
 */
36
class PublicKeyCredentialMapper extends QBMapper {
37
	public function __construct(IDBConnection $db) {
38
		parent::__construct($db, 'webauthn', PublicKeyCredentialEntity::class);
39
	}
40
41
	public function findOneByCredentialId(string $publicKeyCredentialId): PublicKeyCredentialEntity {
42
		$qb = $this->db->getQueryBuilder();
43
44
		$qb->select('*')
45
			->from($this->getTableName())
46
			->where(
47
				$qb->expr()->eq('public_key_credential_id', $qb->createNamedParameter(base64_encode($publicKeyCredentialId)))
48
			);
49
50
		return $this->findEntity($qb);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->findEntity($qb) returns the type OCP\AppFramework\Db\Entity which includes types incompatible with the type-hinted return OC\Authentication\WebAut...blicKeyCredentialEntity.
Loading history...
51
	}
52
53
	/**
54
	 * @return PublicKeyCredentialEntity[]
55
	 */
56
	public function findAllForUid(string $uid): array {
57
		$qb = $this->db->getQueryBuilder();
58
59
		$qb->select('*')
60
			->from($this->getTableName())
61
			->where(
62
				$qb->expr()->eq('uid', $qb->createNamedParameter($uid))
63
			);
64
65
		return $this->findEntities($qb);
66
	}
67
68
	/**
69
	 * @param string $uid
70
	 * @param int $id
71
	 *
72
	 * @return PublicKeyCredentialEntity
73
	 * @throws DoesNotExistException
74
	 */
75
	public function findById(string $uid, int $id): PublicKeyCredentialEntity {
76
		$qb = $this->db->getQueryBuilder();
77
78
		$qb->select('*')
79
			->from($this->getTableName())
80
			->where($qb->expr()->andX(
81
				$qb->expr()->eq('id', $qb->createNamedParameter($id)),
82
				$qb->expr()->eq('uid', $qb->createNamedParameter($uid))
83
			));
84
85
		return $this->findEntity($qb);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->findEntity($qb) returns the type OCP\AppFramework\Db\Entity which includes types incompatible with the type-hinted return OC\Authentication\WebAut...blicKeyCredentialEntity.
Loading history...
86
	}
87
88
	/**
89
	 * @throws \OCP\DB\Exception
90
	 */
91
	public function deleteByUid(string $uid) {
92
		$qb = $this->db->getQueryBuilder();
93
94
		$qb->delete($this->getTableName())
95
			->where(
96
				$qb->expr()->eq('uid', $qb->createNamedParameter($uid))
97
			);
98
		$qb->executeStatement();
99
	}
100
}
101