ApiKeyMapper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
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 38
loc 38
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 find() 5 5 1
A findByUser() 5 5 1
A findAll() 4 4 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 ApiKeyMapper 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_apikeys', '\OCA\Maps\Db\ApiKey');
11 1
	}
12
13
	/**
14
	 * @param int $id
15
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
16
	 * @return ApiKey
17
	 */
18
	public function find($id) {
19
		$sql = 'SELECT * FROM `*PREFIX*maps_apikeys` '.
20
			'WHERE `id` = ?';
21
		return $this->findEntity($sql, [$id]);
22
	}
23
24
	/**
25
	 * @param string $uid
26
	 * @throws \OCP\AppFramework\Db\DoesNotExistException if not found
27
	 * @return ApiKey
28
	 */
29 1
	public function findByUser($uid) {
30
		$sql = 'SELECT * FROM `*PREFIX*maps_apikeys` '.
31 1
			'WHERE `user_id` = ?';
32 1
		return $this->findEntity($sql, [$uid]);
33
	}
34
35
	/**
36
	 * @param int $limit
37
	 * @param int $offset
38
	 * @return ApiKey[]
39
	 */
40
	public function findAll($limit=null, $offset=null) {
41
		$sql = 'SELECT * FROM `*PREFIX*maps_apikeys`';
42
		return $this->findEntities($sql, $limit, $offset);
43
	}
44
}
45