Completed
Pull Request — master (#1523)
by
unknown
09:53
created

AliasesService::findAll()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 15
loc 15
rs 8.8571
cc 5
eloc 9
nc 5
nop 2
1
<?php
2
/**
3
 * @author Tahaa Karim <[email protected]>
4
 *
5
 * ownCloud - Mail
6
 *
7
 * This code is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License, version 3,
9
 * as published by the Free Software Foundation.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License, version 3,
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
18
 *
19
 */
20
namespace OCA\Mail\Service;
21
22
use Exception;
23
use OCA\Mail\Account;
24
use OCA\Mail\Db\AliasMapper;
25
use OCP\IL10N;
26
27
class AliasesService {
28
29
	/** @var \OCA\Mail\Db\AliasMapper */
30
	private $mapper;
31
32
	/**
33
	 * Cache accounts for multiple calls to 'findByUserId'
34
	 *
35
	 * @var IAccount[]
36
	 */
37
	private $aliases;
38
39
	/** @var IL10N */
40
	private $l10n;
41
42
	/**
43
	 * @param AliasMapper $mapper
44
	 */
45
	public function __construct(AliasMapper $mapper, IL10N $l10n) {
46
		$this->mapper = $mapper;
47
		$this->l10n = $l10n;
48
	}
49
50
	/**
51
	 * @param $currentUserId
52
	 * @param $accountId
53
	 * @return IAccount
54
	 */
55 View Code Duplication
	public function findAll($currentUserId, $accountId) {
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...
56
		if ($this->accounts !== null) {
57
			foreach ($this->accounts as $account) {
0 ignored issues
show
Bug introduced by
The property accounts does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
58
				if ($account->getId() === $accountId) {
59
					return $account;
60
				}
61
			}
62
			throw new Exception("Invalid account id <$accountId>");
63
		}
64
65
		if ((int)$accountId === UnifiedAccount::ID) {
66
			return $this->buildUnifiedAccount($currentUserId);
0 ignored issues
show
Bug introduced by
The method buildUnifiedAccount() does not seem to exist on object<OCA\Mail\Service\AliasesService>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
		}
68
		return new Account($this->mapper->find($currentUserId, $accountId));
69
	}
70
71
	/**
72
	 * @param int $accountId
73
	 */
74 View Code Duplication
	public function delete($currentUserId, $accountId) {
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...
75
		if ((int)$accountId === UnifiedAccount::ID) {
76
			return;
77
		}
78
		$mailAccount = $this->mapper->find($currentUserId, $accountId);
79
		$this->mapper->delete($mailAccount);
80
	}
81
82
	/**
83
	 * @param $newAccount
84
	 * @return \OCA\Mail\Db\MailAccount
85
	 */
86
	public function save($newAccount) {
0 ignored issues
show
Unused Code introduced by
The parameter $newAccount is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
87
		return $this->mapper->save($newAlias);
0 ignored issues
show
Bug introduced by
The variable $newAlias does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
88
	}
89
}
90