Passed
Pull Request — master (#875)
by Pauli
04:42 queued 02:14
created

BookmarkMapper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A findUniqueEntity() 0 3 1
A findByEntry() 0 3 1
1
<?php declare(strict_types=1);
2
3
/**
4
 * ownCloud - Music app
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Gavin E <[email protected]>
10
 * @author Pauli Järvinen <[email protected]>
11
 * @copyright Gavin E 2020
12
 * @copyright Pauli Järvinen 2020, 2021
13
 */
14
15
namespace OCA\Music\Db;
16
17
use \OCP\AppFramework\Db\Entity;
18
use \OCP\IDBConnection;
19
20
/**
21
 * Type hint a base class methdo to help Scrutinizer
22
 * @method Bookmark findEntity(string $sql, array $params=[], ?int $limit=null, ?int $offset=null)
23
 */
24
class BookmarkMapper extends BaseMapper {
25
	public function __construct(IDBConnection $db) {
26
		parent::__construct($db, 'music_bookmarks', '\OCA\Music\Db\Bookmark', 'comment');
27
	}
28
29
	public function findByEntry(int $type, int $entryId, string $userId) : Bookmark {
30
		$sql = $this->selectUserEntities("`type` = ? AND `entry_id` = ?");
31
		return $this->findEntity($sql, [$userId, $type, $entryId]);
32
	}
33
34
	/**
35
	 * @see \OCA\Music\Db\BaseMapper::findUniqueEntity()
36
	 * @param Bookmark $bookmark
37
	 * @return Bookmark
38
	 */
39
	protected function findUniqueEntity(Entity $bookmark) : Entity {
40
		assert($bookmark instanceof Bookmark);
41
		return $this->findByEntry($bookmark->getType(), $bookmark->getEntryId(), $bookmark->getUserId());
42
	}
43
}
44