Passed
Push — feature/786_podcasts ( da2795...426725 )
by Pauli
02:03
created

BookmarkMapper::findByEntry()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
class BookmarkMapper extends BaseMapper {
21
	public function __construct(IDBConnection $db) {
22
		parent::__construct($db, 'music_bookmarks', '\OCA\Music\Db\Bookmark', 'comment');
23
	}
24
25
	public function findByEntry(int $type, int $entryId, string $userId) : Bookmark {
26
		$sql = $this->selectUserEntities("`type` = ? AND `entry_id` = ?");
27
		return $this->findEntity($sql, [$userId, $type, $entryId]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->findEntity...erId, $type, $entryId)) returns the type OCP\AppFramework\Db\Entity which includes types incompatible with the type-hinted return OCA\Music\Db\Bookmark.
Loading history...
28
	}
29
30
	/**
31
	 * @see \OCA\Music\Db\BaseMapper::findUniqueEntity()
32
	 * @param Bookmark $bookmark
33
	 * @return Bookmark
34
	 */
35
	protected function findUniqueEntity(Entity $bookmark) : Entity {
36
		return $this->findByEntry($bookmark->getType(), $bookmark->getEntryId(), $bookmark->getUserId());
0 ignored issues
show
Bug introduced by
It seems like $bookmark->getType() can also be of type null; however, parameter $type of OCA\Music\Db\BookmarkMapper::findByEntry() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
		return $this->findByEntry(/** @scrutinizer ignore-type */ $bookmark->getType(), $bookmark->getEntryId(), $bookmark->getUserId());
Loading history...
Bug introduced by
It seems like $bookmark->getUserId() can also be of type null; however, parameter $userId of OCA\Music\Db\BookmarkMapper::findByEntry() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
		return $this->findByEntry($bookmark->getType(), $bookmark->getEntryId(), /** @scrutinizer ignore-type */ $bookmark->getUserId());
Loading history...
Bug introduced by
It seems like $bookmark->getEntryId() can also be of type null; however, parameter $entryId of OCA\Music\Db\BookmarkMapper::findByEntry() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
		return $this->findByEntry($bookmark->getType(), /** @scrutinizer ignore-type */ $bookmark->getEntryId(), $bookmark->getUserId());
Loading history...
37
	}
38
}
39