Code Duplication    Length = 9-11 lines in 6 locations

lib/Db/FileMapper.php 2 locations

@@ 47-56 (lines=10) @@
44
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
45
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
46
	 */
47
	public function getFile($file_id, $user_id = null) {
48
		$sql = 'SELECT * FROM `*PREFIX*passman_files` ' .
49
			'WHERE `id` = ?';
50
		$params = [$file_id];
51
		if ($user_id !== null) {
52
			$sql .= ' and `user_id` = ? ';
53
			array_push($params, $user_id);
54
		}
55
		return $this->findEntity($sql, $params);
56
	}
57
	/**
58
	 * @param $file_id
59
	 * @param null $user_id
@@ 64-73 (lines=10) @@
61
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
62
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
63
	 */
64
	public function getFileByGuid($file_guid, $user_id = null) {
65
		$sql = 'SELECT * FROM `*PREFIX*passman_files` ' .
66
			'WHERE `guid` = ?';
67
		$params = [$file_guid];
68
		if ($user_id !== null) {
69
			$sql .= ' and `user_id` = ? ';
70
			array_push($params, $user_id);
71
		}
72
		return $this->findEntity($sql, $params);
73
	}
74
75
	/**
76
	 * @param $file_raw

lib/Db/CredentialMapper.php 2 locations

@@ 83-93 (lines=11) @@
80
     * @param null $user_id
81
     * @return Credential
82
     */
83
	public function getCredentialById($credential_id, $user_id = null){
84
		$sql = 'SELECT * FROM `*PREFIX*passman_credentials` ' .
85
			'WHERE `id` = ?';
86
        // If we want to check the owner, add it to the query
87
		$params = [$credential_id];
88
        if ($user_id !== null){
89
        	$sql .= ' and `user_id` = ? ';
90
			array_push($params, $user_id);
91
		}
92
		return $this->findEntity($sql,$params);
93
	}
94
95
	/**
96
	 * Get credential label by id
@@ 186-194 (lines=9) @@
183
     * @param $credential_guid
184
     * @return Credential
185
     */
186
	public function getCredentialByGUID($credential_guid, $user_id = null){
187
	    $q = 'SELECT * FROM `*PREFIX*passman_credentials` WHERE guid = ? ';
188
		$params = [$credential_guid];
189
		if ($user_id !== null){
190
			$q .= ' and `user_id` = ? ';
191
			array_push($params, $user_id);
192
		}
193
        return $this->findEntity($q, $params);
194
    }
195
}

lib/Db/CredentialRevisionMapper.php 2 locations

@@ 45-54 (lines=10) @@
42
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
43
	 * @return CredentialRevision[]
44
	 */
45
	public function getRevisions($credential_id, $user_id = null) {
46
		$sql = 'SELECT * FROM `*PREFIX*passman_revisions` ' .
47
			'WHERE `credential_id` = ?';
48
        $params = [$credential_id];
49
        if ($user_id !== null) {
50
            $sql.= ' and `user_id` = ? ';
51
            $params[] = $user_id;
52
        }
53
		return $this->findEntities($sql, $params);
54
	}
55
56
	/**
57
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
@@ 61-70 (lines=10) @@
58
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
59
	 * @return CredentialRevision
60
	 */
61
	public function getRevision($revision_id, $user_id = null) {
62
		$sql = 'SELECT * FROM `*PREFIX*passman_revisions` ' .
63
			'WHERE `id` = ?';
64
        $params = [$revision_id];
65
        if ($user_id !== null) {
66
            $sql.= ' and `user_id` = ? ';
67
            $params[] = $user_id;
68
        }
69
		return $this->findEntity($sql, $params);
70
	}
71
72
	/**
73
	 * Create a revision