Passed
Push — master ( 28aace...5efe1b )
by Pauli
04:20
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
	 * @return string|false
28
	 */
29
	public function findByToken($token) {
30
		$sql = 'SELECT `user_id`
31
				FROM `*PREFIX*music_ampache_sessions`
32
				WHERE `token` = ? AND `expiry` > ?';
33
		$params = [$token, \time()];
34
35
		$result = $this->execute($sql, $params);
36
37
		$row = $result->fetch();
38
		return \is_array($row) ? $row['user_id'] : false;
39
	}
40
41
	/**
42
	 * @param string $token
43
	 * @param integer $expiry
44
	 */
45
	public function extend($token, $expiry) {
46
		$sql = 'UPDATE `*PREFIX*music_ampache_sessions`
47
				SET `expiry` = ?
48
				WHERE `token` = ?';
49
50
		$params = [$expiry, $token];
51
		$this->execute($sql, $params);
52
	}
53
54
	public function cleanUp() {
55
		$sql = 'DELETE FROM `*PREFIX*music_ampache_sessions`
56
				WHERE `expiry` < ?';
57
		$params = [\time()];
58
		$this->execute($sql, $params);
59
	}
60
61
	/**
62
	 * @param string $token
63
	 * @return integer|false
64
	 */
65
	public function getExpiryTime($token) {
66
		$sql = 'SELECT `expiry`
67
				FROM `*PREFIX*music_ampache_sessions`
68
				WHERE `token` = ?';
69
		$params = [$token];
70
71
		$result = $this->execute($sql, $params);
72
73
		$row = $result->fetch();
74
		return \is_array($row) ? (int)$row['expiry'] : false;
75
	}
76
}
77