AutoCompleteService   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findMatches() 0 15 1
1
<?php
2
3
/**
4
 * @author Christoph Wurst <[email protected]>
5
 *
6
 * Mail
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OCA\Mail\Service\AutoCompletion;
23
24
use OCA\Mail\Service\ContactsIntegration;
25
26
class AutoCompleteService {
27
28
	/** @var ContactsIntegration */
29
	private $contactsIntegration;
30
31
	/** @var AddressCollector */
32
	private $addressCollector;
33
34 1
	public function __construct(ContactsIntegration $ci, AddressCollector $ac) {
35 1
		$this->contactsIntegration = $ci;
36 1
		$this->addressCollector = $ac;
37 1
	}
38
39 1
	public function findMatches($term) {
40 1
		$recipientsFromContacts = $this->contactsIntegration->getMatchingRecipient($term);
41 1
		$fromCollector = $this->addressCollector->searchAddress($term);
42
43
		// Convert collected addresses into same format as CI creates
44 1
		$recipientsFromCollector = array_map(function ($address) {
45
			return [
46 1
				'id' => $address->getId(),
47 1
				'label' => $address->getEmail(),
48 1
				'value' => $address->getEmail(),
49 1
			];
50 1
		}, $fromCollector);
51
52 1
		return array_merge($recipientsFromContacts, $recipientsFromCollector);
53
	}
54
55
}
56