Code Duplication    Length = 9-11 lines in 6 locations

lib/Db/CredentialRevisionMapper.php 2 locations

@@ 30-39 (lines=10) @@
27
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
28
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
29
	 */
30
	public function getRevisions($credential_id, $user_id = null) {
31
		$sql = 'SELECT * FROM `*PREFIX*passman_revisions` ' .
32
			'WHERE `credential_id` = ?';
33
        $params = [$credential_id];
34
        if ($user_id !== null) {
35
            $sql.= ' and `user_id` = ? ';
36
            $params[] = $user_id;
37
        }
38
		return $this->findEntities($sql, $params);
39
	}
40
41
	/**
42
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
@@ 46-55 (lines=10) @@
43
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
44
	 * @return CredentialRevision
45
	 */
46
	public function getRevision($revision_id, $user_id = null) {
47
		$sql = 'SELECT * FROM `*PREFIX*passman_revisions` ' .
48
			'WHERE `id` = ?';
49
        $params = [$revision_id];
50
        if ($user_id !== null) {
51
            $sql.= ' and `user_id` = ? ';
52
            $params[] = $user_id;
53
        }
54
		return $this->findEntity($sql, $params);
55
	}
56
57
	/**
58
	 * @param $credential

lib/Db/FileMapper.php 2 locations

@@ 33-42 (lines=10) @@
30
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
31
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
32
	 */
33
	public function getFile($file_id, $user_id = null) {
34
		$sql = 'SELECT * FROM `*PREFIX*passman_files` ' .
35
			'WHERE `id` = ?';
36
		$params = [$file_id];
37
		if ($user_id !== null) {
38
			$sql .= ' and `user_id` = ? ';
39
			array_push($params, $user_id);
40
		}
41
		return $this->findEntity($sql, $params);
42
	}
43
	/**
44
	 * @param $file_id
45
	 * @param null $user_id
@@ 50-59 (lines=10) @@
47
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
48
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
49
	 */
50
	public function getFileByGuid($file_guid, $user_id = null) {
51
		$sql = 'SELECT * FROM `*PREFIX*passman_files` ' .
52
			'WHERE `guid` = ?';
53
		$params = [$file_guid];
54
		if ($user_id !== null) {
55
			$sql .= ' and `user_id` = ? ';
56
			array_push($params, $user_id);
57
		}
58
		return $this->findEntity($sql, $params);
59
	}
60
61
	/**
62
	 * @param $file_raw

lib/Db/CredentialMapper.php 2 locations

@@ 64-74 (lines=11) @@
61
     * @param null $user_id
62
     * @return Credential
63
     */
64
	public function getCredentialById($credential_id, $user_id = null){
65
		$sql = 'SELECT * FROM `*PREFIX*passman_credentials` ' .
66
			'WHERE `id` = ?';
67
        // If we want to check the owner, add it to the query
68
		$params = [$credential_id];
69
        if ($user_id !== null){
70
        	$sql .= ' and `user_id` = ? ';
71
			array_push($params, $user_id);
72
		}
73
		return $this->findEntity($sql,$params);
74
	}
75
76
	/**
77
	 * @param $credential_id
@@ 162-170 (lines=9) @@
159
     * @param $credential_guid
160
     * @return Credential
161
     */
162
	public function getCredentialByGUID($credential_guid, $user_id = null){
163
	    $q = 'SELECT * FROM `*PREFIX*passman_credentials` WHERE guid = ? ';
164
		$params = [$credential_guid];
165
		if ($user_id !== null){
166
			$q .= ' and `user_id` = ? ';
167
			array_push($params, $user_id);
168
		}
169
        return $this->findEntity($q, $params);
170
    }
171
}