Completed
Pull Request — master (#1559)
by Christoph
09:17
created

MailAccountMapper::findByEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 9
loc 9
ccs 0
cts 6
cp 0
rs 9.6666
cc 1
eloc 6
nc 1
nop 2
crap 2
1
<?php
2
3
/**
4
 * @author Christoph Wurst <[email protected]>
5
 * @author Christoph Wurst <[email protected]>
6
 * @author Lukas Reschke <[email protected]>
7
 * @author Thomas Müller <[email protected]>
8
 *
9
 * ownCloud - Mail
10
 *
11
 * This code is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License, version 3,
13
 * as published by the Free Software Foundation.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License, version 3,
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
22
 *
23
 */
24
25
namespace OCA\Mail\Db;
26
27
use OCP\AppFramework\Db\Mapper;
28
use OCP\IDb;
29
30
class MailAccountMapper extends Mapper {
31
32
	/**
33
	 * @param IDb $db
34
	 */
35 2
	public function __construct(IDb $db) {
36 2
		parent::__construct($db, 'mail_accounts');
37 2
	}
38
39
	/** Finds an Mail Account by id
40
	 *
41
	 * @param int $userId
42
	 * @param int $accountId
43
	 * @return MailAccount
44
	 */
45 1
	public function find($userId, $accountId) {
46 1
		$sql = 'SELECT * FROM `' . $this->getTableName() . '` WHERE user_id = ? and id = ?';
47 1
		$params = [$userId, $accountId];
48
49 1
		return $this->findEntity($sql, $params);
50
	}
51
52
	/**
53
	 * Finds all Mail Accounts by user id existing for this user
54
	 * @param string $userId the id of the user that we want to find
55
	 * @param $userId
56
	 * @return MailAccount[]
57
	 */
58 1
	public function findByUserId($userId) {
59 1
		$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE user_id = ?';
60 1
		$params = [$userId];
61
62 1
		return $this->findEntities($sql, $params);
63
	}
64
65 View Code Duplication
	public function findByEmail($email, $userId) {
0 ignored issues
show
Duplication introduced by
This method 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...
66
		$sql = 'SELECT * FROM ' . $this->getTableName() . ' WHERE user_id = ? and email = ?';
67
		$params = [
68
			$userId,
69
			$email,
70
		];
71
72
		return $this->findEntities($sql, $params);
73
	}
74
75
	/**
76
	 * Saves an User Account into the database
77
	 * @param MailAccount $account
78
	 * @return MailAccount
79
	 */
80 1
	public function save(MailAccount $account) {
81 1
		if (is_null($account->getId())) {
82 1
			return $this->insert($account);
83
		} else {
84 1
			$this->update($account);
85 1
			return $account;
86
		}
87
	}
88
89
}
90