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

AutoCompleteService::findMatches()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1
Metric Value
dl 0
loc 15
ccs 10
cts 10
cp 1
rs 9.4285
cc 1
eloc 10
nc 1
nop 1
crap 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