CollectedAddressMapper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 35
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A findMatching() 0 8 1
A exists() 0 8 1
1
<?php
2
3
/**
4
 * @author Christoph Wurst <[email protected]>
5
 * @author Thomas Müller <[email protected]>
6
 *
7
 * Mail
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
23
namespace OCA\Mail\Db;
24
25
use OCP\AppFramework\Db\Mapper;
26
use OCP\IDb;
27
28
class CollectedAddressMapper extends Mapper {
29
30
	/**
31
	 * @param IDb $db
32
	 */
33 4
	public function __construct(IDb $db) {
34 4
		parent::__construct($db, 'mail_collected_addresses');
35 4
	}
36
37
	/**
38
	 * Find email addresses by query string
39
	 *
40
	 * @param string $userId
41
	 * @param string $query
42
	 * @return CollectedAddress[]
43
	 */
44 2
	public function findMatching($userId, $query) {
45 2
		$sql = 'SELECT * FROM *PREFIX*mail_collected_addresses WHERE `user_id` = ? AND `email` ILIKE ?';
46
		$params = [
47 2
			$userId,
48 2
			'%' . $query . '%',
49 2
		];
50 2
		return $this->findEntities($sql, $params);
51
	}
52
53 2
	public function exists($userId, $email) {
54 2
		$sql = 'SELECT * FROM *PREFIX*mail_collected_addresses WHERE `user_id` = ? AND `email` ILIKE ?';
55
		$params = [
56 2
			$userId,
57
			$email
58 2
		];
59 2
		return count($this->findEntities($sql, $params)) > 0;
60
	}
61
62
}
63