Passed
Push — master ( f27996...767f60 )
by Pauli
01:52
created

AmpacheSessionMapper::getExpiryTime()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 10
ccs 0
cts 6
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
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 Morris Jobke <[email protected]>
10
 * @author Pauli Järvinen <[email protected]>
11
 * @copyright Morris Jobke 2013, 2014
12
 * @copyright Pauli Järvinen 2020
13
 */
14
15
namespace OCA\Music\Db;
16
17
use OCP\AppFramework\Db\Mapper;
0 ignored issues
show
Bug introduced by
The type OCP\AppFramework\Db\Mapper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use OCP\IDBConnection;
0 ignored issues
show
Bug introduced by
The type OCP\IDBConnection was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
20
class AmpacheSessionMapper extends Mapper {
21
	public function __construct(IDBConnection $db) {
22
		parent::__construct($db, 'music_ampache_sessions', '\OCA\Music\Db\AmpacheSession');
23
	}
24
25
	/**
26
	 * @param string $token
27
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
28
	 * @return AmpacheSession
29
	 */
30
	public function findByToken($token) {
31
		$sql = 'SELECT *
32
				FROM `*PREFIX*music_ampache_sessions`
33
				WHERE `token` = ? AND `expiry` > ?';
34
		$params = [$token, \time()];
35
36
		return $this->findEntity($sql, $params);
37
	}
38
39
	/**
40
	 * @param string $token
41
	 * @param integer $expiry
42
	 */
43
	public function extend($token, $expiry) {
44
		$sql = 'UPDATE `*PREFIX*music_ampache_sessions`
45
				SET `expiry` = ?
46
				WHERE `token` = ?';
47
48
		$params = [$expiry, $token];
49
		$this->execute($sql, $params);
50
	}
51
52
	public function cleanUp() {
53
		$sql = 'DELETE FROM `*PREFIX*music_ampache_sessions`
54
				WHERE `expiry` < ?';
55
		$params = [\time()];
56
		$this->execute($sql, $params);
57
	}
58
}
59