Passed
Push — master ( b39fb5...590849 )
by Roeland
11:59 queued 10s
created

PublicKeyCredentialMapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 51
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A findOneByCredentialId() 0 10 1
A __construct() 0 2 1
A findById() 0 11 1
A findAllForUid() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright Copyright (c) 2020, Roeland Jago Douma <[email protected]>
7
 *
8
 * @author Roeland Jago Douma <[email protected]>
9
 *
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
namespace OC\Authentication\WebAuthn\Db;
28
29
use OCP\AppFramework\Db\DoesNotExistException;
30
use OCP\AppFramework\Db\QBMapper;
31
use OCP\IDBConnection;
32
33
class PublicKeyCredentialMapper extends QBMapper {
34
35
	public function __construct(IDBConnection $db) {
36
		parent::__construct($db, 'webauthn', PublicKeyCredentialEntity::class);
37
	}
38
39
	public function findOneByCredentialId(string $publicKeyCredentialId): PublicKeyCredentialEntity {
40
		$qb = $this->db->getQueryBuilder();
41
42
		$qb->select('*')
43
			->from($this->getTableName())
44
			->where(
45
				$qb->expr()->eq('public_key_credential_id', $qb->createNamedParameter(base64_encode($publicKeyCredentialId)))
46
			);
47
48
		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...
49
	}
50
51
	/**
52
	 * @return PublicKeyCredentialEntity[]
53
	 */
54
	public function findAllForUid(string $uid): array {
55
		$qb = $this->db->getQueryBuilder();
56
57
		$qb->select('*')
58
			->from($this->getTableName())
59
			->where(
60
				$qb->expr()->eq('uid', $qb->createNamedParameter($uid))
61
			);
62
63
		return $this->findEntities($qb);
64
	}
65
66
	/**
67
	 * @param string $uid
68
	 * @param int $id
69
	 *
70
	 * @return PublicKeyCredentialEntity
71
	 * @throws DoesNotExistException
72
	 */
73
	public function findById(string $uid, int $id): PublicKeyCredentialEntity {
74
		$qb = $this->db->getQueryBuilder();
75
76
		$qb->select('*')
77
			->from($this->getTableName())
78
			->where($qb->expr()->andX(
79
				$qb->expr()->eq('id', $qb->createNamedParameter($id)),
80
				$qb->expr()->eq('uid', $qb->createNamedParameter($uid))
81
			));
82
83
		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...
84
	}
85
86
}
87