Completed
Pull Request — master (#1276)
by Thomas
04:23
created

AutoCompleteService   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findMatches() 0 15 1
1
<?php
2
3
/**
4
 * ownCloud - Mail
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Christoph Wurst <[email protected]>
10
 * @copyright Christoph Wurst 2016
11
 */
12
13
namespace OCA\Mail\Service\AutoCompletion;
14
15
use OCA\Mail\Service\ContactsIntegration;
16
17
class AutoCompleteService {
18
19
	/** @var ContactsIntegration */
20
	private $contactsIntegration;
21
22
	/** @var AddressCollector */
23
	private $addressCollector;
24
25 1
	public function __construct(ContactsIntegration $ci, AddressCollector $ac) {
26 1
		$this->contactsIntegration = $ci;
27 1
		$this->addressCollector = $ac;
28 1
	}
29
30 1
	public function findMatches($term) {
31 1
		$recipientsFromContacts = $this->contactsIntegration->getMatchingRecipient($term);
32 1
		$fromCollector = $this->addressCollector->searchAddress($term);
33
34
		// Convert collected addresses into same format as CI creates
35 1
		$recipientsFromCollector = array_map(function ($address) {
36
			return [
37 1
				'id' => $address->getId(),
38 1
				'label' => $address->getEmail(),
39 1
				'value' => $address->getEmail(),
40 1
			];
41 1
		}, $fromCollector);
42
43 1
		return array_merge($recipientsFromContacts, $recipientsFromCollector);
44
	}
45
46
}
47