Completed
Push — master ( 75f541...50b854 )
by Marcos
02:58
created

VaultMapper   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 82.5%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 79
ccs 33
cts 40
cp 0.825
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A find() 0 5 1
A findByGuid() 0 5 1
A findVaultsFromUser() 0 6 1
A create() 0 9 1
A setLastAccess() 0 7 1
A updateVault() 0 3 1
A updateSharingKeys() 0 8 1
1
<?php
2
/**
3
 * Nextcloud - passman
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Sander Brand <[email protected]>
9
 * @copyright Sander Brand 2016
10
 */
11
namespace OCA\Passman\Db;
12
13
use OCA\Passman\Utility\Utils;
14
use OCP\IDBConnection;
15
use OCP\AppFramework\Db\Mapper;
16
17
class VaultMapper extends Mapper {
18
	private $utils;
19
	public function __construct(IDBConnection $db, Utils $utils) {
20
		parent::__construct($db, 'passman_vaults');
21
		$this->utils = $utils;
22
	}
23
24
25
	/**
26
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
27
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
28
	 * @return Vault
29
	 */
30
	public function find($vault_id, $user_id) {
31
		$sql = 'SELECT * FROM `*PREFIX*passman_vaults` ' .
32
			'WHERE `id`= ? and `user_id` = ?';
33
		return $this->findEntities($sql, [$vault_id, $user_id]);
34
	}
35
	/**
36
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
37
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
38
	 * @return Vault
39
	 */
40 1
	public function findByGuid($vault_guid, $user_id) {
41
		$sql = 'SELECT * FROM `*PREFIX*passman_vaults` ' .
42 1
			'WHERE `guid`= ? and `user_id` = ?';
43 1
		return $this->findEntity($sql, [$vault_guid, $user_id]);
44
	}
45
46
47
	/**
48
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
49
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
50
	 * @return Vault[]
51
	 */
52 1
	public function findVaultsFromUser($userId){
53
		$sql = 'SELECT * FROM `*PREFIX*passman_vaults` ' .
54 1
			'WHERE `user_id` = ? ';
55 1
		$params = [$userId];
56 1
		return $this->findEntities($sql, $params);
57
	}
58
59
	/**
60
	 * Creates a vault
61
	 * @param $vault_name
62
	 * @param $userId
63
	 * @return Vault
64
	 */
65 1
	public function create($vault_name, $userId){
66 1
		$vault = new Vault();
67 1
		$vault->setName($vault_name);
68 1
		$vault->setUserId($userId);
69 1
		$vault->setGuid($this->utils->GUID());
70 1
		$vault->setCreated($this->utils->getTime());
71 1
		$vault->setLastAccess(0);
72 1
		return parent::insert($vault);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (insert() instead of create()). Are you sure this is correct? If so, you might want to change this to $this->insert().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
73
	}
74
75 1
	public function setLastAccess($vault_id, $user_id){
76 1
		$vault = new Vault();
77 1
		$vault->setId($vault_id);
78 1
		$vault->setUserId($user_id);
79 1
		$vault->setLastAccess(Utils::getTime());
80 1
		$this->update($vault);
81 1
	}
82
83 1
	public function updateVault(Vault $vault){
84 1
		$this->update($vault);
85 1
	}
86
87 1
	public function updateSharingKeys($vault_id, $privateKey, $publicKey){
88 1
		$vault = new Vault();
89 1
		$vault->setId($vault_id);
90 1
		$vault->setPrivateSharingKey($privateKey);
91 1
		$vault->setPublicSharingKey($publicKey);
92 1
		$vault->setSharingKeysGenerated($this->utils->getTime());
93 1
		$this->update($vault);
94
	}
95
}