|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Christoph Wurst <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @license GNU AGPL version 3 or any later version |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
9
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
10
|
|
|
* License, or (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace OCA\TwoFactorBackupCodes\Db; |
|
23
|
|
|
|
|
24
|
|
|
use OCP\AppFramework\Db\Mapper; |
|
25
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder; |
|
26
|
|
|
use OCP\IDb; |
|
27
|
|
|
use OCP\IUser; |
|
28
|
|
|
|
|
29
|
|
|
class BackupCodeMapper extends Mapper { |
|
30
|
|
|
|
|
31
|
|
|
public function __construct(IDb $db) { |
|
32
|
|
|
parent::__construct($db, 'twofactor_backup_codes'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param IUser $user |
|
37
|
|
|
* @return BackupCode[] |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getBackupCodes(IUser $user) { |
|
40
|
|
|
/* @var IQueryBuilder $qb */ |
|
41
|
|
|
$qb = $this->db->getQueryBuilder(); |
|
42
|
|
|
|
|
43
|
|
|
$qb->select('id', 'user_id', 'code', 'used') |
|
|
|
|
|
|
44
|
|
|
->from('twofactor_backup_codes') |
|
45
|
|
|
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID()))); |
|
46
|
|
|
$result = $qb->execute(); |
|
47
|
|
|
|
|
48
|
|
|
$rows = $result->fetchAll(); |
|
49
|
|
|
$result->closeCursor(); |
|
50
|
|
|
|
|
51
|
|
|
return array_map(function ($row) { |
|
52
|
|
|
return BackupCode::fromRow($row); |
|
53
|
|
|
}, $rows); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
View Code Duplication |
public function deleteCodes(IUser $user) { |
|
|
|
|
|
|
57
|
|
|
/* @var IQueryBuilder $qb */ |
|
58
|
|
|
$qb = $this->db->getQueryBuilder(); |
|
59
|
|
|
|
|
60
|
|
|
$qb->delete('twofactor_backup_codes') |
|
61
|
|
|
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID()))); |
|
62
|
|
|
$qb->execute(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.