DeviceMapper::findByHash()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 5
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 5
loc 5
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
namespace OCA\Maps\Db;
3
4
use OCP\AppFramework\Db\Mapper;
5
use OCP\IDb;
6
7 View Code Duplication
class DeviceMapper extends Mapper {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
9 1
	public function __construct(IDB $db) {
10 1
		parent::__construct($db, 'maps_location_track_users', '\OCA\Maps\Db\Device');
11 1
	}
12
13
	/**
14
	 * @param string $hash
15
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
16
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
17
	 * @return Device
18
	 */
19
	public function findByHash($hash) {
20
		$sql = 'SELECT * FROM `*PREFIX*maps_location_track_users` '.
21
			'WHERE `hash` = ?';
22
		return $this->findEntity($sql, [$hash]);
23
	}
24
25
	/**
26
	 * @param int $id
27
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
28
	 * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
29
	 * @return Device
30
	 */
31
	public function findById($id) {
32
		$sql = 'SELECT * FROM `*PREFIX*maps_location_track_users` '.
33
			'WHERE `id` = ?';
34
		return $this->findEntity($sql, [$id]);
35
	}
36
37
	/**
38
	 * @param string $userId
39
	 * @param int $limit
40
	 * @param int $offset
41
	 * @return Device[]
42
	 */
43 1
	public function findAll($userId, $limit=null, $offset=null) {
44
		$sql = 'SELECT * FROM `*PREFIX*maps_location_track_users`'.
45 1
			'WHERE `user_id` = ?';
46 1
		return $this->findEntities($sql, [$userId], $limit, $offset);
47
	}
48
49
}
50