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

PodcastChannelMapper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 23
rs 10
c 2
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A findUniqueEntity() 0 3 1
A findAllIdsWithNoUpdateSince() 0 5 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 Pauli Järvinen <[email protected]>
10
 * @copyright Pauli Järvinen 2021
11
 */
12
13
namespace OCA\Music\Db;
14
15
use \OCP\AppFramework\Db\Entity;
16
use \OCP\IDBConnection;
17
18
/**
19
 * Type hint a base class methdo to help Scrutinizer
20
 * @method PodcastChannel insert(PodcastChannel $channel)
21
 */
22
class PodcastChannelMapper extends BaseMapper {
23
	public function __construct(IDBConnection $db) {
24
		parent::__construct($db, 'music_podcast_channels', '\OCA\Music\Db\PodcastChannel', 'title');
25
	}
26
27
	/**
28
	 * @return int[]
29
	 */
30
	public function findAllIdsWithNoUpdateSince(string $userId, \DateTime $timeLimit) : array {
31
		$sql = "SELECT `id` FROM `{$this->getTableName()}` WHERE `user_id` = ? AND `update_checked` < ?";
32
		$result = $this->execute($sql, [$userId, $timeLimit->format(BaseMapper::SQL_DATE_FORMAT)]);
33
34
		return \array_map('intval', $result->fetchAll(\PDO::FETCH_COLUMN));
35
	}
36
37
	/**
38
	 * @see \OCA\Music\Db\BaseMapper::findUniqueEntity()
39
	 * @param PodcastChannel $channel
40
	 * @return PodcastChannel
41
	 */
42
	protected function findUniqueEntity(Entity $channel) : Entity {
43
		$sql = $this->selectUserEntities("`rss_hash` = ?");
44
		return $this->findEntity($sql, [$channel->getUserId(), $channel->getRssHash()]);
45
	}
46
}
47