Passed
Push — feature/909_Ampache_API_improv... ( cb99df...a84036 )
by Pauli
02:41
created

PodcastChannelMapper::advFormatSqlCondition()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 4
nop 2
dl 0
loc 6
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 Pauli Järvinen <[email protected]>
10
 * @copyright Pauli Järvinen 2021 - 2023
11
 */
12
13
namespace OCA\Music\Db;
14
15
use OCP\IDBConnection;
16
17
/**
18
 * Type hint a base class methdo to help Scrutinizer
19
 * @method PodcastChannel insert(PodcastChannel $channel)
20
 * @phpstan-extends BaseMapper<PodcastChannel>
21
 */
22
class PodcastChannelMapper extends BaseMapper {
23
	public function __construct(IDBConnection $db) {
24
		parent::__construct($db, 'music_podcast_channels', PodcastChannel::class, '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` < ?";
0 ignored issues
show
Deprecated Code introduced by
The function OCA\Music\AppFramework\D...dMapper::getTableName() has been deprecated: 14.0.0 Move over to QBMapper ( Ignorable by Annotation )

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

31
		$sql = "SELECT `id` FROM `{/** @scrutinizer ignore-deprecated */ $this->getTableName()}` WHERE `user_id` = ? AND `update_checked` < ?";

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
32
		$result = $this->execute($sql, [$userId, $timeLimit->format(BaseMapper::SQL_DATE_FORMAT)]);
0 ignored issues
show
Deprecated Code introduced by
The function OCA\Music\AppFramework\D...tcloudMapper::execute() has been deprecated: 14.0.0 Move over to QBMapper ( Ignorable by Annotation )

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

32
		$result = /** @scrutinizer ignore-deprecated */ $this->execute($sql, [$userId, $timeLimit->format(BaseMapper::SQL_DATE_FORMAT)]);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
33
34
		return \array_map('intval', $result->fetchAll(\PDO::FETCH_COLUMN));
35
	}
36
37
	/**
38
	 * Overridden from the base implementation to provide support for table-specific rules
39
	 *
40
	 * {@inheritdoc}
41
	 * @see BaseMapper::advFormatSqlCondition()
42
	 */
43
	protected function advFormatSqlCondition(string $rule, string $sqlOp) : string {
44
		switch ($rule) {
45
			case 'podcast_episode':	return "`*PREFIX*music_podcast_channels`.`id` IN (SELECT `channel_id` FROM `*PREFIX*music_podcast_episodes` `e` WHERE LOWER(`e`.`title`) $sqlOp LOWER(?))";
46
			case 'time':			return "`*PREFIX*music_podcast_channels`.`id` IN (SELECT * FROM (SELECT `channel_id` FROM `*PREFIX*music_podcast_episodes` GROUP BY `channel_id` HAVING SUM(`duration`) $sqlOp ?) mysqlhack)";
47
			case 'pubdate':			return "`published` $sqlOp ?";
48
			default:				return parent::advFormatSqlCondition($rule, $sqlOp);
49
		}
50
	}
51
52
	/**
53
	 * @see \OCA\Music\Db\BaseMapper::findUniqueEntity()
54
	 * @param PodcastChannel $channel
55
	 * @return PodcastChannel
56
	 */
57
	protected function findUniqueEntity(Entity $channel) : Entity {
58
		$sql = $this->selectUserEntities("`rss_hash` = ?");
59
		return $this->findEntity($sql, [$channel->getUserId(), $channel->getRssHash()]);
0 ignored issues
show
Deprecated Code introduced by
The function OCA\Music\AppFramework\D...oudMapper::findEntity() has been deprecated: 14.0.0 Move over to QBMapper ( Ignorable by Annotation )

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

59
		return /** @scrutinizer ignore-deprecated */ $this->findEntity($sql, [$channel->getUserId(), $channel->getRssHash()]);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Bug introduced by
The method getRssHash() does not exist on OCA\Music\Db\Entity. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

59
		return $this->findEntity($sql, [$channel->getUserId(), $channel->/** @scrutinizer ignore-call */ getRssHash()]);
Loading history...
Bug Best Practice introduced by
The expression return $this->findEntity...channel->getRssHash())) returns the type OCP\AppFramework\Db\Entity which includes types incompatible with the type-hinted return OCA\Music\Db\Entity.
Loading history...
60
	}
61
}
62