DeviceMapper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 43
loc 43
ccs 6
cts 12
cp 0.5
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 3 3 1
A findByHash() 5 5 1
A findById() 5 5 1
A findAll() 5 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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